XML to JSON converter in Siebel

Often we come across requirement for Siebel to integrate with external applications. Siebel provides various ways to integrate through EAI (Enterprise Application Integration) like EIM, Prebuilt connectors, various queues like MSMQ, JMS, WebSphere MQ. Also Web service based integration using SOAP. Siebel also supports RESTful based integration using Fusion Middleware.

One important feature of Siebel EAI is EAI Java Business Service which can be used to invoke external Java class to perform various operations.
In this article we will see how we can use various EAI Business services to communicate with JSON API of external application. We will have an XML input processed and resulted into a JSON output in Siebel.

As we know JSON has become new standard for API in most social media sites like Facebook, twitter, LinkedIn etc. Apart from social media sites most of mobile applications are using JSON for integrations. But unfortunately we don’t have any out of box service to create JSON objects in Siebel to communicate with external application.
Hence we’re designing a XML to JSON converter which can be called from within Siebel. Which can be used for any sort of integration.
What we need?

  1. A Java program to convert XML to JSON.
  2. Invoking this program from within Siebel and pass on required XML as input.
  3. Receive JSON as output.

 

Steps to achieve XML to JSON from within Siebel:

    1. Write a simple java code as follows:
import org.json.JSONObject;
import org.json.XML;
import com.siebel.data.SiebelPropertySet;
import com.siebel.eai.SiebelBusinessServiceException;

public class XML2JSON extends com.siebel.eai.SiebelBusinessService {

public void doInvokeMethod(String methodName, SiebelPropertySet input,SiebelPropertySet output) throws SiebelBusinessServiceException{

	try{
	if(methodName.equals("XMLtoJSON")){
		String XMLText2 = input.getProperty("XMLString");
		JSONObject jsonObj = XML.toJSONObject(XMLText2); 
		output.setProperty("JSONString", jsonObj.toString());
	   }	
     }
     catch(Exception e)
     {
         e.printStackTrace();
     }
   }
}

  • Compile to a class named “XML2JSON.class” (which happened by default anyways based on class name we mentioned in code above) and save in “CLASSES” folder on web client or Server.
  • Now we need to create a proxy Business Service to call this java class.
  • In tools create new Business Service “XML2JSON Conv” with class “CSSJavaBusinessService”. This is a specialized class for EAI Java Business Services.
  • We define the java class to be referred in BS user properties using “@class” property.
  • Create user property as follows:

 

Name = “@class”
Value = XML2JSON
    1. Now add a method to BS as “XMLtoJSON”. This method will have two arguments

a. Input

Name: XMLString
Datatype : String
Type: Input

b. Output

Name: JSONString
Datatype: String
Type: Output
    1. We are almost done here but for one step.

We have to define JAVA subsystem which will execute this code. Instead of writing whole stuff here I would recommend you to refer this bookshelf page for thorough explanation for different environments.

Case Study:

We have a requirement where Siebel needs to integrate with a Location Based system to obtain current location of user and respond accordingly. External application was accepting request only using JSON API, which we have to use to create and query data.
We used above proxy business service (BS) and couple it with Integration Object based XML (EAI Siebel Adapter) using a simple workflow and voila!! We have JSON returned to us based on XML we input.

Now all we have to do is define IO structure in such a way that when its converted to JSON, it represents the required input JSON.

So this ends the XML to JSON conversion in Siebel to get things done; though story doesn’t end here!
Once we have JSON, we could always use “EAI HTTP Transport” to send across this message and get response; but again the response will be in JSON again. To pass it to Siebel or using with XML we need the reverse converter.

In next post we shall look in to the reversal of JSON2XML for Siebel.

Hope this helps!

3 comments
  1. got this error:

    Exception:java.lang.UnsupportedClassVersionError: XML2JSON : Unsupported major.minor version 52.0.(SBL-EAI-05010)

    can you help me?

  2. Dear Kedar,
    Can you please post the JSON2XML code snipet as I have exact reverse requirement?

    Regards,
    Srinivas M.

Leave a Reply to Oscar Gonzalez Cancel reply

Your email address will not be published. Required fields are marked *