简体   繁体   English

Spring Integration中的错误处理期间的MessageTransformation异常

[英]MessageTransformation exception during error handling in Spring Integration

I have a http inboundgateway and defined an error channel to the gateway . 我有一个http inboundgateway,并定义了通往网关的错误通道。

<int-http:inbound-gateway 
    request-channel="requestChannel"  reply-channel="replyChannel" 
        supported-methods="POST" request-payload-type="com.test.RequestWsDTO"
    path="/trips/modify" error-channel="errorChannel" >
    <int-http:request-mapping consumes="application/json" produces="application/json" />
</int-http:inbound-gateway>

From the gateway , it goes to a transformer to transform the message to an appropriate request for ws outboundgateway 从网关,它转到转换器将消息转换为对ws outboundgateway的适当请求

<int:transformer id="segmentCancelTransformer" ref="segmentCancelTransformerBean" input-channel="segmentCancelChannel"
             method="transform" output-channel="rcsChannel"/>
    <beans:bean id="segmentCancelTransformerBean" class="com.test.SegmentCancelRequestTransformer" />

I throw a runtime exception from the Transformer . 我从Transformer抛出运行时异常。

I have defined an service activator to handle the exception 我已经定义了一个服务激活器来处理异常

   <int:service-activator input-channel="errorChannel" ref="exceptionhandler" method="createErrorResponse"/>
<beans:bean id="exceptionTransformer" class="com.test.ExceptionHandler" />

In the ExceptionHandler class , I am handling the exception like 在ExceptionHandler类中,我正在像处理异常

public  ErrorDTO createErrorResponse(ErrorMessage msg) {
        System.out.println("Exception occured "+msg.getPayload());
        ErrorDTO dto=new ErrorDTO ();
      ......................

msg.getPayload() is showing the exception to be of "org.springframework.integration.transformer.MessageTransformationException" msg.getPayload()显示的异常是“ org.springframework.integration.transformer.MessageTransformationException”

Exception message stacktrace: 异常消息stacktrace:

Exception occured org.springframework.integration.transformer.MessageTransformationException: Failed to transform Message; nested exception is org.springframework.messaging.MessageHandlingException: nested exception

What am i doing wrong here ? 我在这里做错了什么?

That's really correct and also useful. 这确实是正确的,也很有用。 First, you deal with messaging where the loosely-coupling is the first of principles between components. 首先,您要处理消息传递,其中松散耦合是组件之间的第一原则。 Another advantage is the failedMessage set to the property of the MessagingException which you can use to determine the problem. 另一个优点是将failedMessage设置为MessagingException的属性,可以用来确定问题。

Since the error maybe from another thread, it's hard to determine what's wrong by just a custom exception. 由于错误可能来自另一个线程,因此仅通过自定义异常很难确定错误所在。 Anyway you always can find your own cause in the stack trace. 无论如何,您总是可以在堆栈跟踪中找到自己的原因。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM