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

XI Adapter - Error handling in SAP CPI

former_member601407
Participant
1,744

Hi,

With XI adapter, I am trying to fetch data and its working fine. But when the source fields are invalid, it is not returning any error payload, which is not getting captured in exception subprocess. With trace on XI adapter step (SAP CPI HElper extension), i can see the error message returned in LOG tab (no error ifnormation in header/properties/body). This error infirmation is only avialable in XI adapter step trace and not in exception subprocess step.

How to fetch the XI error response ? because we have a exception mapping to be done and for that, error text is needed.

Attached the XI adapter step trace screenshot. Its available only in LOG tab, hence how to capture these error texts in content modifier ?

Accepted Solutions (0)

Answers (3)

Answers (3)

miguel_motta
Participant
0 Kudos

Hi,

I was researching exception handling for XI and found this thread. Since we don't have any proposed solutions, I decided to investigate further on by my self.

I know this thread is old and maybe everyone has already found a solution, but for reference, here's what I did.

I don't have much knowledge on Groovy, so there may be improvements that could be made to the code and I would appreciate your feedback.

I get the base of this code from here.
https://help.sap.com/docs/cloud-integration/sap-cloud-integration/script-example-for-exception-handl...

 

 

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
    
    // get a map of properties
    def map = message.getProperties();
    
    // get an exception java class instance
    def ex = map.get("CamelExceptionCaught");
    
    if (ex!=null) {
     
        // an XI adapter throws an instance of org.apache.cxf.binding.soap.SoapFault
        if (ex.getClass().getCanonicalName().equals("org.apache.cxf.binding.soap.SoapFault")) {
            
            // get tag "Code" of XML exception
            def code = ex.getDetail().getElementsByTagNameNS("*", "Code").item(0).getTextContent().trim();
            
            // get tag "Stack" of XML exception
            def error = ex.getDetail().getElementsByTagNameNS("*", "Stack").item(0).getTextContent().trim();
            
            // set "Code" and "Stack" values on response body
            message.setBody(code + "\r\n" + error);
            
            // change http code to 500 (Internal Server Error)
            def header = message.getHeaders();
            message.setHeader("CamelHttpResponseCode", "500");
            
        }
        
    }

    return message;

}

 

Option to send full detail of exception to response payload that I hadn't found before.
Based on https://community.sap.com/t5/technology-blogs-by-members/fetch-soap-fault-error-response-from-receiv...  

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.xml.*;
def Message processData(Message message) {
    
    // get a map of properties
    def map = message.getProperties();
    
    // get an exception java class instance
    def ex = map.get("CamelExceptionCaught");
    
    if (ex!=null) {
     
        // an XI adapter throws an instance of org.apache.cxf.binding.soap.SoapFault
        if (ex.getClass().getCanonicalName().equals("org.apache.cxf.binding.soap.SoapFault")) {
            
            def xml = XmlUtil.serialize(ex.getDetail());    
            message.setBody(xml);

            // change http code to 500 (Internal Server Error)
            def header = message.getHeaders();
            message.setHeader("CamelHttpResponseCode", "500");
            
        }
        
    }

    return message;

}

Regards,
Miguel Motta

philippeaddor
Active Participant
0 Kudos

I'm looking for the same. I have created a feature request on Customer Influence:

https://influence.sap.com/sap/ino/#/idea/311779

Please vote for it!

0 Kudos

Hello all,

I have the same issue. Any hints?

Regards,

Thorsten

former_member601407
Participant
0 Kudos

Nope. If you get any solution, pls share