views:

68

answers:

4

Hello All..

I need to get connect with https url, send my request schema and I will get some xml response from web service.

For https url connection I am using :

URL myurl = new URL(httpsURL);
                HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
                con.setDoOutput(true);
                con.setDoInput(true);
                con.setUseCaches(false);
    con.setRequestProperty("Content-type","text/xml");

So, from above code I am getting responded XML from server. Now my question is which would be best parser for me to parse responded xml data to my Simple Java Object.

I have goggled alot on that, and getting various solutions but I have confuse for choosing appropriate one.

if anybody have suggestion with some sample example, then please provide..

Thanks in advance...

EDIT : Above https response is not a soap

+1  A: 

If this is a SOAP service then you should be using a SOAP client API instead like Spring-WS or JAX-WS.

Mike Thomsen
Thanks for the response Mike, but it's a simple xml not a soap.
Nirmal
A: 

We use the Metro library for this, which requires Java 1.5 and is included in Java 6.

You then get a DOM tree for the result, which can then easily be postprocessed.

We used IntelliJ IDEA to convert the WSDL to Java source using Metro.

Thorbjørn Ravn Andersen
A: 

I would suggest having a look at Castor (http://www.castor.org/xml-mapping.html) - it's an extremely simple way to map XML to POJOs. It generates the Java classes based on your XML schema (in your case the WSDL file).

When you're done parsing the response is as simple as:

StringReader sr = new StringReader(inMessageString);
YourSoapResponse response = (YourSoapResponse)Unmarshaller.unmarshal(YourSoapResponse.class, sr);

Castor is relatively fast (once it's warmed up) but if your XML response are "huge" you may need to reconsider and use Stax (http://stax.codehaus.org/Home) for instance.

Tim