• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Need Help with HTTP Request

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 in advance
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You simply write a servlet to output XML. See servlet that generates XML or
A DOM based XML-RPC servlet for an example. You'll need Tomcat or another web container.

For the client code see Connecting an XML-RPC server with URLConnection
[ October 26, 2005: Message edited by: Peer Reynders ]
 
K Krishna Kishore
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the client code see Connecting an XML-RPC server with URLConnection.

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.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
a wee bit from the empire
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic