Search code examples
javaweb-servicessoapcxfjax-ws

SOAP Action is empty while using Dispatch api of Apache cxf


I am using Apache cxf for the the soap client. While firing the request, even though after setting the SOAPAction in the MIME header, it gets changed to ""(empty string). Kindly provide a solution to solve this case. Following is the code

public class TempEg {

public static void main(String[] args) throws SOAPException, IOException {

    String withOutAuthBody="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://www.webserviceX.NET/\"><soapenv:Body><ns:ConvertTemp><ns:Temperature>35</ns:Temperature><ns:FromUnit>degreeCelsius</ns:FromUnit><ns:ToUnit>degreeFahrenheit</ns:ToUnit></ns:ConvertTemp></soapenv:Body></soapenv:Envelope>";


    String wsdlURLWithOutAuth="http://www.webservicex.net/ConvertTemperature.asmx?wsdl";



    MessageFactory factory = MessageFactory.newInstance();
    System.out.println(wsdlURLWithOutAuth + "\n\n");

    QName serviceName = new QName("http://www.webserviceX.NET/","ConvertTemperature");
    QName portName = new QName("http://www.webserviceX.NET/","ConvertTemperatureSoap");

    Service service1 = Service.create(new URL(wsdlURLWithOutAuth),serviceName);

    InputStream is1 = new ByteArrayInputStream(withOutAuthBody.getBytes());
    SOAPMessage soapReq1 = factory.createMessage(null, is1);




    Dispatch<SOAPMessage> dispSOAPMsg1 = service1.createDispatch(portName,
         SOAPMessage.class, Mode.MESSAGE);



    MimeHeaders headers = soapReq1.getMimeHeaders();
    headers.addHeader("SOAPAction", "http://www.webserviceX.NET/ConvertTemp");



    System.out.println("Invoking server through Dispatch interface using SOAPMessage");


    SOAPMessage soapResp = dispSOAPMsg1.invoke(soapReq1);
    System.out.println("Response from server: " + soapResp.getSOAPBody().getTextContent());


}

}

This is the error I am getting after running the above code.

    Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: .
   at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
   at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
   at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
   at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
    at org.apache.cxf.jaxws.DispatchImpl.mapException(DispatchImpl.java:287)
    at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:408)
    at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:243)
    at demo.hwDispatch.client.TempEg.main(TempEg.java:76)
Caused by: org.apache.cxf.binding.soap.SoapFault: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: .
   at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
   at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
   at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
   at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
    at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:84)
    at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:51)
    at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:40)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
    at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:113)
    at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
    at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
    at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:798)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1636)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1525)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1330)
    at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
    at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:638)
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:326)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:279)
    at org.apache.cxf.endpoint.ClientImpl.invokeWrapped(ClientImpl.java:314)
    at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:401)
    ... 2 more

This is the SOAPAction I could see whiling capturing the request through fiddler.

SOAPAction: ""

Solution

  • Looks like a bug, please submit a bug report + test-case here: https://issues.apache.org/jira/browse/CXF

    Colm.