Custom Web Service for Json/XML conversions deployed in Tomcat callable from Siebel
16. 10. 2020
Since IP 2016, Siebel natively supports REST calls with json content type. As Siebel internally works with Siebel Messages and XML Hierarchies and a lot of interfaces to and from Siebel CRM still use XML message format, it is very useful to have conversion methods from XML to JSON and vice versa. Having such converter eases migration of XML json content type to json content type interfaces, typically SOAP webservice to REST.
After small research, the most suitable way is to use existing Java XML/JSON conversion classes to perform this task. Another option considered was to write conversion directly in eScript. As many XML and JSON parsers existing in JavaScript are implemented in Javascript engines, this option would require to write parses from the scratch. So having this in mind we have decided for JSON/XML converter implemented in Java.
One possibility how to use JAVA functionality from Siebel is to define Business Service with Class CSSJavaBusinessService in Siebel Tools and develop and deploy custom Java package implementing JSON/XML conversions.
Another possibility is to create deployable war package for Tomcat server that is running on each Siebel Server. This blog deals with this solution.
We have used IntelliJ Idea IDE to create a Webservice application according https://www.jetbrains.com/help/idea/creating-and-running-your-first-restful-web-service.html#new_project
Project is using javax.ws.rs libraries, that ease webservice implementations. Our class implements two methods. Using of directives @Path, @POST, @Produces @Consumes redirects the webservice call to the right methods: xmltoJson or jsontoxml respectively.
Method xmltoJson will be accessible using filter /converter/xmltojson and method jsontoxml using filter /converter/jsontoxml, we will see it later in the example.
For the conversion we use org.json library - https://mvnrepository.com/artifact/org.json/json.
The war package build with IntelliJ has to be deployed in Tomcat, it means copied into applicationcontainer/webapps directory. The name of the package is XMLJsonConverter
The implementation on Siebel side is very simple, here are the examples of XMLtoJSON, JSONtoXML methods.
function XMLtoJSON(Inputs:PropertySet, Outputs:PropertySet)
{
var oEAIHTTPBS = TheApplication().GetService("EAI HTTP Transport");
Inputs.SetProperty("CharSetConversion","UTF-8");
Inputs.SetProperty("HTTPRequestMethod", "POST");
Inputs.SetProperty("HDR.Content-Type", "application/xml");
Inputs.SetProperty("HTTPAccept", "application/json");
Inputs.SetProperty("HTTPRequestURLTemplate", "http://localhost:9012/XMLJsonConverter/convert/xmltojson" );
oEAIHTTPBS.InvokeMethod("SendReceive", Inputs , Outputs);
}
function JSONtoXML (Inputs:PropertySet, Outputs:PropertySet)
{
var oEAIHTTPBS = TheApplication().GetService("EAI HTTP Transport");
Inputs.SetProperty("CharSetConversion","UTF-8");
Inputs.SetProperty("HTTPRequestMethod", "POST");
Inputs.SetProperty("HDR.Content-Type", "application/json");
Inputs.SetProperty("HTTPAccept", "application/xml");
Inputs.SetProperty("HTTPRequestURLTemplate", "http://localhost:9012/XMLJsonConverter/convert/jsontoxml" );
oEAIHTTPBS.InvokeMethod("SendReceive", Inputs , Outputs);
}
Both methods are using EAI HTTP Transport business service and method SendReceive with appropriate parameters. Method XMLtoJSON uses Content-Type application/xml and HTTPAccept application/json as it send xml in body and expects json in response. The method JSONtoXML uses it in opposite way.
The following pictures show examples of calling the methods with business service simulator.
Späť na Blog