Unmarshalling SOAP Messages to java / or simply parsing SOAP message?

Bouanani Meher picture Bouanani Meher · Sep 13, 2011 · Viewed 24.1k times · Source

I am facing this problem for over than one month , so i would be realy pleased by your help , in fact i am asking about a way that can let me parse a SOAP message (request) to can retrieve the needed information , such as the security information if there is any and informations from the body of the message


Thanks for answering me , but know i am dealing with another problerm which is the WS-SecurityPolicy and i have to finaly parse an xml file like this one : <?xml version="1.0" encoding="UTF-8"?>

    <sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
      <wsp:Policy>
        <sp:TransportToken>
          <wsp:Policy>
            <sp:HttpsToken RequireClientCertificate="false"/>
          </wsp:Policy>
        </sp:TransportToken>
        <sp:AlgorithmSuite>
          <wsp:Policy>
            <sp:Basic128/>
          </wsp:Policy>
        </sp:AlgorithmSuite>
        <sp:Layout>
          <wsp:Policy>
            <sp:Lax/>
          </wsp:Policy>
        </sp:Layout>
        <sp:IncludeTimestamp/>
      </wsp:Policy>
    </sp:TransportBinding>
    <sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
        <wsp:Policy>
            <sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient" />
      </wsp:Policy>
    </sp:SignedSupportingTokens>

'

knowing that this XML file is named Policy.xml and contains the rules of WS-SecurityPolicy, which must be present.

Answer

andbi picture andbi · Sep 13, 2011

It depends on what's inside your message. You've tagged your question with jaxb which makes me think that you have xml-serialized data inside soap message. If this is the case you could use JAXB unmarshaller to convert your message to an instance of Java class:

JAXBContext jbc = JAXBContext.newInstance("com.mypackage");
Unmarshaller um = jbc.createUnmarshaller();

JAXBElement<MyClass> element = um.unmarshal(parameterNode, MyClass.class);
MyClass data = element.getValue();