开发者

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

开发者 https://www.devze.com 2023-04-04 08:23 出处:网络
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

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:Algor开发者_如何学JAVAithmSuite>
        <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.


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();


I've found this code to unmarshall from a SOAPResponse Message to POJO class, I hope be helpful.

    //unmarshalling
    JAXBContext jc = JAXBContext.newInstance(MyPOJO.class);
    Unmarshaller um = jc.createUnmarshaller();
    MyPOJO output = (MyPOJO)um.unmarshal(soapResponse.getSOAPBody().extractContentAsDocument());


i'm guessing you already have a soap object and want to parse the contents of the message.

// assumptions: soapMessage contains the SoapMessage
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        soapMessage.writeTo(baos);
        final InputSource inputSource = new InputSource(new StringReader(
            new String(baos.toByteArray())));
        final DocumentBuilderFactory dbFactory = DocumentBuilderFactory
            .newInstance();
        final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        final Document doc = dBuilder.parse(inputSource);
        doc.normalize();
// after this use Xpath to process the soapMessage

if you have the soap message as a string then you can start from building the Document object using the string.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号