Hello All, Fairly new to the world of J2EE. I am trying to find a way to send a HTTP post request and receive and XML response. Would greatly appreciate if any one can help me with this.
Thanks Peer Reynders. I was actually trying to interact with a server that takes HTTP requests and returns XML file as a response. Can someone guide me thru to get this task achieved.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 32767
posted
0
Originally posted by K Krishna Kishore: I was actually trying to interact with a server that takes HTTP requests and returns XML file as a response.
Which is precisely what Peers answer talks about. After having looked through the links he gave, which part are you unclear about?
I guess I should have reversed the beginning and end of my response .
I do think having your own servlet would be great for testing though.
K Krishna Kishore
Greenhorn
Joined: Aug 09, 2005
Posts: 12
posted
0
Hi PeerReynders,
thanks for the response. But The client in the link you have supplied is writing an XML output to the server after connecting to it. In my case that is not the issue.
The problem is that "I NEED TO SEND A HTTP REQUEST (by using an encoded URL). Bascially it would instantiate a servlet with the parameters that I have passed. Processes my request and send me a reply back. The reply being sent back is an XML file. Also this is a plain XML file and is not bound in SOAP envolope."
Hope someone can help me resolve this.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 32767
posted
0
I think the problem is clear now - you need a servlet that reads some parameters in the URL and generates XML as response. Nothing too complicated about that. Where exactly are you stuck?
On the client side it might be sufficient to use the URL class, particularly the getContent method. Then you'll have the XML in a string and can use SAX or DOM to process it further.
Peer Reynders
Bartender
Joined: Aug 19, 2005
Posts: 2906
posted
0
You are possibly not seeing the "forest for the trees". :roll: FibonacciXMLRPCClient is assembling an HTTP POST Request which it then sends to the server; then it shows what the server returns. You simply want an HTTP GET Request which uses exactly the same building blocks and procedures; so a little research through the API docs of the classes involved should have solved your problem. Here are some examples that are not obscured by the use of XML: Examples from Java Network Programming, 2nd Edition Example 7-5: SourceViewer Example 7-6: ContentGetter Example 15-1: SourceViewer2 Example 15-10: SourceViewer3 [ November 08, 2005: Message edited by: Peer Reynders ]
K Krishna Kishore
Greenhorn
Joined: Aug 09, 2005
Posts: 12
posted
0
Thanks Peer,
I have the exact same code written in my class (ofcourse that was "parsed" from the XMLRPC Client ). I am even checking for the response code being sent back. I am getting a response code 200. But the input reader is not displaying the response. Heres the code for the buffer reader.
[ November 08, 2005: Message edited by: K Krishna Kishore ]
Peer Reynders
Bartender
Joined: Aug 19, 2005
Posts: 2906
posted
0
Seems InputStreamReader is a bit unpredictable if you do not initially specify a character set. This works:
[ November 08, 2005: Message edited by: Peer Reynders ]
K Krishna Kishore
Greenhorn
Joined: Aug 09, 2005
Posts: 12
posted
0
thanks Peer for the help.....
I am running into exceptions though....When i try to hit a server with text data it works fine. But when i try to hit the test server to receive the XML file... it does keeps giving me the following exceptions:
These exceptions happen when i change to use the AXIS servlet using this URL : http://localhost/axis/EchoHeaders.jws?method=list. But in this case I changed the content type to text/XML..... and then i get this error.
where as in the prev case... if i change the content type to text/XML i get the "NOT XML Text" message......
Thanks for your time [ November 08, 2005: Message edited by: K Krishna Kishore ]
Peer Reynders
Bartender
Joined: Aug 19, 2005
Posts: 2906
posted
0
Your axis installation must be having trouble. I changed:
and
and it works fine.
Status code (503) indicates that the HTTP server is temporarily overloaded and is unable to handle the request.
Peer Reynders
Bartender
Joined: Aug 19, 2005
Posts: 2906
posted
0
For some inforamtion why the text/xml MIME type can be problematic and why it may not be used in connection with some XML over HTTP data see: XML on the Web Has Failed Just Use Media Types?