on 10-19-2017 9:54 AM
Hi Guys,
I'm trying to figure out a way on how to throw HTTP 500 response and set some custom error description in the response header incase of an error during validation or message failure. Eventually, I would also like to put all error details in the response body.
In the above exception subflow which begins with "Error Start" event and ends with "End Message" Event, I have the written the following script to explicitly set the status of the code to 500 and some custom header text.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
def body = message.getBody();
def map = message.getProperties();
def ex = map.get("CamelExceptionCaught");
if (ex!=null) {
message.setBody('Test Body from CamelException');
message.setHeader("STATUS_CODE", 500);
message.setHeader("STATUS_TEXT", "TEST Header Validation failed from CamelException");
}
else{
message.setBody('test123');
message.setHeader("STATUS_CODE", 500);
}
return message;
}
Content modifier body
<faultMessage>
<success>false</success>
<error>
<message>${exception.message}</message>
<body>${in.body}</body>
</error>
</faultMessage>
Response:
Issue: The response status still stays 200 although I explicitly set it to HTTP 500. body content is correct though
Also noticeably when I change the "End Message" to "Error End" event in the exception subflow. I do get the HTTP 500 response, which I wanted . However, it ignores the body and the Header text I had set via the script.
Issue: Status is set to 500 but the body is overwritten with standard exception message.
How do I set HTTP 500 and Custom Header Text and Body in case of an error ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Amber,
With script also it works but you need to use above header which is specific to HTTP adapter of SAP CPI.
def Message processData(Message message) {
def map = message.getHeaders();
map.put("CamelHttpResponseCode",900);
message.setBody("CustomError");
return message;
}
Regards,
Sriprasad Shivaram Bhat
Hi Amber,
Did you solve the issue? I experience the exact same issue.
Regards,
Daniel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.