Skip to Content

SAP Cloud Platform Integration - Groovy Extract httpresponseexception

Hi to all,

as required by the title, is there anyway to extract the HttpResponseException?
In my scenario( CPI--> LMS) I am receiving the HTTP 500 Internal Server error in CPI with HTTP Response Exception, but i want manage this exception retrieving the JSON Payload.
I tried to do the same call with POSTMAN directly to LMS Endpoint

And i am receiving the json error.
In attachment the complete flow and direct call on LMS Endpoint with JSON response in http500.
flow.png
endpoint.png
httpresponsebody.png
Thanks in advance

flow.png (26.8 kB)
endpoint.png (5.4 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Posted on Aug 03, 2020 at 11:46 AM

    Hello Claudio,

    while Sriprasad Shivaram Bhat's answer is true for HTTP exceptions, it doesn't work in your setup because you use the Successfactors adapter which behaves differently compared to the plain http adapter.

    As you have seen (and mentioned in the comments) you can't call the "getResponseBody()" function, because the Successfactors adapter doesn't throw an AhcOperationFailedException but an ODataProcessingException which has no such method. By use of the following code snippet, you can check which functions an exception class does support:

    //internal
    import com.sap.gateway.ip.core.customdev.util.Message
    import groovy.xml.MarkupBuilder
    
    Message processData(Message message) {
     
       def sw = new StringWriter()
       def builder = new MarkupBuilder(sw)
       builder.methods {
          com.sap.gateway.core.ip.component.exception.ODataProcessingException.getMethods().each { m ->
             method(m.toString())
          }
       }
      
       message.setBody(sw.toString()) 
       return message
    }

    The result of this call shows, that there's no function which returns the HTML body:

    <methods>
      <method>public static com.sap.gateway.core.ip.component.exception.ODataProcessingException com.sap.gateway.core.ip.component.exception.ODataProcessingException.throwException(java.lang.String)</method>
      <method>public static com.sap.gateway.core.ip.component.exception.ODataProcessingException com.sap.gateway.core.ip.component.exception.ODataProcessingException.throwException(java.lang.String,java.lang.Throwable)</method>
      <method>public java.lang.String java.lang.Throwable.getMessage()</method>
      <method>public java.lang.String java.lang.Throwable.getLocalizedMessage()</method>
      <method>public synchronized java.lang.Throwable java.lang.Throwable.getCause()</method>
      <method>public synchronized java.lang.Throwable java.lang.Throwable.initCause(java.lang.Throwable)</method>
      <method>public java.lang.String java.lang.Throwable.toString()</method>
      <method>public void java.lang.Throwable.printStackTrace()</method>
      <method>public void java.lang.Throwable.printStackTrace(java.io.PrintStream)</method>
      <method>public void java.lang.Throwable.printStackTrace(java.io.PrintWriter)</method>
      <method>public synchronized java.lang.Throwable java.lang.Throwable.fillInStackTrace()</method>
      <method>public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()</method>
      <method>public void java.lang.Throwable.setStackTrace(java.lang.StackTraceElement[])</method>
      <method>public final synchronized void java.lang.Throwable.addSuppressed(java.lang.Throwable)</method>
      <method>public final synchronized java.lang.Throwable[] java.lang.Throwable.getSuppressed()</method>
      <method>public final native java.lang.Class java.lang.Object.getClass()</method>
      <method>public native int java.lang.Object.hashCode()</method>
      <method>public boolean java.lang.Object.equals(java.lang.Object)</method>
      <method>public final native void java.lang.Object.notify()</method>
      <method>public final native void java.lang.Object.notifyAll()</method>
      <method>public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException</method>
      <method>public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException</method>
      <method>public final void java.lang.Object.wait() throws java.lang.InterruptedException</method>
    </methods>
    

    So from my perspective you have only two options:

    1. Stick with Successfactors adapter and accept that you can't access the HTML body from the exceptions thrown.
    2. Switch from Successfactors adapter to plain HTTP adapter. Then you can access the body, but will lose all the comfort of the Successfactors adapter...
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 03, 2020 at 11:52 AM

    Hello Raffael,

    As per my understanding this is not yet supported so I have already requested Claudio to open ticket to LOD-HCI-PI-GB.

    Regards,

    Sriprasad Shivaram Bhat

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 03, 2020 at 10:58 AM

    Hello Claudio,

    Please refer below script which provides details on how to retrieve HTTP Error Response ( use this script inside exception subprocess so that you will be able to capture the error whenever there is a failure ).

    https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/a443efe1d5d2403fb95ee9def1a672d4.html

    Regards,

    Sriprasad Shivaram Bhat

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Sriprasad,

      i used the script mentioned, but seems that it just extract the exception for
      if(ex.getClass().getCanonicalName().equals("org.apache.camel.component.ahc.AhcOperationFailedException"))

      In my case the exception seems be different, i tried to remove the if condition, but seems that the excepiton isn't able to manage the payload:

      Error Details com.sap.it.rt.adapter.http.api.exception.HttpResponseException: An internal server error occured: No signature of method: com.sap.gateway.core.ip.component.exception.ODataProcessingException.getResponseBody() is applicable for argument types: () values: []. The MPL ID for the failed message is : AF8n8pP3M_fklICuwcddZLp9sDF5 For more details please check tail log

      Thanks

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.