aspose file tools*
The moose likes Servlets and the fly likes Streaming response (code) to client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Streaming response (code) to client" Watch "Streaming response (code) to client" New topic
Author

Streaming response (code) to client

sumit anand kumar
Ranch Hand

Joined: Apr 28, 2010
Posts: 83
Guys I know most of you will say its a bad design and its not possible, but I want to explore the power of HTTP Status codes

I have a client and a server. Theres a loadbalancer in between. For some reason its timeout cannot be increased . I don't want to modify the client.
I am doing a heavy duty processing on the server that exceeds the loadbalancer's timeout.
I was streaming response to the client. After my heavy job is finished i send the final response to client.

Is it possible to somehow alert the client to discard any streamed data sent before the response. Can i send just the response code again. (Any hack?)

My code



Response :

$ curl -i http://localhost:8080/stream
HTTP/1.1 207 Multi-Status
Server: Apache-Coyote/1.1
Content-Type: text/html
Transfer-Encoding: chunked
Date: Mon, 25 Jun 2012 18:34:07 GMT

++++++++++My job's output


I expect

$ curl -i http://localhost:8080/stream
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html
Transfer-Encoding: chunked
Date: Mon, 25 Jun 2012 18:34:07 GMT

My job's output
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
Since status codes are sent on the first line of a response, followed by headers, it should be obvious that you can only send a code once.

The subject of handling long running processes within the context of a HTTP server has been covered many times - the consensus is that you should farm long running processes out to a separate thread and provide a mechanism separate request to get the results.

Bill

 
jQuery in Action, 2nd edition
 
subject: Streaming response (code) to client