CXF - 捕获/处理HTTP异常

时间:2011-05-19 16:33:45

标签: cxf httpurlconnection sharepoint-api

这是一个基本的cxf使用问题。我们如何/在哪里捕获实际的HTTP异常/错误。我有点遵循Interceptor / MessageObserver概念,但无法使用它们捕获HTTP错误。

我在log4j日志文件中看到此错误。

Caused by: org.apache.cxf.transport.http.HTTPException: HTTP response
'401: Unauthorized' when communicating with http://10.107.172.79/test/_vti_bin/lists.asmx
                at  org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1502)
                at org.apache.cxf.transpot.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1448)
                at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1356)
                at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
                at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:614)
                at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
                ... 9 more

只有带有“无法发送消息”的javax.xml.ws.WebServiceException。 调用服务时抛出消息

try{

      GetListCollectionResult result = port.getListCollection();

   }catch (javax.xml.ws.WebServiceException excep){

}

这就是我们称之为服务的方式。

提供NTLM凭证:

Authenticator.setDefault( extended class of Authenticator);

创建服务。

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(ListsSoap.class);
factory.setAddress(list_url);
ListsSoap port = (ListsSoap) factory.create();

更新管道。

...

        Client client = ClientProxy.getClient(port);
        HTTPConduit http = (HTTPConduit) client.getConduit();
        HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
        httpClientPolicy.setConnectionTimeout(36000);
        httpClientPolicy.setAllowChunking(false);
        http.setClient(httpClientPolicy);

致电服务并获得结果。

GetListCollectionResult result  = port.getListCollection();

1 个答案:

答案 0 :(得分:1)

没关系,我在CXF邮件列表中找到了答案。

excep.getCause()

允许访问底层异常,在我的例子中,它是HTTP传输异常。