简体   繁体   English

在int-ws:outbound-gateway上通过Spring集成处理Http错误

[英]Handle Http errors with spring integration on int-ws:outbound-gateway

I'm having problems handling http erros on <int-ws:outbound-gateway> 我在处理<int-ws:outbound-gateway>上的http错误时遇到问题
I tried placing a error-channel on <int:gateway> , but it doesn't seem to work, because I get unmarshalling exceptions. 我尝试在<int:gateway>上放置一个error-channel ,但是它似乎不起作用,因为我收到了编组异常。
Plus I feel it's not right, http errors should be caught somewhere after the message is received from <int-ws:outboung-gateway> 另外我觉得这是不对的,从<int-ws:outboung-gateway>收到消息后,应该在某个地方捕获到HTTP错误。
My messaging system is set up like this: 我的消息传递系统是这样设置的:
<int:gateway> -> channel -> transformer -> channel -> <int-ws:outboung-gateway>

Question: what's the right way to catch http errors with spring integration? 问题:通过spring集成捕获HTTP错误的正确方法是什么?

AFTER EDIT 编辑后

  <int:channel id="checkProcessRequestChannel"/>
  <int:channel id="checkProcessResponseChannel"/>

  <int:channel id="errorChannel"/>

  <!-- channels for connecting to the outbound gateway -->
  <int:channel id="checkProcessOutboundRequestChannel"/>
  <int:channel id="checkProcessOutboundResponseChannel"/>



<int:gateway id="eInvoiceGateway" service-interface="com.iquest.play.integration.einvoice.EInvoiceGateway" error-channel="errorChannel">
    <int:method name="checkProcessByCode" request-channel="checkProcessRequestChannel" reply-channel="checkProcessResponseChannel"/>
<int:gateway>



  <int:transformer ref="eInvoiceTransformer" method="transformCheckProcessRequest" input-channel="checkProcessRequestChannel" output-channel="checkProcessOutboundRequestChannel"/>
  <int:transformer ref="eInvoiceTransformer" method="transformCheckProcessResponse" input-channel="checkProcessOutboundResponseChannel" output-channel="checkProcessResponseChannel"/>



 <int-ws:outbound-gateway id="checkClientByCodeOutboundGW"
                           request-channel="checkProcessOutboundRequestChannel"
                           reply-channel="checkProcessOutboundResponseChannel"
                           marshaller="eInvoiceMarshaller"
                           unmarshaller="eInvoiceMarshaller"
                           destination-provider="eInvoiceUriProvider"
                           message-factory="eInvoiceMessageFactory"
                           />

FIX: So, after placing a error-channel on the gateway, the thread was getting stuck somewhere. FIX:因此,在网关上放置error-channel后,线程被卡在某个地方。 It was a pretty dummy problem, the name of the service-activator for gateway error-channel was errorHandler , it's probably used by the spring namespace -> changing the bean name solved the problem. 这是一个非常虚拟的问题,网关错误通道的service-activator的名称为errorHandler ,它可能由spring名称空间使用->更改bean名称解决了该问题。

We can handle http errors in spring integration during unmarshal. 我们可以在解组期间处理Spring集成中的http错误。

Write a custom unmarshaller and catch the soap fault message. 编写一个自定义的解组器并捕获肥皂故障消息。

This article explains clearly how to handle soap fault message. 本文清楚地说明了如何处理肥皂故障消息。

http://blog.hostmasterzone.com/how-to-unmarshal-soap-fault-in-spring-integration-web-service/ http://blog.hostmasterzone.com/how-to-unmarshal-soap-fault-in-spring-integration-web-service/

 <bean id="hmzJaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
         <property name="contextPaths">
                <list>
                    <value>org.hmz.request.types</value>
                </list>
            </property>
        </bean>
<bean id="custJaxbUnMarshaller" class="com.jay.hmz.util.CustJaxbUnMarshaller" >
     <property name="contextPaths">
            <list>
                <value>org.hmz.request.types</value>
            </list>
        </property>
    </bean>

    <int:chain input-channel="channel.in" output-channel="channel.out"> 
         <int:transformer method="transformParentRequestById"><bean class="org.jay.hmz.api.transformers.OrderTransformer"/></int:transformer>
         <int-ws:header-enricher><int-ws:soap-action value="${order.request.uri}"/></int-ws:header-enricher> <int-ws:outbound-gateway interceptors="hmzSecurityInterceptor" mapped-request-headers="GUID, USER_REF" request-callback="hmzWebServiceMessageCallback" unmarshaller="custJaxbUnMarshaller" marshaller="hmzJaxbMarshaller" uri="${order.request.uri}"/> 
         <int:transformer method="transformRetrieveParentOrderResponse"><bean class="org.jay.hmz.api.transformers.OrderTransformer"/></int:transformer> 
     </int:chain>

    <int:service-activator input-channel="requestErrorChannel" output-channel="response.out" ref="requestErrorHandler" method="handleFailedOrderRequest"/>

    <bean id="requestErrorHandler" class="org.jay.hmz.api.errorhandler.RequestErrorHandler"/>

public class CustJaxbUnMarshaller extends Jaxb2Marshaller {

    @Override
    public Object unmarshal(Source source, MimeContainer mimeContainer)
            throws XmlMappingException {
        LOGGER.debug("Inside Custom JaxbWrapper unmarshal");
        Object mimeMessage = new DirectFieldAccessor(mimeContainer)
                .getPropertyValue("mimeMessage");
        Object unmarshalObject = null;
        if (mimeMessage instanceof SaajSoapMessage) {
            SaajSoapMessage soapMessage = (SaajSoapMessage) mimeMessage;
            String faultReason = soapMessage.getFaultReason();
            if (faultReason != null) {
                throw convertJaxbException(new JAXBException(faultReason));
            } else {
                unmarshalObject = super.unmarshal(source, mimeContainer);
            }
        }
        return unmarshalObject;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Integration Java DSL - 如何调用int-http:outbound-gateway? - Spring Integration Java DSL - How to invoke int-http:outbound-gateway? Spring Integration http:outbound-gateway“没有合适的HttpMessageConverter” - Spring Integration http:outbound-gateway “no suitable HttpMessageConverter” Spring Integration http出站网关和UTF-8 - Spring Integration http outbound-gateway and UTF-8 Spring Integration单元测试http:outbound-gateway - Spring Integration unit test http:outbound-gateway 处理 ws:outbound-gateway 中的 404 错误 - handle 404 error in ws:outbound-gateway Spring Integration-网址变量在http:outbound-gateway中不起作用 - Spring Integration - url-variable not working in http:outbound-gateway Spring Integration-占位符未注入ws:outbound-gateway uri(仅用于单元测试) - Spring Integration - placeholders not injected into ws:outbound-gateway uri (only for unit tests) Spring集成ws:outbound-gateway jaxb内部服务器错误[500] - Spring integration ws:outbound-gateway jaxb internal server error[500] Http出站网关:是否可以处理非HTTP错误,尤其是“无连接”错误? - Http outbound-gateway: is there a way to handle not HTTP errors and, in particular, “no connection” error? Spring Integration:如何使用http:outbound-gateway将字节数组作为POST参数发送? - Spring Integration: how to send a Byte Array as POST parameter with an http:outbound-gateway?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM