0

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

4 Answers 4

2

We use JAXB https://jaxb.dev.java.net/tutorial/section_3_1-Unmarshalling-and-Using-the-Data.html#Unmarshalling

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

Thanks for the response Mike, but it's a simple xml not a soap.
0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.