我按如下方式连接了以下设置:
1)响应&请求渠道
2)用于响应的变压器/对系统值对象的请求
3)WS请求/响应信道
4)出站网关
<!-- ~~~~~~~~~~~~~~~~~ -->
<!-- integration layer -->
<!-- ~~~~~~~~~~~~~~~~~ -->
<int:channel id="getStatusRequestChannel"/>
<int:channel id="getStatusResponseChannel"/>
<int:channel id="getStatusWSRequestChannel"/>
<int:channel id="getStatusWSResponseChannel"/>
<!-- ~~~~~~~~~~~~~~~~~~ -->
<!-- gateway definition -->
<!-- ~~~~~~~~~~~~~~~~~~ -->
<int:gateway id="mnpGateway" service-interface="com.iquest.play.integration.mnp.MNPGateway">
<int:method name="getMNPStatus" request-channel="getStatusRequestChannel" reply-channel="getStatusResponseChannel"/>
</int:gateway>
<!-- ~~~~~~~~~~~~~~ -->
<!-- channel chains -->
<!-- ~~~~~~~~~~~~~~ -->
<int:chain input-channel="getStatusRequestChannel" output-channel="getStatusWSRequestChannel">
<int:transformer ref="getStatusTransformer" method="transformMNPStatusRequest"/>
</int:chain>
<int:chain input-channel="getStatusWSResponseChannel" output-channel="getStatusResponseChannel">
<int:transformer ref="getStatusTransformer" method="transformMNPStatusResponse"/>
</int:chain>
<!-- ~~~~~~~~~~~~~~~~ -->
<!-- outbound gateway -->
<!-- ~~~~~~~~~~~~~~~~ -->
<int-ws:outbound-gateway id="getStatusOutboundGW"
request-channel="getStatusWSRequestChannel"
reply-channel="getStatusWSResponseChannel"
marshaller="marshaller"
unmarshaller="marshaller"
destination-provider="mnpUriProvider"/>
这是WSDL:
<wsdl:operation name="getCaseInfo">
<wsdl:documentation>Message</wsdl:documentation>
<wsdl:input message="tns:GetCaseInfoRequest">
</wsdl:input>
<wsdl:output message="tns:GetCaseInfoResponse">
</wsdl:output>
<wsdl:fault message="tns:GetCaseInfoError" name="getCaseInfoError">
</wsdl:fault>
</wsdl:operation>
我怎样才能抓住肥皂病?
编辑后:
我已尝试延长SoapFaultMessageResolver
并覆盖方法public void resolveFault(WebServiceMessage message) throws IOException
从那里我试图抛出一个自定义的IntegrationException(扩展IOException),我会在调用网关接口的方法中捕获它。这是调用方法:
try {
gateway.MethodA();
} catch (Exception e) {
/// I was trying to catch IntegrationException
}
问题是捕获的异常属于WebServiceIOException
类型,其根本原因为IntegrationException
,并且它会触发巨大的错误日志。所以我认为这种方法是不对的。
答案 0 :(得分:2)
<int-ws:outbound-gateway>
完全基于Spring WS的WebServiceTemplate
,因此Spring Integration中的Soap Fault没有任何停顿。
默认情况下,它将是WebServiceException
,它会从WebServiceTemplate.sendAndReceive
引发并传播到MessageHandler
,而error-channel
会将其抛给调用方或发送给{{ 1}}作为Message
payload
。
一旦使用<int:gateway>
,可能会在方法调用中捕获Exception
。
如果你想在重新抛出之前对那个错误做一些逻辑,你可以将fault-message-resolver
作为FaultMessageResolver
的实现注入<int-ws:outbound-gateway>
。
答案 1 :(得分:1)
我们可以在unmarshel期间处理soap故障消息并将相应的消息抛给错误处理程序。
本文清楚地解释了如何处理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;
}
}