Message Image  

IBM Integration Bus JavaScript Client API does not contain subelement namespaces

 View Only
Wed July 01, 2020 08:57 AM

Alex Goldberg
Published on January 23, 2018 / Updated on November 27, 2018

The IBM Integration Bus JavaScript Client API creates Java classes, which are used by IIB runtime to convert JSON to XML, see https://www.ibm.com/support/knowledgecenter/en/SSMKHH_10.0.0/com.ibm.etools.mft.doc/ss26030_.htm for more information.

In the generated Java classes, the namespace is set only on the element and not subelements, which causes in some cases incorrect XML and subsequent incorrect message processing.

When JavaScript client API is generated in the Toolkit, Java utility classes are generated as well.

In the example below, the SampleServiceUtility.java class is generated for the SampleService.

Fig 1. Toolkit shows the generated Java class, SampleServiceUtility.java

In the template/generated code –

MbElement firstChild = xmlnscElement.getFirstChild();
if (null != firstChild) {
firstChild.setNamespace(TARGET_NAMESPACE);
}

It depends on the XML schema whether this code is correct. If the schema specifies elementFormDefault=”qualified”, then all elements and subelements are in the targetNamespace of the schema.

If the schema specifies elementFormDefault=”unqualified” or does not specify elementFormDefault, then only the top level element is in the targetNamespace of the schema.

In case elementFormDefault=”qualified” in the schema, change the Java class as following:

FROM:

MbElement firstChild = xmlnscElement.getFirstChild();

if (null != firstChild) {

firstChild.setNamespace(TARGET_NAMESPACE);


}

TO:

MbElement firstChild = xmlnscElement.getFirstChild();
while (firstChild != null) {
firstChild.setNamespace(TARGET_NAMESPACE);
MbElement child = firstChild.getNextSibling();
while (child != null) {
child.setNamespace(TARGET_NAMESPACE);
child = child.getNextSibling();
}

firstChild = firstChild.getFirstChild();


Fig 2. Changed code in the Toolkit

Save the changed Java class. The messages will be processed correctly now.




#API
#IntegrationBus(IIB)
#Javaclass
#JavaScript