0

I am pretty new with JAX-WS, I would like to get a value in the Response Data of my Soap Handler but I do not know how.

Below is the soap response in XML:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tsn="http://TestSession/BSCS_SessionManager" xmlns:ses="http://TestSession">
    <soapenv:Header/>
    <soapenv:Body>
        <tsn:LogonResponse>
            <ses:CS_ServiceHeader>
                <SourceSystem>SRCSYS</SourceSystem>
                <TargetSystem>TGTSYS</TargetSystem>
                <ExternalID>20150525043213</ExternalID>
                <AgentName>JOHNDOE</AgentName>
            </ses:CS_ServiceHeader>
            <ses:CS_LogonResponse>
                <CS_LogonResponseData>
                    <Signature>b9n9+BWWvJ0=|Qe9HGWuQXKt8zb6oaIoseiyIMsdy+svIYASZJLEy6bhmICr4LkNkOHrvLeDWAItQ7YU17N0eRDq0X36Ls8GSXR75SDsovL6DjAgSpN0AuC/BEkTJcQjVft1buhqfiyMrHsoqMU9c2vM=</Signature>
                </CS_LogonResponseData>
            </ses:CS_LogonResponse>
            <ses:Trailer>
                <Version>0.0.1</Version>
            </ses:Trailer>
        </tsn:LogonResponse>
    </soapenv:Body>
</soapenv:Envelope>

I would like to get the value of <Signature> inside <CS_LogonResponseData>. I used the following but it seems to work only in stand alone application.

Code:

SOAPMessage soapMsg = context.getMessage();
SOAPBody body = soapMsg.getSOAPBody();
body.getChildNodes().item(0).getChildNodes().item(3).getChildNodes().item(1).getChildNodes().item(1).getTextContent();

When I use the same code in my project... the result is always null.

Is there a way I can navigate from the response data and get value of <Signature>... the childnodes items indexes seems to be changing when run as standalone application and when run via tomcat.

I will be needing the signature value in the resquest data of my other operation (like logout, etc).

Thanks in advance

Borgy Manotoy
  • 1,960
  • 5
  • 27
  • 42
  • Just a thought, would it be ok to use XPath here? I created a separate simple application that uses the response XML and xpath to get the value of `` and it works. But I am not sure if XPath would work when used inside SoapHandler. I also not sure if XPath is a good solution for my problem. Thanks – Borgy Manotoy May 26 '15 at 02:26
  • Using XPath, I was able to get the value of `` using the code: String expression = "//Signature"; ... String signature = objXPath.compile(expression).evaluate(objDocument); Now, I needed to get the ieai value (LogonResponse or LogoutResponse) from the response XML. It is just below ``. I only need the local name LogonResponse/LogoutResponse. – Borgy Manotoy May 26 '15 at 09:30
  • Logon Response: ... Logout Response: ... Using XPath, how do I get the values LogonResponse OR LogoutResponse? – Borgy Manotoy May 26 '15 at 09:31
  • Based on the XML in the original post, I can get the LogonResponse or LogoutResponse by using the expression: "substring-after(name(//Body/*[1]), ':')". In my case, there is only one child inside ``. Again, I am not sure if using XPath inside SoapHandler is acceptable... but this do the job for me. – Borgy Manotoy May 26 '15 at 14:08

0 Answers0