Here’s a comprehensive solution covering SOAP XML namespace mapping, WSDL import quirks, and custom Java action implementation:
1. Understanding the WSDL Import Issue:
Mendix Integration Hub generates namespace prefixes automatically based on import order. The WSDL structure affects this:
<!-- WSDL defines target namespace -->
<definitions targetNamespace="http://company.com/erp/v2"
xmlns:tns="http://company.com/erp/v2">
Mendix sees tns but generates ns1, ns2 etc. for consistency across all imported services.
2. Custom Java Action for Namespace Prefix Mapping:
Create SOAPNamespaceMapper.java in your Mendix project:
public class SOAPNamespaceMapper extends CustomJavaAction<String> {
public String executeAction() throws Exception {
String inputXML = this.InputXML;
Document doc = parseXMLString(inputXML);
remapNamespaces(doc);
return serializeDocument(doc);
}
}
3. WSDL Import Workaround:
For services with strict prefix requirements, use a two-step approach:
- Import WSDL to generate domain model and basic structure
- Override the actual SOAP call with custom Java action
- Keep domain model mapping but control XML generation
In your microflow:
// Instead of: Call SOAP Service directly
// Do: Build request object → Java action → Parse response
requestObject = createSOAPRequest();
rawXML = SOAPNamespaceMapper(requestObject);
responseXML = HTTPPost(url, rawXML);
responseObject = parseSOAPResponse(responseXML);
4. Complete Java Implementation:
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
private void remapNamespaces(Document doc) {
Element root = doc.getDocumentElement();
remapPrefixRecursive(root, "ns1", "erp");
}
private void remapPrefixRecursive(Node node, String oldPrefix, String newPrefix) {
if (node.getPrefix() != null && node.getPrefix().equals(oldPrefix)) {
doc.renameNode(node, node.getNamespaceURI(), newPrefix + ":" + node.getLocalName());
}
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
remapPrefixRecursive(children.item(i), oldPrefix, newPrefix);
}
}
5. Alternative: XSLT Transformation:
For complex namespace requirements, use XSLT:
<!-- namespace-transform.xslt -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*[namespace-uri()='http://company.com/erp/v2']">
<xsl:element name="erp:{local-name()}" namespace="http://company.com/erp/v2">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Apply in Java action using TransformerFactory.
6. Handling WSDL Import Quirks:
Common issues and solutions:
- Multiple namespace declarations: Mendix consolidates them - verify all required namespaces are present
- Nested complex types: May generate unexpected prefixes - test with sample data
- Optional elements: Mendix includes nil elements - some services reject these
For optional element issues, add filtering:
// Remove nil elements before sending
NodeList nilElements = doc.getElementsByTagNameNS(
"http://www.w3.org/2001/XMLSchema-instance", "nil");
for (int i = nilElements.getLength() - 1; i >= 0; i--) {
Node nil = nilElements.item(i);
nil.getParentNode().removeChild(nil);
}
7. Testing and Validation:
Create comprehensive test suite:
1. Generate XML with Mendix SOAP service
2. Apply namespace transformation
3. Validate against ERP's XSD schema
4. Test with ERP's validation endpoint (if available)
5. Compare with vendor-provided sample XML
8. Production Considerations:
- Cache the XSLT transformer for performance (static initialization)
- Log both original and transformed XML in development
- Add error handling for malformed vendor responses
- Document the specific namespace mappings required
- Version control your Java action with WSDL version
9. Long-term Solution:
Work with ERP vendor to:
- Understand why they require specific prefixes (likely legacy code)
- Request relaxed validation or provide correct WSDL with prefix hints
- Consider REST API alternative if available
This approach has successfully integrated with SAP, Oracle, and legacy mainframe SOAP services that have strict XML requirements. The key is intercepting and transforming XML at the right point in the integration flow.