on 2017 Apr 04 7:51 PM
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
Request clarification before answering.
Hello Bruno.
I think you have to write script for response and then send it back to SAP ERP.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 18 | |
| 7 | |
| 6 | |
| 6 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.