so_*_*_mv 5 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
Run Code Online (Sandbox Code Playgroud)
只有带有“无法发送消息”的 javax.xml.ws.WebServiceException。调用服务时抛出消息
try{
GetListCollectionResult result = port.getListCollection();
}catch (javax.xml.ws.WebServiceException excep){
}
Run Code Online (Sandbox Code Playgroud)
这就是我们调用服务的方式。
要提供 NTLM 凭据:
Authenticator.setDefault( extended class of Authenticator);
Run Code Online (Sandbox Code Playgroud)
创建服务。
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(ListsSoap.class);
factory.setAddress(list_url);
ListsSoap port = (ListsSoap) factory.create();
Run Code Online (Sandbox Code Playgroud)
更新导管。
..
Client client = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(36000);
httpClientPolicy.setAllowChunking(false);
http.setClient(httpClientPolicy);
Run Code Online (Sandbox Code Playgroud)
致电服务并获得结果。
GetListCollectionResult result = port.getListCollection();
Run Code Online (Sandbox Code Playgroud)
没关系,我在 CXF 邮件列表中找到了答案。
excep.getCause()
Run Code Online (Sandbox Code Playgroud)
提供对底层异常的访问,在我的例子中它是 HTTP 传输异常。
| 归档时间: |
|
| 查看次数: |
7106 次 |
| 最近记录: |