如果http出站网关抛出httpstatuscodeexception ......它会冒泡到我调用网关方法的地方。我似乎无法抓住那里的例外
我有以下配置
<int:channel id="responseChannel" />
<int:gateway id="someGateway" service-interface="someinterface" default-request-channel="requestChannel" default-reply-channel="responseChannel" default-reply-timeout="${reply.timeout}">
<int:method name ="somemethod">
</int:gateway>
<int:chain id="some-gateway-chain" input-channel="requestChannel" output- channel="responseChannel">
<int:object-to-json-transformer />
<int-http:outbound-gateway url-expression="some url" http-method="POST" expected-response-type-expression="some.RESPONSE_TYPE" request-factory="somehttpClientFactory" reply-timeout="${reply.timeout}"/>
</int:chain>
编辑:--------------------------------------------- ----------
我可以这样做吗
<int:service-activator input-channel="errorChannel" output-channel="some other channel">
<int-groovy:script> how do i check if the payload.message.cause is a httpstatuscodeexception and then throw it from here
</int-groovy:script> </int:service-activator>
答案 0 :(得分:1)
向error-channel
添加<int:gateway/>
并在那里处理异常。错误通道上的消息为ErrorMessage
,其有效负载为MessagingException
,其属性为failedMessage
和cause
。
错误流可以抛出另一个异常或返回其他一些结果。
回应编辑:
嗯...
if (payload.cause instanceof ...) {
throw payload.cause
}
someOtherResult