简体   繁体   中英

How to extract soap header from response Envelope using apache.cxf java

Following is response from server:

在此处输入图片说明

I have tried with the following code but it does not work for me

 public void handleMessage(SoapMessage message) throws Fault {
        SOAPMessage sm = message.getContent(SOAPMessage.class);
        try {
            System.out.println("In side read intercepter..");
            String soapheader=sm.getSOAPPart().getEnvelope().getHeader().getTextContent();
            System.out.println("SOAP Env Header:=>"+soapheader);
        } catch (SOAPException e) {
            throw new Fault(e);
        } 
    }

Expected result:

<e:Header>
        <Friends>
            <friend>
                <Name>Testabc</Name>
                <Age>12121</Age>
                <Phone>Testpqr</Phone>
            </friend>
        </Friends>
</e:Header>

Check Below. Extract the Headers of Response.

public class SOAPRSPInt extends AbstractSoapInterceptor {

    private static final Logger log = LoggerFactory.getLogger(SOAPRSPInt.class);

    public SOAPRSPInt() {
        super(Phase.POST_INVOKE);
    }

    @Override
    public void handleMessage(SoapMessage message) throws Fault {
        List<Header> list = message.getHeaders();

        log.debug("SOAPRSPInt message: '{}'", ToStringBuilder.reflectionToString(message),
                ToStringStyle.MULTI_LINE_STYLE);

        String hfrMSG = "SOAPRSPInt message ";
        String resultMSG = "";
        for (Header header : list) {

            hfrMSG += "  '" + header.getName() + "':" + 
                    ((ElementNSImpl) header.getObject()).getTextContent() + "\n";

            if (header.getName().toString().equalsIgnoreCase("{urn:sap-com:document:sap:rfc:functions}ResultStatus")) {
                resultMSG = ((ElementNSImpl) header.getObject()).getTextContent();
            }
        }

        log.debug("SOAPRSPInt headers: '{}'", hfrMSG);

        log.debug("SOAPRSPInt ResultMSG: '{}'", resultMSG);


    }
    
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM