gpt4 book ai didi

java - 使用 Apache cxf 的 Dispatch api 时 SOAP Action 为空

转载 作者:行者123 更新时间:2023-12-01 11:42:35 25 4
gpt4 key购买 nike

我正在使用 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

科尔姆。

关于java - 使用 Apache cxf 的 Dispatch api 时 SOAP Action 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29410078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com