Hi,
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 com.sap.gateway.ip.core.customdev.util.Message; 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 message.setProperty("http.ResponseBody",ex.getResponseBody()); // copy the http error response to the message body message.setBody(ex.getResponseBody()); // copy the value of http error code (i.e. 500) to a property message.setProperty("http.StatusCode",ex.getStatusCode()); // copy the value of http error text (i.e. "Internal Server Error") to a property message.setProperty("http.StatusText",ex.getStatusText()); } } return message; }
Thank you,
Madhu