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

SAP CPI exception: getStatusCode() is applicable for argument types: () values: []

prabhu_s2
Active Contributor
0 Likes
5,224

Dear All

I am trying to get the http status code when an exception is called. I think i have the right groovy in place but getting the below error:

java.lang.NoSuchMethodException: No signature of method: com.sap.it.rt.adapter.openconnectors.exceptions.OpenConnectorsException.getStatusCode() is applicable for argument types: () values: []

The message properties:


CamelExceptionCaughtcom.sap.it.rt.adapter.openconnectors.exceptions.OpenConnectorsException: HTTP operation failed : {"requestId":"5e8c93f9e4b02c84ec1e41f4","message":"Service Unavailable","providerMessage":"error - {code=503, message=The service is currently unavailable., status=UNAVAILABLE}"} status code : 503

My code:

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

Any help on this please?

Accepted Solutions (0)

Answers (2)

Answers (2)

r_herrmann
Active Contributor

Hi,

The property "CamelExceptionCaught" contains just any Exception caught by the IFlow. Those exceptions don't have to be escpecially of type "AhcOperationFailedException". (They only should inherit the Throwable class.) But the getStatusCode() method is a method of the Exception class "AhcOperationFailedException". When looking at your post, we can see your exception caught is of another type. Escpecially it is of type "OpenConnectorsException".

This exception class has no "getStatusCode" method. But what methods does it provide? By using reflection (as shown in this article by 7a519509aed84a2c9e6f627841825b5a) we can see, that the OpenConnectorsException class only brings one own (not inherited) method, called "getMessage". So the only function you can call is getMethod() which returns a String.

Nevertheless from your input above, we can see that the error messages text indeed contains a status code. So the solution might be to call getMessage to get the error text and then parse it for the status code.

The following code is "dummy" code, written out of my head. So maybe you have to correct one or two things, but in general it should work like this:

def map = message.getProperties()
def ex = map.get("CamelExceptionCaught")
    
if (ex!=null) {
  //Detect exception type
def exType = ex.getClass().getCanonicalName() if (exType == "org.apache.camel.component.ahc.AhcOperationFailedException"){ message.setHeader("HTTP_CODE", ex.getStatusCode()) } else if (exType == "com.sap.it.rt.adapter.openconnectors.exceptions.OpenConnectorsException"){ def statusCode = (ex.getMessage() =~ /status code ?: ?(\d{3})/)[0][1] message.setHeader("HTTP_CODE", statusCode) } }
Sriprasadsbhat
Active Contributor
0 Likes

Hello Prabhu,

Please refer to below help document which is applicable for HTTP adapter.

https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/a443efe1d5d2403fb95ee9def1a...

For open connector adapter you might need to white list all the headers in run time configuration and then check for the corresponding header which returning the error status code.

Regards,

Sriprasad Shivaram Bhat