cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Cloud Platform Integration - Groovy Extract httpresponseexception

claudiopallad
Explorer
0 Kudos

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

Accepted Solutions (0)

Answers (3)

Answers (3)

Sriprasadsbhat
Active Contributor

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

r_herrmann
Active Contributor

Hello Claudio,

while sriprasadshivaramabhat'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...
claudiopallad
Explorer
0 Kudos

Thanks Raffael,

your contribute is always precious.

Sriprasadsbhat
Active Contributor
0 Kudos

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/a443efe1d5d2403fb95ee9def1a...

Regards,

Sriprasad Shivaram Bhat

claudiopallad
Explorer
0 Kudos

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