CPI Groovy Examples

Go to List of Examples

Getting HTTP Error Body

This example works if you are using HTTP receiver adapter.

If you are using SOAP adapter you can change adapter type to HTTP, or see the other example "Getting SOAP Error Body"

If you want to convert SOAP Receiver to HTTP Receiver:

  • Change the receiver adapter type. Enter the connection details.

  • Wrap your request message body in SOAP Envelope in a Content Modifier before calling the adapter.

  • (optional) If your service requires, you may need to add the "SOAPAction" HTTP header accordingly.

  • Add an exception subprocess to the flow and use the below Groovy script from the documentation

    Groovy IDE notice You can't test this example with GroovyIDE at the moment.


Try it on Groovy IDE
import com.sap.gateway.ip.core.customdev.util.Message;


def Message processData(Message message) {

    def map = message.getProperties();

    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")) {
            def messageLog = messageLogFactory.getMessageLog(message);
            messageLog.addAttachmentAsString("http.ResponseBody", ex.getResponseBody(), "text/plain");



    return message;