2.3.4. 传播 SOAP Exception
概述
Camel CXF 组件提供了与 Apache CXF 集成,可让您从 Apache Camel 端点发送和接收 SOAP 消息。您可以在 XML 中轻松定义 Apache Camel 端点,然后可使用端点的 bean ID 在路由中引用。如需了解更多详细信息,请参阅 Apache Camel 组件参考指南 中的 CXF。
如何传播堆栈追踪信息
可以配置 CXF 端点,以便在服务器端抛出 Java 异常时,异常的堆栈追踪会被放入故障消息并返回到客户端。要启用这个 feaure,请将 dataFormat
设置为 PAYLOAD
,并在 cxfEndpoint
元素中将 faultStackTraceEnabled
属性设置为 true
,如下所示:
<cxf:cxfEndpoint id="router" address="http://localhost:9002/TestMessage" wsdlURL="ship.wsdl" endpointName="s:TestSoapEndpoint" serviceName="s:TestService" xmlns:s="http://test"> <cxf:properties> <!-- enable sending the stack trace back to client; the default value is false--> <entry key="faultStackTraceEnabled" value="true" /> <entry key="dataFormat" value="PAYLOAD" /> </cxf:properties> </cxf:cxfEndpoint>
出于安全考虑,堆栈追踪不包括造成异常(即 后面的堆栈跟踪部分)。如果要在堆栈追踪中包含造成异常,请在
cxfEndpoint
元素中将 exceptionMessageCauseEnabled
属性设置为 true
,如下所示:
<cxf:cxfEndpoint id="router" address="http://localhost:9002/TestMessage" wsdlURL="ship.wsdl" endpointName="s:TestSoapEndpoint" serviceName="s:TestService" xmlns:s="http://test"> <cxf:properties> <!-- enable to show the cause exception message and the default value is false --> <entry key="exceptionMessageCauseEnabled" value="true" /> <!-- enable to send the stack trace back to client, the default value is false--> <entry key="faultStackTraceEnabled" value="true" /> <entry key="dataFormat" value="PAYLOAD" /> </cxf:properties> </cxf:cxfEndpoint>
警告
您应该只启用 exceptionMessageCauseEnabled
标记,用于测试和诊断。服务器通常会区分原始异常原因,从而使恶意用户更难以探测服务器。