使用 Apache cxf 的 Dispatch api 时 SOAP 操作为空

SOAP Action is empty while using Dispatch api of Apache cxf

我正在使用 Apache cxf 作为 soap 客户端。在触发请求时,即使在 MIME header 中设置了 SOAPAction 之后,它也会更改为“”(空字符串)。请提供解决此案例的解决方案。以下是代码

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());


}

}

这是我在 运行 上面的代码之后得到的错误。

    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

这是我在通过 fiddler 捕获请求时看到的 SOAPAction。

SOAPAction: ""

看起来像一个错误,请在此处提交错误报告 + 测试用例:https://issues.apache.org/jira/browse/CXF