Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

sendRedirect versus ServletOutputStream  RSS feed

 
Stuart Bell
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am developing a web service application which will facilitate communication of XML over HTTP. A client submits an HTTP POST request to my service, I process their request where my result is a response XML. I need to return that XML to a particular address, whilst keeping the whole transaction synchronous. If I attempt a sendRedirect to a new URL I can't find anyway of attaching or writing my response XML to that redirection, thereby passing the XML to the return address. If I use ServletOutputStream to right the XML string as binary output, I have no way of redirecting it to a different URL.

I am trapped in a catch-22 situation where I can either a) send the redirect but not attach my response XML or b) write the response XML but not redirect it to the new URL.

Can anyone out there offer any sage advice to help me out of this? Is it possible? If so, how can it be achieved?

Hope that makes sense.

Thanks,


Stuart
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I can understand from your post, you want to

1. Respond to a request with an xml output
2. Redirect the same request to another url.

And if the above is right, you cannot do such things. The moment you redirect, the browser sends a new request to the redirect url. When you send an output, the response is committed and redirection after that causes an IllegalStateException.

Ofcourse your posting contains what you want to achieve. Some more info on the actual requirement (i.e. - why you want to do things this way) may help.

cheers,
Ram.
 
Stuart Bell
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ram,


Thanks for your quick reply, in answer to your question:

"Ofcourse your posting contains what you want to achieve. Some more info on the actual requirement (i.e. - why you want to do things this way) may help."

I am working with a transmission standard called Origo, whereby I am developing a pipeline tracking system. This is all communicated through XML over HTTP. As part of the request XML from the client, a <return_location> tag is contained which sepecifies the URL to return the response to, rather than returning it back to the client the request came from.

So, from this that is why I need to redirect the response output to this new location. Is there some way that this can be achieved??

Thanks,

Stuart
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I may be wrong and somebody who knows a lot more may suggest a better way to handle this

As far as I can see, the only way out is to have the url (to which the response needs to be sent) listen over http/tcp. The process which handles the original request then becomes a client to this url, opens a stream (HttpURLConnection or plain Sockets), writes the response and closes the connection.


cheers,
ram.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!