【问题标题】:Logging SOAP message on http gateway spring integration在 http 网关 spring 集成上记录 SOAP 消息
【发布时间】:2016-01-15 20:27:20
【问题描述】:

我正在使用 spring 集成 (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>

【问题讨论】:

  • 请停止破坏您的帖子,将其回滚到早期的、不完整的版本。如果您希望请求解除关联,以便您的姓名不再与帖子相关联,请使用页面底部的“联系我们”链接。
  • 我昨天两次联系(与我们联系)删除我的帖子及其修订。你能帮我删除这篇文章的修订版和这篇文章吗?谢谢。
  • @HariBajavada 这是周末。这些事情在周末需要更长的时间。

标签: spring-integration


【解决方案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 现在会捕获此异常,这取决于您如何在错误处理程序中处理异常。

在 MessagingException 的原因中找到了 SOAP 错误代码和错误字符串(如果是 SoapFaultClientException)。

我在这里将错误消息发送到一个频道供我监控。

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    最好分享一些配置以及您想要获取日志/异常的点。

    &lt;int-http:outbound-gateway&gt;&lt;int-ws:outbound-gateway&gt; 都具有 &lt;request-handler-advice-chain&gt; 功能,您可以在其中使用 ExpressionEvaluatingRequestHandlerAdvice 并发送带有请求(有罪?)消息的 ErrorMessage 以进行任何诊断。

    您应该在适当的ClientHttpRequestFactory 上配置readTimeout,例如HttpComponentsClientHttpRequestFactory#setReadTimeout(int timeout).

    关于转换器以及希望在出现错误时记录其结果...

    如何用所需的逻辑实现ClientHttpRequestInterceptor

    try {
       return execution.execute(request, body);
    catch (Exception e) {
       this.errorChannel.send(...);
    }
    

    我很确定 byte[] body 是您的 SOAP 请求。

    有关更多信息,请参阅ClientHttpRequestInterceptorJavaDocs。

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

    对于ws:outbound-gateway,您应该使用ClientInterceptorhandleFault 实现并提取MessageContext.getRequest() 用于您的目的。

    【讨论】:

    • 不,请编辑您的问题并在那里分享更多信息。或者只是尝试弄清楚我的回答是否已经足以满足您的需求,然后我可以继续为其他人提供帮助。
    • 请把相同的内容移到您的问题中并正确格式化以提高可读性。
    • &lt;int:gateway&gt; 级别上,您可以配置receive-timeouterror-channel。有关详细信息,请参阅参考手册:docs.spring.io/spring-integration/docs/latest-ga/reference/html/…
    • 我刚刚在答案中添加了关于RestTemplate的注释
    • 好吧,您的配置中的所有内容看起来都像我想看到的那样。不确定您的问题是什么...也许最好逐行调试以确定要提取的正确属性。虽然对我来说 ClientHttpRequestInterceptor 完全希望 SOAP Request 发送...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-05
    • 2019-02-20
    • 1970-01-01
    • 2014-06-08
    相关资源
    最近更新 更多