Spring Integration Java DSL and Http.outboundGateway: How to get the real error message JSON












2















How to get the real error message JSON when the Http.outboundGateway call is failed.



For example my program does the HTTP POST. The operation fails with the error code 400 Bad Request and the real error message is (tested with the Postman):



{
"name": [
"This field is needed."
]
}


I have the error channel like this:



    @Bean
private IntegrationFlow myErrorChannel() {
return f -> f.handle("myErrorHandler", "handle")
....
;
}


and the Class MyErrorHandler is like this:



@Service
public class MyErrorHandler {
@ServiceActivator
public Message<MessageHandlingException> handle(Message<MessageHandlingException> message) {
...
}


}



Does the MessageHandlingException contain the real error message?



    {
"name": [
"This field is needed."
]
}


I debugged the code and checked the MessageHandlingException exception and it seems it doesn't contain the real error message. The detailMessage contains the text 400 Bad Request, but I want to know the real error message.



How to get the real error message?



Edit:



This is working (I'm assigning the real error message to the new payload):



        final RestClientResponseException clientException = (RestClientResponseException) messagingHandlingException.getCause();
payload = clientException.getResponseBodyAsString();









share|improve this question





























    2















    How to get the real error message JSON when the Http.outboundGateway call is failed.



    For example my program does the HTTP POST. The operation fails with the error code 400 Bad Request and the real error message is (tested with the Postman):



    {
    "name": [
    "This field is needed."
    ]
    }


    I have the error channel like this:



        @Bean
    private IntegrationFlow myErrorChannel() {
    return f -> f.handle("myErrorHandler", "handle")
    ....
    ;
    }


    and the Class MyErrorHandler is like this:



    @Service
    public class MyErrorHandler {
    @ServiceActivator
    public Message<MessageHandlingException> handle(Message<MessageHandlingException> message) {
    ...
    }


    }



    Does the MessageHandlingException contain the real error message?



        {
    "name": [
    "This field is needed."
    ]
    }


    I debugged the code and checked the MessageHandlingException exception and it seems it doesn't contain the real error message. The detailMessage contains the text 400 Bad Request, but I want to know the real error message.



    How to get the real error message?



    Edit:



    This is working (I'm assigning the real error message to the new payload):



            final RestClientResponseException clientException = (RestClientResponseException) messagingHandlingException.getCause();
    payload = clientException.getResponseBodyAsString();









    share|improve this question



























      2












      2








      2








      How to get the real error message JSON when the Http.outboundGateway call is failed.



      For example my program does the HTTP POST. The operation fails with the error code 400 Bad Request and the real error message is (tested with the Postman):



      {
      "name": [
      "This field is needed."
      ]
      }


      I have the error channel like this:



          @Bean
      private IntegrationFlow myErrorChannel() {
      return f -> f.handle("myErrorHandler", "handle")
      ....
      ;
      }


      and the Class MyErrorHandler is like this:



      @Service
      public class MyErrorHandler {
      @ServiceActivator
      public Message<MessageHandlingException> handle(Message<MessageHandlingException> message) {
      ...
      }


      }



      Does the MessageHandlingException contain the real error message?



          {
      "name": [
      "This field is needed."
      ]
      }


      I debugged the code and checked the MessageHandlingException exception and it seems it doesn't contain the real error message. The detailMessage contains the text 400 Bad Request, but I want to know the real error message.



      How to get the real error message?



      Edit:



      This is working (I'm assigning the real error message to the new payload):



              final RestClientResponseException clientException = (RestClientResponseException) messagingHandlingException.getCause();
      payload = clientException.getResponseBodyAsString();









      share|improve this question
















      How to get the real error message JSON when the Http.outboundGateway call is failed.



      For example my program does the HTTP POST. The operation fails with the error code 400 Bad Request and the real error message is (tested with the Postman):



      {
      "name": [
      "This field is needed."
      ]
      }


      I have the error channel like this:



          @Bean
      private IntegrationFlow myErrorChannel() {
      return f -> f.handle("myErrorHandler", "handle")
      ....
      ;
      }


      and the Class MyErrorHandler is like this:



      @Service
      public class MyErrorHandler {
      @ServiceActivator
      public Message<MessageHandlingException> handle(Message<MessageHandlingException> message) {
      ...
      }


      }



      Does the MessageHandlingException contain the real error message?



          {
      "name": [
      "This field is needed."
      ]
      }


      I debugged the code and checked the MessageHandlingException exception and it seems it doesn't contain the real error message. The detailMessage contains the text 400 Bad Request, but I want to know the real error message.



      How to get the real error message?



      Edit:



      This is working (I'm assigning the real error message to the new payload):



              final RestClientResponseException clientException = (RestClientResponseException) messagingHandlingException.getCause();
      payload = clientException.getResponseBodyAsString();






      spring-integration spring-integration-dsl






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 '18 at 12:42







      Mike

















      asked Nov 21 '18 at 11:00









      MikeMike

      4111




      4111
























          1 Answer
          1






          active

          oldest

          votes


















          1














          The Resttemplate uses a DefaultResponseErrorHandler by default. That one has a logic like:



          protected void handleError(ClientHttpResponse response, HttpStatus statusCode) throws IOException {
          String statusText = response.getStatusText();
          HttpHeaders headers = response.getHeaders();
          byte body = getResponseBody(response);
          Charset charset = getCharset(response);
          switch (statusCode.series()) {
          case CLIENT_ERROR:
          throw HttpClientErrorException.create(statusCode, statusText, headers, body, charset);
          case SERVER_ERROR:
          throw HttpServerErrorException.create(statusCode, statusText, headers, body, charset);
          default:
          throw new UnknownHttpStatusCodeException(statusCode.value(), statusText, headers, body, charset);
          }
          }


          An exception from here is thrown to the HttpRequestExecutingMessageHandler which really wraps it into the MessageHandlingException.



          Since you say that you can handle the last one via your MyErrorHandler, I would suggest you just take a look into the cause of the MessageHandlingException, and you'll that RestClientResponseException with all the required info from the response.






          share|improve this answer
























          • I checked with debugger and then logged message.getPayload().getMostSpecificCause(), but the result is org.springframework.web.client.HttpClientErrorException: 400 Bad Request. It is not what I wanted. Is there something I'm doing wrong?

            – Mike
            Nov 22 '18 at 7:27











          • And also I can see from the complete stack trace that there is not the information what I need. Is there something wrong I'm doing??

            – Mike
            Nov 23 '18 at 6:53











          • I think the information you need is indeed not included into stack trace, but that is a part of getters on the RestClientResponseException

            – Artem Bilan
            Nov 23 '18 at 13:23











          • Thanks, just you said. Added the answer above.

            – Mike
            Nov 28 '18 at 12:43











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410674%2fspring-integration-java-dsl-and-http-outboundgateway-how-to-get-the-real-error%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          The Resttemplate uses a DefaultResponseErrorHandler by default. That one has a logic like:



          protected void handleError(ClientHttpResponse response, HttpStatus statusCode) throws IOException {
          String statusText = response.getStatusText();
          HttpHeaders headers = response.getHeaders();
          byte body = getResponseBody(response);
          Charset charset = getCharset(response);
          switch (statusCode.series()) {
          case CLIENT_ERROR:
          throw HttpClientErrorException.create(statusCode, statusText, headers, body, charset);
          case SERVER_ERROR:
          throw HttpServerErrorException.create(statusCode, statusText, headers, body, charset);
          default:
          throw new UnknownHttpStatusCodeException(statusCode.value(), statusText, headers, body, charset);
          }
          }


          An exception from here is thrown to the HttpRequestExecutingMessageHandler which really wraps it into the MessageHandlingException.



          Since you say that you can handle the last one via your MyErrorHandler, I would suggest you just take a look into the cause of the MessageHandlingException, and you'll that RestClientResponseException with all the required info from the response.






          share|improve this answer
























          • I checked with debugger and then logged message.getPayload().getMostSpecificCause(), but the result is org.springframework.web.client.HttpClientErrorException: 400 Bad Request. It is not what I wanted. Is there something I'm doing wrong?

            – Mike
            Nov 22 '18 at 7:27











          • And also I can see from the complete stack trace that there is not the information what I need. Is there something wrong I'm doing??

            – Mike
            Nov 23 '18 at 6:53











          • I think the information you need is indeed not included into stack trace, but that is a part of getters on the RestClientResponseException

            – Artem Bilan
            Nov 23 '18 at 13:23











          • Thanks, just you said. Added the answer above.

            – Mike
            Nov 28 '18 at 12:43
















          1














          The Resttemplate uses a DefaultResponseErrorHandler by default. That one has a logic like:



          protected void handleError(ClientHttpResponse response, HttpStatus statusCode) throws IOException {
          String statusText = response.getStatusText();
          HttpHeaders headers = response.getHeaders();
          byte body = getResponseBody(response);
          Charset charset = getCharset(response);
          switch (statusCode.series()) {
          case CLIENT_ERROR:
          throw HttpClientErrorException.create(statusCode, statusText, headers, body, charset);
          case SERVER_ERROR:
          throw HttpServerErrorException.create(statusCode, statusText, headers, body, charset);
          default:
          throw new UnknownHttpStatusCodeException(statusCode.value(), statusText, headers, body, charset);
          }
          }


          An exception from here is thrown to the HttpRequestExecutingMessageHandler which really wraps it into the MessageHandlingException.



          Since you say that you can handle the last one via your MyErrorHandler, I would suggest you just take a look into the cause of the MessageHandlingException, and you'll that RestClientResponseException with all the required info from the response.






          share|improve this answer
























          • I checked with debugger and then logged message.getPayload().getMostSpecificCause(), but the result is org.springframework.web.client.HttpClientErrorException: 400 Bad Request. It is not what I wanted. Is there something I'm doing wrong?

            – Mike
            Nov 22 '18 at 7:27











          • And also I can see from the complete stack trace that there is not the information what I need. Is there something wrong I'm doing??

            – Mike
            Nov 23 '18 at 6:53











          • I think the information you need is indeed not included into stack trace, but that is a part of getters on the RestClientResponseException

            – Artem Bilan
            Nov 23 '18 at 13:23











          • Thanks, just you said. Added the answer above.

            – Mike
            Nov 28 '18 at 12:43














          1












          1








          1







          The Resttemplate uses a DefaultResponseErrorHandler by default. That one has a logic like:



          protected void handleError(ClientHttpResponse response, HttpStatus statusCode) throws IOException {
          String statusText = response.getStatusText();
          HttpHeaders headers = response.getHeaders();
          byte body = getResponseBody(response);
          Charset charset = getCharset(response);
          switch (statusCode.series()) {
          case CLIENT_ERROR:
          throw HttpClientErrorException.create(statusCode, statusText, headers, body, charset);
          case SERVER_ERROR:
          throw HttpServerErrorException.create(statusCode, statusText, headers, body, charset);
          default:
          throw new UnknownHttpStatusCodeException(statusCode.value(), statusText, headers, body, charset);
          }
          }


          An exception from here is thrown to the HttpRequestExecutingMessageHandler which really wraps it into the MessageHandlingException.



          Since you say that you can handle the last one via your MyErrorHandler, I would suggest you just take a look into the cause of the MessageHandlingException, and you'll that RestClientResponseException with all the required info from the response.






          share|improve this answer













          The Resttemplate uses a DefaultResponseErrorHandler by default. That one has a logic like:



          protected void handleError(ClientHttpResponse response, HttpStatus statusCode) throws IOException {
          String statusText = response.getStatusText();
          HttpHeaders headers = response.getHeaders();
          byte body = getResponseBody(response);
          Charset charset = getCharset(response);
          switch (statusCode.series()) {
          case CLIENT_ERROR:
          throw HttpClientErrorException.create(statusCode, statusText, headers, body, charset);
          case SERVER_ERROR:
          throw HttpServerErrorException.create(statusCode, statusText, headers, body, charset);
          default:
          throw new UnknownHttpStatusCodeException(statusCode.value(), statusText, headers, body, charset);
          }
          }


          An exception from here is thrown to the HttpRequestExecutingMessageHandler which really wraps it into the MessageHandlingException.



          Since you say that you can handle the last one via your MyErrorHandler, I would suggest you just take a look into the cause of the MessageHandlingException, and you'll that RestClientResponseException with all the required info from the response.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 14:13









          Artem BilanArtem Bilan

          67.5k84973




          67.5k84973













          • I checked with debugger and then logged message.getPayload().getMostSpecificCause(), but the result is org.springframework.web.client.HttpClientErrorException: 400 Bad Request. It is not what I wanted. Is there something I'm doing wrong?

            – Mike
            Nov 22 '18 at 7:27











          • And also I can see from the complete stack trace that there is not the information what I need. Is there something wrong I'm doing??

            – Mike
            Nov 23 '18 at 6:53











          • I think the information you need is indeed not included into stack trace, but that is a part of getters on the RestClientResponseException

            – Artem Bilan
            Nov 23 '18 at 13:23











          • Thanks, just you said. Added the answer above.

            – Mike
            Nov 28 '18 at 12:43



















          • I checked with debugger and then logged message.getPayload().getMostSpecificCause(), but the result is org.springframework.web.client.HttpClientErrorException: 400 Bad Request. It is not what I wanted. Is there something I'm doing wrong?

            – Mike
            Nov 22 '18 at 7:27











          • And also I can see from the complete stack trace that there is not the information what I need. Is there something wrong I'm doing??

            – Mike
            Nov 23 '18 at 6:53











          • I think the information you need is indeed not included into stack trace, but that is a part of getters on the RestClientResponseException

            – Artem Bilan
            Nov 23 '18 at 13:23











          • Thanks, just you said. Added the answer above.

            – Mike
            Nov 28 '18 at 12:43

















          I checked with debugger and then logged message.getPayload().getMostSpecificCause(), but the result is org.springframework.web.client.HttpClientErrorException: 400 Bad Request. It is not what I wanted. Is there something I'm doing wrong?

          – Mike
          Nov 22 '18 at 7:27





          I checked with debugger and then logged message.getPayload().getMostSpecificCause(), but the result is org.springframework.web.client.HttpClientErrorException: 400 Bad Request. It is not what I wanted. Is there something I'm doing wrong?

          – Mike
          Nov 22 '18 at 7:27













          And also I can see from the complete stack trace that there is not the information what I need. Is there something wrong I'm doing??

          – Mike
          Nov 23 '18 at 6:53





          And also I can see from the complete stack trace that there is not the information what I need. Is there something wrong I'm doing??

          – Mike
          Nov 23 '18 at 6:53













          I think the information you need is indeed not included into stack trace, but that is a part of getters on the RestClientResponseException

          – Artem Bilan
          Nov 23 '18 at 13:23





          I think the information you need is indeed not included into stack trace, but that is a part of getters on the RestClientResponseException

          – Artem Bilan
          Nov 23 '18 at 13:23













          Thanks, just you said. Added the answer above.

          – Mike
          Nov 28 '18 at 12:43





          Thanks, just you said. Added the answer above.

          – Mike
          Nov 28 '18 at 12:43




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410674%2fspring-integration-java-dsl-and-http-outboundgateway-how-to-get-the-real-error%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          鏡平學校

          ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

          Why https connections are so slow when debugging (stepping over) in Java?