在使用 Apache CXF v2.7.3 实现 SSL 安全的 WebService 时,我想测试客户端如何处理自定义异常类(例如 MyException)。
因此我有以下服务器端方法:
@WebMethod
public void foo() throws MyException {
throw new MyException("test!");
}
我还配置为通过以下方式在 cxf.xml 中登录和传出消息:
<bean id="logInbound" class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
<bean id="logOutbound" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
<jaxws:inInterceptors>
<ref bean="logInbound"/>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<ref bean="logOutbound"/>
</jaxws:outInterceptors>
使用客户端调用此函数会导致以下控制台输出
INFO: Inbound Message
----------------------------
ID: 1
Address: https://localhost:8443/WebApp/services/ClientService
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml; charset=UTF-8
Headers: {Accept=[*/*], cache-control=[no-cache], connection=[keep-alive], Content-Length=[184], content-type=[text/xml; charset=UTF-8], host=[localhost:8443], pragma=[no-cache], SOAPAction=[""], user-agent=[Apache CXF 2.7.3]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:foo xmlns:ns2="http://services.client.test.cloud.org/"/></soap:Body></soap:Envelope>
--------------------------------------
18.02.2013 22:49:02 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
INFO: Application {http://services.client.test.cloud.org/}ClientService#{http://services.client.test.cloud.org/}foo has thrown exception, unwinding now: org.cloud.test.client.exception.MyException: test!
18.02.2013 22:49:02 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
INFO: Application {http://services.client.test.cloud.org/}ClientService#{http://services.client.test.cloud.org/}foo has thrown exception, unwinding now: java.lang.NullPointerException: null
客户端收到“读取 XMLStreamReader 时出错”。由于“意外的EOF”。我想,服务器没有写任何响应。您知道为什么会抛出2 个异常以及为什么对客户端没有任何响应吗?我已经在 Apache CXF 应用程序中搜索了未重定向到客户端的异常,但找不到任何解决方案。
提前致谢!