WSO2 data service and data mapper - namespaces

I am trying to apply the data mapper mediator to the output of the XML data service defined within WSO2EI. Documentation indicates, that to use the data mapper you need to have a fully qualified names in the XML input files.
The data service I am creating does not include qualified prefixes within the XML it generates.
I tried to export the XSLT data mapping from the CAR file and run it along the sample XML generated by the data service through the external XML transformer - it did not work. However, if I added qualified prefixes in the input XML manually, everything works fine.
It seems that the reason for my data mapper not working is the default, and not qualified, namespace in the input XML. Unfortunately, I cannot get the data service including namespace prexifes in its output. Any ideas?
To illustrate the nature of the problem let us consider two slightly different inputs; first XML input file uses the default names, second one qualified names:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<users xmlns="http://ws.wso2.org/dataservice">
<user>
<last>Waelchi</last>
<first>Xzavier</first>
<country>Swaziland</country>
</user>
</users>
</soapenv:Body>
</soapenv:Envelope>
This XML is not properly handled by the XSLT, no matter if within WSO2EI, or external XML processor. However, the same XML with qualified names:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<users xmlns:p="http://ws.wso2.org/dataservice">
<p:user>
<p:last>Waelchi</p:last>
<p:first>Xzavier</p:first>
<p:country>Swaziland</p:country>
</p:user>
</users>
</soapenv:Body>
</soapenv:Envelope>
is properly interpreted at least by the external XML processor. My problem is, that I cannot get WSO2EI data service to include qualified prefixes in its output.
OK, I have managed to bypass the problem transforming XML output by WSO2 data service into qualified XML using XSLT transform. However, I am still unable to get qualified XML directly from the data service; any suggestion shall be appreciated.

Related

How to can JIBX codeGen be instructed to not generate duplicate classes for 2 schemas

I am using JIBX maven plugin to generate the Java classes from the XSD schema. Below are 2 different sample XML types one representing a customer and other representing an account. The address field is similar in both the schema. However codegen generates 2 separate Address classes (i.e. Address and Address1) because they belong to different namespaces. How can I make JIBX codegen generate a single class file and make them reuse across repeating structure. Provided the author of the schema does not provide a common type schema.
<customer xmlns="xyz.com/cust">
<cust_number>97767</cust_number>
<name>John Doe</name>
<address>
<street_name>1st Street</street_name>
<address_line1>Line 1</address_line1>
<address_line2>Line 2</address_line2>
<city>San Jose</city>
</address>
</customer>
<account xmlns="xyz.com/acc">
<acc_number>97767</acc_number>
<acc_type>CHK</acc_type>
<name>John Doe</name>
<address>
<street_name>1st Street</street_name>
<address_line1>Line 1</address_line1>
<address_line2>Line 2</address_line2>
<city>San Jose</city>
</address>
</account>
Technically, if a schema is in a different namespace, it is a different schema. JiBX doesn't have a way to fake a namespace using configuration. If you have an issue with a vendor's schema, run it through a transformation tool such as XSLT to correct the issue with the schema (ie., change the namespace), then you can generate the shared schema. JiBX can then use the shared schema as it does in the example here:
https://github.com/jibx/maven-plugin/tree/master/test-suite/web-schema-test.
You can find an explanation here:
https://jibx.sourceforge.io/maven-jibx-plugin/modular-codegen.html. I use this technique successfully in my automated public schema to code scripts.

Convert and Transform JSON HTTP request to XML

I need to create a Logic Apps workflow with three steps:
When HTTP Request is received (JSON)
Convert Json from request to XML
Save XML file to FTP
What I have done so far:
Add action "When HTTP Request is received"
Add Liquid to Convert JSON to XML
(but i don't see option JSON to XML...Only Tranform JSON to JSON, JSON to
TEXT, XML to JSON, XML to TEXT)
Add action "FTP - Create file"
I also created Integration Account and try to add map for mapping JSON to XML, but I can't find any examples/templates to do this...
Is it possible at all ? Maybe there is another way to convert between these two formats ?
When you just want to convert a JSON payload to an XML file, without doing any transformation to the data, you can use the built-in xml() function of the Workflow Definition Language.
Detailed info in the docs: Workflow Definition Language reference #xml
I've made a small test Logic App to demo your usecase. It looks like this:
As you can see I use the xml function on the triggerbody #xml(triggerBody()) as an input for my FTP file content.
Remark: This will only work if your JSON message has a single rootnode. Otherwise the xml conversion will fail. You'll get this error:
The provided value cannot be converted to XML: 'JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifying a DeserializeRootElementName.
You can work around that by concatenating a rootnode to your JSON payload. The function then would look like: #xml(json(concat('{\"rootnode\":',triggerBody(),'}')))
Good luck testing this out. Let me know if you need more help with this.

Convert JSON to XML Request using WSDL

I Have a SOAP web services which takes XML as input and send XML as response. Now I have a JSON object which is the same as XML request. How can I convert JSON Object to XML so that I can send the XML request to my SOAP web service. I have the WSDL file. In other terms, I wanted to provide a extra layer of REST on top of SOAP
A JSON object can never be "the same as" an XML document, because the data models are different. It may hold the same information, but the problem is that there is no definitive mapping from JSON to XML that is guaranteed to produce the XML representation that you are after.
There are a number of libraries available that do JSON to XML conversion: give them a try, but you will probably have to "tweak" the XML to get it into the required form. That can always be done using XSLT, of course.
If you use XSLT 3.0 then you can do the JSON to XML conversion and subsequent processing ("tweaking") in a single step.

How to omit fields when using camel-xmljson JAR to convert XML string to JSON string

XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
xmlJsonFormat.setEncoding("UTF-8");
xmlJsonFormat.setForceTopLevelObject(true);
xmlJsonFormat.setTrimSpaces(true);
xmlJsonFormat.setSkipNamespaces(true);
xmlJsonFormat.setRemoveNamespacePrefixes(true);
Pool a XML file from source directory and transform it to JSON format before sending it to destination directory
from("file:/inn?noop=true").marshal(xmlJsonFormat)
.setHeader(Exchange.FILE_NAME, simple("${file:onlyname.noext}.json"))
.to("file:/out").end();
It works great when i want a JSON string right from a XML without using a POJO.
But now consider a XML where I would like to omit an element.
Should I use another lib but camel-xmljson?
Is this way the right way of accomplish it:
JAXB lib to get a POJO from XML
Jackson lib to get a JSON from POJO and with excluding POJO fields from marshalling
I understand, even I would try to avoid any POJO's in camel routes.
Having said that, I wont just straight way let the XML out. I would put a XSLT after the xmljson component, so that I can trim the xml for desired output.
Thanks gnanagurus! This is quite simple using XSLT. Moreover the xslt: component is included in the last version of the core of Camel.
I defined an xlst file 'transform.xsl' taht includes the field that is to be omited. And then defined the Camel route like that:
from("file:/inn?noop=true")
.to("xslt:file:src/transform.xsl")
.marshal(xmlJsonFormat)
.setHeader(Exchange.FILE_NAME, simple("${file:onlyname.noext}.json"))
.to("file:/out").end();

Unable to Parse this RDF/XML since System.Xml was unable to parse the document

I'am using .Net RDF library to make some sparql query on RDF files.
but when I tried to load the RDF file to C# .Net RDFlibrary.
The error is:
Unable to Parse this RDF/XML since System.Xml was unable to parse
the document, see Inner Exception for details
My RDF file:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE rdf:RDF [<!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#'>
<!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#'>]>
<rdf:RDF xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dnr="http://www.dotnetrdf.org/configuration#"
xmlns:rdf="http://www.w3.org/XML/1998/namespace#"
xml:base="http://www.example.org/">
<rdf:Description rdf:about="Fadi">
<ns0:eat xmlns:ns0="http://example.org/">Apple</ns0:eat>
<xml:startTime>00:01:38</xml:startTime>
<xml:endTime>00:01:39</xml:endTime>
</rdf:Description>
</rdf:RDF>
and the statement to load:
Graph myGraph = new Graph();
FileLoader.Load(myGraph, "C:\\Users\\hasoOn\\Desktop\\tt.rdf");
Can anyone tell me what is wrong? - and why I get this error?
Did you actually look at the Inner Exception as the exception messages tells you to? That would contain the XmlException that was produced and would tell you exactly what is wrong with your RDF/XML including positional information i.e. where in the file the error is.
In your case your problem happens to be that you have defined the rdf namespace twice on the same element i.e. you have two xmlns:rdf attributes on your root rdf:RDF element which makes your XML illegal.
If you remove that then it will be valid XML however it will still fail to parse in dotNetRDF because you have used the properties xml:startTime and xml:endTime without defining the xml namespace. I guess dotNetRDF should probably allow those because xml: is implicitly defined in XML though using the xml namespace for anything other than XML syntax itself is generally a very bad idea and a symptom of bad data modeling.