Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Streaming response (code) to client

 
sumit anand kumar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic