Spring integration: handle http error with oubound gateway

前端 未结 3 1062
星月不相逢
星月不相逢 2021-01-07 12:35

How can I handle exceptions in an http outbound gateway? When i receive status code 500 or 400..., an exception is shown. So What should I do to handle http error using spr

3条回答
  •  囚心锁ツ
    2021-01-07 13:29

    I had occurred the same problem.I threw my own customized Exception and error message but always got "500 Internal server error".It's because there will be no reply message and "reply" is timeout when throw Exception.So I handle the exception by subscribing error-channel and then reply by myself.

    Message failedMessage = exception.getFailedMessage();
    Object replyChannel = new MessageHeaderAccessor(failedMessage).getReplyChannel();
    if (replyChannel != null) {
        ((MessageChannel) replyChannel).send(MessageFactory.createDataExchangeFailMessage(exception));
    }
    

提交回复
热议问题