{"id":2214,"date":"2015-06-07T09:42:49","date_gmt":"2015-06-07T09:42:49","guid":{"rendered":"http:\/\/kedar.nitty-witty.com\/?p=2214"},"modified":"2015-06-19T06:17:43","modified_gmt":"2015-06-19T06:17:43","slug":"xml-to-json-converter-in-siebel","status":"publish","type":"post","link":"https:\/\/kedar.nitty-witty.com\/blog\/xml-to-json-converter-in-siebel","title":{"rendered":"XML to JSON converter in Siebel"},"content":{"rendered":"<p>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.<\/p>\n<p>One important feature of Siebel EAI is EAI Java Business Service which can be used to invoke external Java class to perform various operations.<br \/>\nIn 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.<\/p>\n<p><!--more--><\/p>\n<p>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\u2019t have any out of box service to create JSON objects in Siebel to communicate with external application.<br \/>\nHence we&#8217;re designing a XML to JSON converter which can be called from within Siebel. Which can be used for any sort of integration.<br \/>\n<b>What we need?<\/b><\/p>\n<ol>\n<li>A Java program to convert XML to JSON.<\/li>\n<li>Invoking this program from within Siebel and pass on required XML as input.<\/li>\n<li>Receive JSON as output.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h2>Steps to achieve XML to JSON from within Siebel:<\/h2>\n<ol>\n<ol>\n<li>Write a simple java code as follows:<\/li>\n<\/ol>\n<\/ol>\n<blockquote style=\"background-color: beige;\">\n<pre style=\"white-space: pre-wrap;\">import org.json.JSONObject;\r\nimport org.json.XML;\r\nimport com.siebel.data.SiebelPropertySet;\r\nimport com.siebel.eai.SiebelBusinessServiceException;\r\n\r\npublic class XML2JSON extends com.siebel.eai.SiebelBusinessService {\r\n\r\npublic void doInvokeMethod(String methodName, SiebelPropertySet input,SiebelPropertySet output) throws SiebelBusinessServiceException{\r\n\r\n\ttry{\r\n\tif(methodName.equals(\"XMLtoJSON\")){\r\n\t\tString XMLText2 = input.getProperty(\"XMLString\");\r\n\t\tJSONObject jsonObj = XML.toJSONObject(XMLText2); \r\n\t\toutput.setProperty(\"JSONString\", jsonObj.toString());\r\n\t   }\t\r\n     }\r\n     catch(Exception e)\r\n     {\r\n         e.printStackTrace();\r\n     }\r\n   }\r\n}\r\n<\/pre>\n<\/blockquote>\n<p style=\"padding-left: 30px;\">\n<ul>\n<li>Compile to a class named &#8220;XML2JSON.class&#8221; (which happened by default anyways based on class name we mentioned in code above) and save in &#8220;CLASSES&#8221; folder on web client or Server.<\/li>\n<li>Now we need to create a proxy Business Service to call this java class.<\/li>\n<li>In tools create new Business Service \u201cXML2JSON Conv\u201d with class &#8220;CSSJavaBusinessService&#8221;. This is a specialized class for EAI Java Business Services.<\/li>\n<li>We define the java class to be referred in BS user properties using &#8220;@class&#8221; property.<\/li>\n<li>Create user property as follows:<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<blockquote style=\"background-color: beige; padding-left: 30px;\">\n<pre style=\"white-space: pre-wrap; padding-left: 30px;\">Name = \u201c@class\u201d\r\nValue = XML2JSON\r\n<\/pre>\n<\/blockquote>\n<ol>\n<ol>\n<li>Now add a method to BS as \u201cXMLtoJSON\u201d. This method will have two arguments<\/li>\n<\/ol>\n<\/ol>\n<p style=\"padding-left: 60px;\">a. Input<\/p>\n<blockquote style=\"background-color: beige; padding-left: 30px;\">\n<pre style=\"white-space: pre-wrap; padding-left: 30px;\">Name: XMLString\r\nDatatype : String\r\nType: Input\r\n<\/pre>\n<\/blockquote>\n<p style=\"padding-left: 60px;\">b. Output<\/p>\n<blockquote style=\"background-color: beige; padding-left: 30px;\">\n<pre style=\"white-space: pre-wrap; padding-left: 30px;\">Name: JSONString\r\nDatatype: String\r\nType: Output\r\n<\/pre>\n<\/blockquote>\n<ol>\n<ol>\n<li>We are almost done here but for one step.<\/li>\n<\/ol>\n<\/ol>\n<p style=\"padding-left: 30px;\">We have to define JAVA subsystem which will execute this code. Instead of writing whole stuff here I would recommend you to refer <a href=\"http:\/\/docs.oracle.com\/cd\/E14004_01\/books\/EAI3\/EAI3_EAIJBS3.html\" target=\"_blank\" rel=\"nofollow\">this bookshelf page<\/a> for thorough explanation for different environments.<\/p>\n<h3>Case Study:<\/h3>\n<p>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.<br \/>\nWe 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.<\/p>\n<p>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.<\/p>\n<p>So this ends the XML to JSON conversion in Siebel to get things done; though story doesn&#8217;t end here!<br \/>\nOnce we have JSON, we could always use \u201cEAI HTTP Transport\u201d 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.<\/p>\n<p>In next post we shall look in to the reversal of JSON2XML for Siebel.<\/p>\n<p>Hope this helps!<\/p>\n","protected":false},"excerpt":{"rendered":"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&hellip;\n","protected":false},"author":4201,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[137,6],"tags":[],"class_list":{"0":"post-2214","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-guest-posts","7":"category-technical"},"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/2214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/users\/4201"}],"replies":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/comments?post=2214"}],"version-history":[{"count":17,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/2214\/revisions"}],"predecessor-version":[{"id":2234,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/2214\/revisions\/2234"}],"wp:attachment":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/media?parent=2214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/categories?post=2214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/tags?post=2214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}