Decision Management & Intelligence (ODM, DI)

 View Only

 Custom Exception Handler - dump input data

T. Ibis's profile image
T. Ibis posted Fri April 10, 2026 08:56 AM

Hello,

I have implemented a Custom Exception Handler which dumps all input data (input parameters) to a file, whenever an exception occurs. It works fine for ruleapps which use a XML based XOM (XSD-XOM). Below are some working code fragments provided for better understanding:

Class ExcepHandler.java:

	@Override
	public void handleActionException(Exception arg0, RuleInstance ruleInstance) throws Exception {
		logger.log(Level.SEVERE, "Exception while executing action of rule: " + ruleInstance.getRuleName(), arg0);		
		dumpInData();
		throw arg0;
	}

Class Dump.java:

public static void dumpInData(Map<String, Object> inData, RunningEngine re){
     // No XmlBindingService available for Java-XOM rules...
     xmlBindingService.set(re.getService(XmlBindingService.class));
     xmlDriver.set(xmlBindingService.get().getDataDriver());

     for (String inParamName : inData.keySet()) {
           Object inParamObject = inData.get(inParamName);
           if (inParamObject instanceof IlrXmlObject) {
                 StringWriter sw = new StringWriter();
                 xmlDriver.get().writeObject(xmlObject, sw);
           }
      }
}

The above code lets you write all input data into an XML file.

Problem: There is no XML driver available for ruleapps which use a Java model (Java-XOM). The object inData is not of type IlrXmlObject. It is a custom Java type class (e.g. MyInputData). Regardless of how you call the rule app (XML payload, JSON payload), the object type is not IlrXMLObject.

How do I retrieve the input data/input parameters robustly for Java-XOM ruleapps? Is it possible to retrieve the input data as a JSON payload and dump it into a file, similar to the code above?

Alain Robert's profile image
Alain Robert

You are already retrieving the parameters  and filtering on IlrXmlObject.  If it is not an XML Object you can use a json serialization library to generate similar output.

see for example https://www.baeldung.com/java-serialization-approaches 

I hope this helps.

T. Ibis's profile image
T. Ibis

Thank you Alain. I guess I overthinked it😂

Here is the solution for those who are interested:.

import com.fasterxml.jackson.databind.ObjectMapper;

ObjectMapper jsonMapper = new ObjectMapper();
String json = jsonMapper.writeValueAsString(inParamObject);