gpt4 book ai didi

java - CXF客户端异常: Interceptor for {XXX} has thrown exception,现在展开

转载 作者:搜寻专家 更新时间:2023-10-30 19:57:23 26 4
gpt4 key购买 nike

我遇到了以下 CXF 异常:

warning: Interceptor for {http://example.com/wsdl/esc/2011-12-12/}AmazonEC2#{http://example.com/wsdl/esc/2011-12-12/}NewDescribeImages has thrown exception, unwinding now
java.lang.NullPointerException
at org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor.handleMessage(StartBodyInterceptor.java:59)
at org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor.handleMessage(StartBodyInterceptor.java:37)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:762)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1582)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1467)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1375)
at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:47)
at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:188)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:623)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:510)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:440)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:343)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:295)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)
at $Proxy31.newDescribeImages(Unknown Source)
at test.App.main(App.java:62)
javax.xml.ws.soap.SOAPFaultException: Fault string, and possibly fault code, not set

导致这个异常的代码:

    MyService ms =new MyService ();
MyServicePort port = ms.getAmazonEC2Port();
BindingProvider bp = (BindingProvider) port;
bp.getRequestContext()
.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://192.180.33.12:8773/services/myservice_url/");

Client client = ClientProxy.getClient(portType);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
Endpoint endpoint = client.getEndpoint();

Map<String, Object> inProps=new HashMap<String, Object>();
Map<String,Object> outProps = new HashMap<String,Object>();
configWSProps(inProps, outProps); //here is some WS-Security properties

WSS4JInInterceptor wssIn = new WSS4JInInterceptor(inProps);
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);

endpoint.getInInterceptors().add(wssIn);
endpoint.getOutInterceptors().add(wssOut);

SomeResponseType response = port.someMethod();

这个异常是在最后一行抛出的:port.someMethod()。在 configWSProps(...) 方法中我设置了一些 WS-Security 属性,这里不太可能有问题。

我打印了 cxf 日志,我可以看到入站消息具有正确的数据。

从CXF源码来看,好像是CXF获取soap消息失败,但不知如何解决。请帮助我!

这是CXF源代码: http://grepcode.com/file/repo1.maven.org/maven2/org.apache.cxf/cxf-rt-bindings-soap/2.4.1/org/apache/cxf/binding/soap/interceptor/StartBodyInterceptor.java/#59

最佳答案

在cxf代码中调试并在cxf邮件列表中寻求帮助,终于解决了这个问题。问题出在入站消息上,http消息缺少content-type头,导致CXF创建XMLStreamReader失败,进而读取内容失败,抛出NullPointerException。非常感谢 CXF 社区的 friend 们!

我问了一个问题并在那里得到了答案: http://cxf.547215.n5.nabble.com/CXF-client-exception-Interceptor-for-XXX-has-thrown-exception-unwinding-now-td5449373.html#a5449764

关于java - CXF客户端异常: Interceptor for {XXX} has thrown exception,现在展开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9078726/

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