Call XML to Domain Mapping in a Java Action

Is it possible inside a Java action to leverage an XML to Domain Mapping? I have an instance where Mendix's web service can't handle a MTOM request. Therefore I'm making the call manually in a Java Action. However the response has multiple levels and would like to map the data to Domain model objects. There is already a mapping defined, so if I could pass the response XML to the Mapping framework, it would safe a lot of code and make it easier to modify in the future.
2 answers

There is a Java API call that you can use to directly call the mapping:

Core.importXmlStream(context, xmlStream, importMappingName, mappingParameter, shouldValidate);
//Example call:
Core.importXmlStream(this.getContext(), myXmlInputStream, "MyFirstModule.MyMappingName", this.MyInputParam.getMendixObject(), true);

The function call above does the exact same action as the import XML activity type in microflow.
However I would still consider Erwin's suggestion of storing the response in the XML. I personally try to limit the actions I do in Java, because having everything in microflow increases the visibility and flexibility of the process. (For example with the Java above if you rename the mapping or change an input parameter you will only notice this at runtime, while the XML activity in microflow will provide consistency messages development time)



I don't directly know if this is possible from the custom java action. What you could do is take the response xml data and write this to a file and return this as a file document from the java action and perform the mapping in the microflow calling the java action with the standard functionality. In this way you'll use the java action to perform the action that Mendix standard functionality can directly handle and make optimal use of the standard Mendix functionality for further actions, making your app more maintainable as more standard Mx features are used opposed to more java code.