简体   繁体   中英

adding SOAPHeader in response in AXIS2 webservice

I want to add soap header in response of a soap request. I have googled a lot. What I found is to add handler and define it in module.xml but I have embedded AXIS2 web service in a java web application so I don't have module.xml or axis2.xml. In my project only services.xml is there that is autogenerated by axis2 lib while generating axis2 server side code.

In WSDL, the operation is defined as below:

        <operation name="XYZ">
            <soap:operation soapAction="SOAP_HTTP#XYZ" />
            <input>
                <soap:body use="literal" parts="XYZ"
                    namespace="http://www.ecma-international.org/standards...." />
                <soap:header message="wss:header" part="header" use="literal"></soap:header>
            </input>
            <output>
                <soap:body use="literal" parts="XYZResponse"
                    namespace="http://www.ecma-international.org/standards..." />
                <soap:header message="wss:header" part="header" use="literal"></soap:header>
            </output>
            <fault name="FaultName">
                <soap:fault use="literal" name="FaultName"
                    namespace="http://www.ecma-international.org/standards..." />
            </fault>
        </operation>

I am able to successfully add SOAPHeader in request and also read headers from Request and response both. But I am not able to add SOAPHeader "header" in SOAP response.

Please provide your suggestions on how can I add soap header in SOAP response?

Thanks.

You have to add a Handler via a new Module in Axis2

Handles invoke method will get the response message context and you can add the headers there.

See here : http://wangxiangblog.blogspot.in/2011/01/develop-web-service-with-axis2-7-add.html

To get request headers

In handler

   invoke(MessageContext msgContext) - This is response message context

    MessageContext reqMsgCtx = MessageContext.getCurrentMessageContext(); - This gives    request message context
    //Get header with following code
    SOAPEnvelope env = reqMsgCtx.getEnvelope();
    SOAPHeader aSoapHeader = env.getHeader();

//Your code to add the headerblocks to response message header

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