Skip to Content
Sep 12, 2020 at 10:20 PM

SAP CPI Error Handling - Read error code in exception subprocess - CamelHttpResponseCode

2727 Views Last edit Sep 12, 2020 at 10:27 PM 2 rev


I am trying to read the CamelHttpResponseCode property in the content modifier in an exception subprocess. Below is the screenshot.

I get an error "Unknown function: CamelHttpResponseCode". When I use ${property.CamelHttpResponseCode} it returns empty value.

I also have tried to use a groovy script to get the response body and response code. But I do not understand how to access these attributes in Content Modifier. Please note that I can get the exception message by using ${exception.message} in the content modifier. But my requirement is to get the response code. Appreciate your help on this.

import java.util.HashMap;
def Message processData(Message message) {
                // get a map of iflow properties
                def map = message.getProperties();
                // get an exception java class instance
                def ex = map.get("CamelExceptionCaught");
                if (ex!=null) {
                                // an http adapter throws an instance of org.apache.camel.component.ahc.AhcOperationFailedException
                                if (ex.getClass().getCanonicalName().equals("org.apache.camel.component.ahc.AhcOperationFailedException")) {
                                                // save the http error response as a message attachment 
                                                def messageLog = messageLogFactory.getMessageLog(message);
                                                messageLog.addAttachmentAsString("http.ResponseBody", ex.getResponseBody(), "text/plain");

                                                // copy the http error response to an iflow's property

                                                // copy the http error response to the message body

                                                // copy the value of http error code (i.e. 500) to a property

                                                // copy the value of http error text (i.e. "Internal Server Error") to a property

                return message;

Thank you,



iflow.png (40.9 kB)