xmlxpath

Getting the data From Soap response convertion into java object?


I Have one soap service which gives me the response in the following format

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:getUsersResponse xmlns:ns2="http://soap.com/"> <return> <email>email</email> <id>uid</id> <lastName>last_name</lastName> <userName>first_name</userName> </return> <return> <email>aladdin.scott@testingatgsl.com</email> <id>aladdin.scott@testingatgsl.com</id> <lastName>Scott</lastName> <userName>Aladdin</userName> </return> <return> <email>alice.wonderland@testingatgsl.com</email> <id>alice.wonderland@testingatgsl.com</id> <lastName>Wonderland</lastName> <userName>Alice</userName> </return> </ns2:getUsersResponse> </S:Body> </S:Envelope>

I want convert this into java objects of class given below.

class User { String uid ; String email; String fisrtName; String lastName; }

By using Xpath , I am not getting the right way to do ??


Solution

  • Why don't you use a Web Service framework like Axis2 or CXF?

    Or simply use "wsgen" and JAX-WS annotations?

    Here are a few tutorials:

    http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example-document-style/

    http://www.mkyong.com/tutorials/jax-ws-tutorials/

    http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/2.0/tutorial/doc/JAXWS3.html

    NOTE:

    You'll want to start by running wsgen (or equivalent) on your web service's WSDL. You probably don't want to manually hand-code your Java by reverse-engineering specific SOAP responses.

    The tutorials above should make this clearer...