在http网关spring集成上记录SOAP消息

时间:2016-01-15 20:27:21

标签: spring-integration

我使用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>

2 个答案:

答案 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。

ClientHttpRequestInterceptorRestTemplate的一部分,可以注入http:outbound-gateway

对于ws:outbound-gateway,您应该ClientInterceptor使用handleFault实施,并为您的目的提取MessageContext.getRequest()