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

SAP CPI : iFlow - Exception process block - access HTTP status code

KeshavDesai
Explorer
0 Likes
4,686

Hello experts,

${header.CamelHttpResponseCode} : Is this the correct header parameter to get the HTTP status code when an exception occurs?

I am unable to access this value in exception sub-process block in the iFlow.

Regards

Accepted Solutions (1)

Accepted Solutions (1)

r_herrmann
Active Contributor

Hi Keshav,

in case of an exception (subprocess) it should also be possible to read the status code from the exception. In Groovy you would write something like this:

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


def Message processData(Message message) {
 
	def map = message.getProperties();
	def ex = map.get("CamelExceptionCaught");
	if (ex!=null) {
		message.setHeader("status_code", ex.getStatusCode());
    }      
	return message;
}

Then you could access the status code after the script step via the "status_code" header for routing purposes, etc.

Best regards,
Raffael

KeshavDesai
Explorer
0 Likes

Thanks Raffael. Yes, I can get the status code in the script. Surprised why the same cannot be accessed using the simple expression in the content modifier [by creating a new header/exchange property/even while setting the body].

Also, what other methods can we access from the exception object [

def ex = map.get("CamelExceptionCaught");]? In my case I am getting a

org.apache.cxf.binding.soap.SoapFault exception.

r_herrmann
Active Contributor
0 Likes

Hi Keshav,

there are also methods like "getStatusText" and "getResponseBody" in the exception object. Check the samples over here: https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/a443efe1d5d2403fb95ee9def1a...

In addition, maybe you don't need a script to access the status text, but can set it directly to a property by using Apache Simple Expression. It could work like the following (but I haven't tested it - so no proof that it works):

${property.CamelExceptionCaught.getStatusCode()}
KeshavDesai
Explorer
0 Likes

Thanks for your reply Raffael. Unfortunately, not all methods [get*] listed for the SoapFault in

https://cxf.apache.org/javadoc/latest/org/apache/cxf/binding/soap/SoapFault.html will return details of the fault. I am, however able to get the status code and a message [does not detail the cause of exception], to use in the error log for my response message.

I did notice that in message monitoring, 'Open Text View' in the Logs [even in case of log level Info] has details of the exception, like the status text etc. I believe to get these log details, we will have to use the ODATA API to query the message processing log (?)

Answers (0)