Setting custom response header in SOAP at server side using metro library

1k Views Asked by At

I have created server side endpoint java code from WSDL using metro 2.3 library. In WSDL there are some custom attributes in header. But in generated code, method was only allowing to set response body. To set Custom attribute in header I have added one more parameter as per WSDL in WebMethod for SOAP header response using this tag : @WebParam(mode=OUT,header=true). According to Metro's document this should work. But it is giving following error.

@WebParam(name = "DataInput", targetNamespace = "urn://mycompany.com/Common/Service/CommonGenericReplyRS/ReplyTo/1.0/DataIO", partName = "input")
            DataInput input,
            @WebParam(name = "HeaderRequest", targetNamespace = "urn://mycompany.com/Schemas/SOAMessages/SoapHeader", header = true)
            HeaderRequest headerRequest 
            , @WebParam(header=true, mode=Mode.INOUT, name = "HeaderReply", partName = "output",  **targetNamespace = "urn://mycompany.com/Schemas/SOAMessages/SoapHeader") HeaderReply headerReply**);

I am getting following error once i add HeaderReply headerReply in method signature.

Throwable occurred: java.lang.IllegalArgumentException: **argument type mismatch**
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at com.sun.xml.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:250)
    at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:149)
    at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:88)
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136)
    at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:420)
    at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:687)

Can anyone tell me the way to set custom SOAP header in server side response?

1

There are 1 best solutions below

0
On

It worked after changing parameter type from HeaderReply to Holder<HeaderReply>.

public DataOutput replyTo(
        @WebParam(name = "DataInput", targetNamespace = "urn://mycompany.com/Common/Service/CommonGenericReplyRS/ReplyTo/1.0/DataIO", partName = "input")
        DataInput input,
        @WebParam(name = "HeaderRequest", targetNamespace = "urn://mycompany.com//Schemas/SOAMessages/SoapHeader", header = true, partName = "HeaderRequest")
        HeaderRequest headerRequest,
        @WebParam(name = "HeaderReply", targetNamespace = "urn://mycompany.com/Schemas/SOAMessages/SoapHeader", header = true, mode = WebParam.Mode.OUT, partName = "HeaderReply")
        Holder<HeaderReply> headerReply)