我使用spring integration(4.0.6)使用int-http:outbound-gateway和int-ws:outbound-gateway从rest服务进行SOAP调用。有没有办法只在异常的情况下记录SOAP请求消息。
<int:gateway id="myGateway" service-interface="myservice">
<int:method name="getData" request-channel="reqChannel" reply-channel="repChannel">
</int-gateway>
我的出站网关配置如下
<int-http:outbound-gateway id="og1" request-channel="reqChannel" url="xxx" http-method="POST" reply-channel="repChannel" reply-timeout="10000" message-converters="converter" request-factory="reqFactory">
<bean id="reqFactory"
class="org.springframework.http.client.SimpleClientHttpRequestFactory">
<property name="cTimeout" value="20000"/>
<property name="rTimeout" value="20000"/>
</bean>
答案 0 :(得分:1)
好的,试试这个方法。 创建自己的错误处理程序,它实现spring错误处理程序接口。在您的上下文文件中
<bean id="soapErrorHandlingSyncTaskExecutor"
class="org.springframework.integration.util.ErrorHandlingTaskExecutor">
<constructor-arg>
<bean class="org.springframework.core.task.SyncTaskExecutor" />
</constructor-arg>
<constructor-arg>
<bean class="ErrorHandle"
p:errorSender-ref="errorSender"/>
</constructor-arg>
</bean>
<bean id="errorSender" class="org.springframework.integration.core.MessagingTemplate"
p:defaultChannel-ref="errors" />
当你的WS适配器抛出任何异常时,org.springframework.integration.util.ErrorHandlingTaskExecutor现在捕获这个异常,你可以在错误处理程序中处理异常。
SOAP faultcode和faultstring在MessagingException的原因中找到(如果是SoapFaultClientException)。
这里我将错误消息发送到频道供我监听。
希望这有帮助。
答案 1 :(得分:0)
最好分享一些配置,以及你想获得日志/异常的地方。
<int-http:outbound-gateway>
和<int-ws:outbound-gateway>
都具有<request-handler-advice-chain>
能力,您可以使用ExpressionEvaluatingRequestHandlerAdvice
并发送ErrorMessage
请求(guilty?)消息任何诊断。
您应该在相应的readTimeout
上配置ClientHttpRequestFactory
,例如HttpComponentsClientHttpRequestFactory#setReadTimeout(int timeout)
。
关于转换器以及在出现错误时记录其结果的愿望......
如何使用所需的逻辑实现ClientHttpRequestInterceptor
:
try {
return execution.execute(request, body);
catch (Exception e) {
this.errorChannel.send(...);
}
我确定byte[] body
是您的SOAP请求。
有关详细信息,请参阅ClientHttpRequestInterceptor
JavaDocs。
ClientHttpRequestInterceptor
是RestTemplate
的一部分,可以注入http:outbound-gateway
。
对于ws:outbound-gateway
,您应该ClientInterceptor
使用handleFault
实施,并为您的目的提取MessageContext.getRequest()
。