Sending Response Back from servlet with Resp obj in HttpSession

Discussions

Web tier: servlets, JSP, Web frameworks: Sending Response Back from servlet with Resp obj in HttpSession

  1. Is it possible to store the HttpResponse Object is HttpSession and then later get the response obj from session and send the response back to the client.

    To Summarize:

    Client Sends Req--> HttpServlet-->Creates HttpSession and put HttpResponse in session---> Put the HttpSession Obj in a Global HashMap(Other classes have access to Hashmap)-->Someone sets a Attribute in the HttpSession (which was in HashMap) -->Web Container calls addAttribute method of the MyListener--> Gets the session object which was changed -->Takes the HttpResponse obj from session and send the response back to client...

    Although its getting bit fuzzy here any thoughts appreciated.
  2. Although, conceptually you can do it, it would be a seriously flawed design. You may want to decouple the business objects that
    sets a Attribute in the HttpSession (which was in HashMap)
    Instead of passing the session and response objects by storing them in Global HashMap and making them available to other classes, you can use manager classes or some other form of delegates which could process the data. The cleaner design would put separation between web, business and data tiers.

    Client Sends Req to HttpServlet
    HttpServlet-->Creates HttpSession, Retrieves Data From Request and calls Manager/Delegate to process data which could be a bean or a map etc.
    Manager --> Processes and updates data. Manager is your Business Object or Delegate.
    HttpServlet --> Sends the response back to the client
  3. The whole purpose i was thinking this way is to acomplish psuedo synchronous request/response


    Servelt accepts a request-->Puts it on JMS-->JMS does the processing and Sends Response back on a queue-->Servlet should pick this response and return to client.


    While the JMS processes the request the Servlet Thread has to wait till the request is processed by the JMS and then in the same thread on arrival of JMS response message send the response back to client.

    Cannot implement any other way like call back or client checking back later for the message ...the reqa are such that the response has to go back in the same servlet req and the other system to which we r trying to integrate is JMS based.
  4. Keep it as it is[ Go to top ]

    Servelt accepts a request-->Puts it on JMS-->JMS does the processing and Sends Response back on a queue-->Servlet should pick this response and return to client.
    Which client? A client can terminate a request anytime (user clicks the Stop button), so your response gets useless and is not returned anywhere. HTTP connection is initiated and terminated by a client.
    While the JMS processes the request the Servlet Thread has to wait till the request is processed by the JMS and then in the same thread on arrival of JMS response message send the response back to client.
    Servlets are supposed to be multthreaded.