CXF - 捕获/处理 HTTP 异常

标签 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();

最佳答案

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

excep.getCause()

提供对底层异常的访问,在我的例子中它是 HTTP 传输异常。

关于CXF - 捕获/处理 HTTP 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6061856/

相关文章:

java - 如何将 SOAP 安全 header (UsernameToken) 信息添加到代码优先的 Web 服务生成的 WSDL

java - 带有 UsernameToken 和 SecurityContextToken 的 SOAP 安全 header - CXF

java - 在HttpURLConnection中getErrorStream返回的InputStream中获取服务器发送来的有用数据

java - HttpURLConnection POST 请求 - 无法将数据发送到服务器

sharepoint - 如何在我的 SharePoint 网站中获取多个同名列表?

spring - 如何定义模型以在没有根元素名称的情况下解码发布数据

java - 如何使用 Web 客户端在 Apache CXF JAX-RS 中发送带有正文的 DELETE 请求?

c# - SharePoint2010中的ConversionJob将docx转换为pdf需要很长时间或非常慢

java - 使用 HttpURLConnection 添加自定义 header

javascript - list.asmx 使用 js 在 sharepoint 中给出授权错误