GeeCON Prague 2014*
The moose likes Servlets and the fly likes How to send xml file to a different web server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "How to send xml file to a different web server" Watch "How to send xml file to a different web server" New topic
Author

How to send xml file to a different web server

Pete Neu
Ranch Hand

Joined: Feb 18, 2005
Posts: 86
Hello,

I my app I generate a xml document and write it to the output stream. But what I need to do is redirect the stream to a different server which will process the document for the user. How do I get this to work?
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
I would suggest that what you want to do is invoke a Web Service on the other server and then process the response for the user after it comes back.

Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Pete Neu
Ranch Hand

Joined: Feb 18, 2005
Posts: 86
Hi,

thanks for the fast answer. The other programmer uses PHP and does not want a Web Service. He wants the document in the redirected response. Any chance to do it like this?
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
OK, so the basic problem (as I understand it) is that you can't BOTH write to an output stream from a servlet and use sendRedirect to redirect the URI to a different server. So what you will have to do is:

(1) Build your xml document as a String.
(2) Use an HTTPURLConnection to open a connection to the PHP program and send the String you just built.
(3) Get a String back from the HTTPURLConnection and then place that on the output of your servlet.

By the way -- might I say that this is a horrible architecture for your web site. This will work, but the response time may not be good. If your servlet is the one that the user hits from their URL, then it should be doing the processing -- it may be in your interest to write your own code to just redo everything the PHP program does.

Kyle
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to send xml file to a different web server