2011-05-19 94 views
4

這是一個基本的cxf用法問題。我們如何/在哪裏可以捕捉到實際的HTTP異常/錯誤。我遵循Interceptor/MessageObserver概念,但無法使用它們捕獲HTTP錯誤。CXF - 捕獲/處理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

沒關係,我在CXF郵件列表中找到了答案。

excep.getCause() 

可以訪問底層的異常,在我的情況下它是HTTP傳輸異常。