cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

GET error 400 Body in response SAP HCI / Rest POST Request (HTTP)

Former Member
0 Kudos
7,828

Hi Experts,

We have an scenario where we're posting some data via a REST service (POST Operation), we're using a HTTP Adapter in SAP HCI, sometimes the fields are sent in a wrong way, and we got 400 error from the server due a validation payload, and it's correct, but We'd like to get the body response error from HTTP adapter and send it back to ECC.

Have anyone already done this?

Any Idea on how can We do that?

Thanks

View Entire Topic
Sriprasadsbhat
Active Contributor

Hello Bruno.

I think you have to write script for response and then send it back to SAP ERP.

https://uacp2.hana.ondemand.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/a443efe1d5d2403f...

Below is the sample script given in SAP HELP

import com.sap.gateway.ip.core.customdev.util.Message;

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;
}

You can form the XML in Script itself or you can have a content modifier after script the build XML using the properties set in the script.

Regards,

Sriprasad Shivaram Bhat

Former Member
0 Kudos

Thanks for sharing this, you made my day!

Former Member
0 Kudos

Thanks for sharing, this also made my day.

You Rock!!

emiljessen
Explorer
0 Kudos

Still works! Just what I was looking for. Thanks for sharing.

Br, Emil