Skip to Content
avatar image
Former Member

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

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Apr 05, 2017 at 04:56 AM

    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/a443efe1d5d2403fb95ee9def1a672d4.html

    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

    Add comment
    10|10000 characters needed characters exceeded