• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to send xml file to a different web server

 
Pete Neu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Pete Neu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic