Camel
  1. Camel
  2. CAMEL-4324

Response body lost when an HTTP error code is returned

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.6.0, 2.7.0, 2.8.0
    • Fix Version/s: 2.8.2, 2.9.0
    • Component/s: camel-restlet
    • Labels:
      None
    • Estimated Complexity:
      Novice

      Description

      When a REST service returns an HTTP error code (e.g. 404) with some content in the response body, this body is not correctly copied into the exception.
      This results e.g. in $

      {exception.responseBody} having a value like "org.restlet.data.Response@17bf0a7" in the following route fragment :

      <doTry>
      <to uri="restlet:http://my.service.com/ws/{id}"/>
      <doCatch>
      <exception>org.apache.camel.CamelException</exception>
      <log message="body is : ${exception.responseBody}

      "/>
      </doCatch>
      </doTry>

      The problem is probably due to the statement (class org.apache.camel.component.restlet.RestletProducer, method populateRestletProducerException) :

         String copy = response.toString();
      

      that should be instead something like :

         String copy = null;
         if (response.getEntity() != null) {
             // get content text
             copy = response.getEntity().getText();
         }
      

        Activity

        Cedric de Launois created issue -
        Cedric de Launois made changes -
        Field Original Value New Value
        Description When a REST service returns an HTTP error code (e.g. 404) with some content in the response body, this body is not correctly copied into the exception.
        This results e.g. in ${exception.responseBody} having a value like "org.restlet.data.Response@17bf0a7" in the following route fragment :

        <doTry>
            <to uri="restlet:http://my.service.com/ws/{id}"/>
            <doCatch>
                <exception>org.apache.camel.CamelException</exception>
                <log message="body is : ${exception.responseBody}"/>
            </doCatch>
        </doTry>

        The problem is probably due to the statement :
           String copy = response.toString();

        that should be instead something like :
           String copy = null;
           if (response.getEntity() != null) {
               // get content text
               copy = response.getEntity().getText();
           }
        When a REST service returns an HTTP error code (e.g. 404) with some content in the response body, this body is not correctly copied into the exception.
        This results e.g. in ${exception.responseBody} having a value like "org.restlet.data.Response@17bf0a7" in the following route fragment :

        <doTry>
            <to uri="restlet:http://my.service.com/ws/{id}"/>
            <doCatch>
                <exception>org.apache.camel.CamelException</exception>
                <log message="body is : ${exception.responseBody}"/>
            </doCatch>
        </doTry>

        The problem is probably due to the statement (class org.apache.camel.component.restlet.RestletProducer, method populateRestletProducerException) :
           String copy = response.toString();

        that should be instead something like :
           String copy = null;
           if (response.getEntity() != null) {
               // get content text
               copy = response.getEntity().getText();
           }
        Cedric de Launois made changes -
        Description When a REST service returns an HTTP error code (e.g. 404) with some content in the response body, this body is not correctly copied into the exception.
        This results e.g. in ${exception.responseBody} having a value like "org.restlet.data.Response@17bf0a7" in the following route fragment :

        <doTry>
            <to uri="restlet:http://my.service.com/ws/{id}"/>
            <doCatch>
                <exception>org.apache.camel.CamelException</exception>
                <log message="body is : ${exception.responseBody}"/>
            </doCatch>
        </doTry>

        The problem is probably due to the statement (class org.apache.camel.component.restlet.RestletProducer, method populateRestletProducerException) :
           String copy = response.toString();

        that should be instead something like :
           String copy = null;
           if (response.getEntity() != null) {
               // get content text
               copy = response.getEntity().getText();
           }
        When a REST service returns an HTTP error code (e.g. 404) with some content in the response body, this body is not correctly copied into the exception.
        This results e.g. in ${exception.responseBody} having a value like "org.restlet.data.Response@17bf0a7" in the following route fragment :

        <doTry>
            <to uri="restlet:http://my.service.com/ws/{id}"/>
            <doCatch>
                <exception>org.apache.camel.CamelException</exception>
                <log message="body is : ${exception.responseBody}"/>
            </doCatch>
        </doTry>

        The problem is probably due to the statement (class org.apache.camel.component.restlet.RestletProducer, method populateRestletProducerException) :
        {code}
           String copy = response.toString();
        {code}

        that should be instead something like :
        {code}
           String copy = null;
           if (response.getEntity() != null) {
               // get content text
               copy = response.getEntity().getText();
           }
        {code}

        Cedric de Launois made changes -
        Description When a REST service returns an HTTP error code (e.g. 404) with some content in the response body, this body is not correctly copied into the exception.
        This results e.g. in ${exception.responseBody} having a value like "org.restlet.data.Response@17bf0a7" in the following route fragment :

        <doTry>
            <to uri="restlet:http://my.service.com/ws/{id}"/>
            <doCatch>
                <exception>org.apache.camel.CamelException</exception>
                <log message="body is : ${exception.responseBody}"/>
            </doCatch>
        </doTry>

        The problem is probably due to the statement (class org.apache.camel.component.restlet.RestletProducer, method populateRestletProducerException) :
        {code}
           String copy = response.toString();
        {code}

        that should be instead something like :
        {code}
           String copy = null;
           if (response.getEntity() != null) {
               // get content text
               copy = response.getEntity().getText();
           }
        {code}

        When a REST service returns an HTTP error code (e.g. 404) with some content in the response body, this body is not correctly copied into the exception.
        This results e.g. in ${exception.responseBody} having a value like "org.restlet.data.Response@17bf0a7" in the following route fragment :

        {code:xml}
        <doTry>
            <to uri="restlet:http://my.service.com/ws/{id}"/>
            <doCatch>
                <exception>org.apache.camel.CamelException</exception>
                <log message="body is : ${exception.responseBody}"/>
            </doCatch>
        </doTry>
        {code}

        The problem is probably due to the statement (class org.apache.camel.component.restlet.RestletProducer, method populateRestletProducerException) :
        {code}
           String copy = response.toString();
        {code}

        that should be instead something like :
        {code}
           String copy = null;
           if (response.getEntity() != null) {
               // get content text
               copy = response.getEntity().getText();
           }
        {code}

        Cedric de Launois made changes -
        Description When a REST service returns an HTTP error code (e.g. 404) with some content in the response body, this body is not correctly copied into the exception.
        This results e.g. in ${exception.responseBody} having a value like "org.restlet.data.Response@17bf0a7" in the following route fragment :

        {code:xml}
        <doTry>
            <to uri="restlet:http://my.service.com/ws/{id}"/>
            <doCatch>
                <exception>org.apache.camel.CamelException</exception>
                <log message="body is : ${exception.responseBody}"/>
            </doCatch>
        </doTry>
        {code}

        The problem is probably due to the statement (class org.apache.camel.component.restlet.RestletProducer, method populateRestletProducerException) :
        {code}
           String copy = response.toString();
        {code}

        that should be instead something like :
        {code}
           String copy = null;
           if (response.getEntity() != null) {
               // get content text
               copy = response.getEntity().getText();
           }
        {code}

        When a REST service returns an HTTP error code (e.g. 404) with some content in the response body, this body is not correctly copied into the exception.
        This results e.g. in ${exception.responseBody} having a value like "org.restlet.data.Response@17bf0a7" in the following route fragment :

        <doTry>
            <to uri="restlet:http://my.service.com/ws/{id}"/>
            <doCatch>
                <exception>org.apache.camel.CamelException</exception>
                <log message="body is : ${exception.responseBody}"/>
            </doCatch>
        </doTry>

        The problem is probably due to the statement (class org.apache.camel.component.restlet.RestletProducer, method populateRestletProducerException) :
        {code}
           String copy = response.toString();
        {code}

        that should be instead something like :
        {code}
           String copy = null;
           if (response.getEntity() != null) {
               // get content text
               copy = response.getEntity().getText();
           }
        {code}

        Hide
        Claus Ibsen added a comment -

        Thanks for reporting Cedric do you want to try to work on a patch? with an unit test that reproduces the issue and proves the fix works as expected?

        Show
        Claus Ibsen added a comment - Thanks for reporting Cedric do you want to try to work on a patch? with an unit test that reproduces the issue and proves the fix works as expected?
        Claus Ibsen made changes -
        Fix Version/s 2.9.0 [ 12316374 ]
        Estimated Complexity Moderate Novice
        Priority Major [ 3 ] Minor [ 4 ]
        Hide
        Cedric de Launois added a comment -

        Claus, I won't be able to work on this for the next 3 weeks. If it is ok for you to wait, then I will work on the patch.

        Show
        Cedric de Launois added a comment - Claus, I won't be able to work on this for the next 3 weeks. If it is ok for you to wait, then I will work on the patch.
        Willem Jiang made changes -
        Assignee Willem Jiang [ njiang ]
        Hide
        Willem Jiang added a comment -

        Applied patch into trunk.

        Show
        Willem Jiang added a comment - Applied patch into trunk.
        Willem Jiang made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        J. Daniel Kulp <dkulp@apache.org> committed a6c2f39c5719f656dc24bb0c5012161d0e351d23 (3 files)
        Daniel Kulp made changes -
        Fix Version/s 2.8.2 [ 12317866 ]

          People

          • Assignee:
            Willem Jiang
            Reporter:
            Cedric de Launois
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development