我在<int-ws:outbound-gateway>
上处理http错误时遇到问题
我尝试在error-channel
上放置<int:gateway>
,但它似乎不起作用,因为我得到了解组异常。
另外我觉得这不对,在收到来自<int-ws:outboung-gateway>
的消息后,应该在某处抓到http错误
我的消息系统设置如下:
<int:gateway> -> channel -> transformer -> channel -> <int-ws:outboung-gateway>
问题:使用spring集成捕获http错误的正确方法是什么?
编辑后
<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:
因此,在网关上放置error-channel
之后,线程就会卡在某处。这是一个非常虚拟的问题,网关错误通道service-activator
的名称是errorHandler
,它可能被spring命名空间使用 - &gt;更改bean名称解决了问题。
答案 0 :(得分:0)
我们可以在unmarshal期间处理spring集成中的http错误。
编写自定义unmarshaller并捕获soap错误消息。
本文清楚地解释了如何处理肥皂故障信息。
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;
}
}