Friday, May 30, 2014

API Gateway How to condition a result based on some JSON data


problem:

We need to develop the policy routing flow based on the incoming message What is the way to do the content based routing and condition based routing in OAG. 

For example I have two (may be more) types of JSON message response from a service . I want to set the message based on the JSON response from service . What is the way to develop in this in OAG. . 

Here is the two JOSN response from service that OAG is calling . 

JSOA Type-1 
========================================== 
{"soapenv:Envelope":{"@xmlns:soapenv":"http://schemas.xmlsoap.org/soap/envelope/","env:Header":{"@xmlns:env":"http://schemas.xmlsoap.org/soap/envelope/","wsse:Security":{"@xmlns:wsse":"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"}},"env:Body":{"@xmlns:env":"http://schemas.xmlsoap.org/soap/envelope/","mes:createUserAccountResponse":{"@xmlns:mes":"http://celgene.com/security/messages_v2","mes:createUserAccountOutput":{"mes:status":"SUCCESS"}}}}} 

JSON Type-2 
========================================== 
{"soapenv:Envelope": {"@xmlns:soapenv": "http://schemas.xmlsoap.org/soap/envelope/", "env:Header": {"@xmlns:env": "http://schemas.xmlsoap.org/soap/envelope/"}, "env:Body": {"@xmlns:env": "http://schemas.xmlsoap.org/soap/envelope/", "env:Fault": {"@xmlns:xs": "http://www.w3.org/2001/XMLSchema", "@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance", "faultcode": "soapenv:Server", "faultstring": null, "detail": {"java:UserAlreadyExistsException": {"@xmlns:java": "http://celgene.com/security/exceptions_v2", "java:message": "UserAlreadyExists" }}}}} 


For JSON Msg 1 I want to set the message 
========================================== 
{"Message": "User Created successfully"} 

For JSON Msg 2 I want to set the message 
========================================== 
{"Message": "UserAlreadyExists"} 
SOLUTION:


We can implement this using the Scripting Language filter as follows: 

function invoke(msg) { 

// get the body as JsonNode 
var node = com.vordel.mime.JSONBody.getJSON(msg); 

// get the root 
var root = node.path("soapenv:Envelope"); 

// get the value of reference from body 
var envBody = root.path("env:Body"); 

// get the value of reference from Fault 
var envFault = envBody.path("env:Fault"); 

if (envFault .size() != 0) 
// Follow the line for the message with error 
// get the value of reference from detail 
var detail = envFault.path("detail"); 

// get the value of reference from UserAlreadyExistsException 
var javaUser = detail.path("java:UserAlreadyExistsException"); 

// get the value of reference from message 
var javaMessage = javaUser.path("java:message"); 

// get the text value 
var message = javaMessage.getTextValue(); 

// put the data in the result 
msg.put("message", "UserAlreadyExists"); 
return true; 

// get the value of reference from createUserAccountResponse 
var mesCreateUserAccountResponse = envBody.path("mes:createUserAccountResponse"); 
if (mesCreateUserAccountResponse .size() !=0) 
// Follow the line for the Success 


// get the value of reference from mesCreateUserAccountResponse 
var mesCreateUserAccountOutput = mesCreateUserAccountResponse.path("mes:createUserAccountOutput"); 

// get the value of reference from mesCreateUserAccountOutput 
var mesStatus = mesCreateUserAccountOutput.path("mes:status"); 

// get the text value 
var message = mesStatus.getTextValue(); 

// put the data in the result 
msg.put("message", "User Created successfully"); 

return true; 




Friday, May 16, 2014

How to convert file format from ASCII to UTF


How to convert file format from ASCII to UTF

#1 : Check the file format
$file input.txt

#2
use the iconv command
iconv -f   <<Source Format >>    -t      <<Target Format>>   < input.txt   > output.txt

iconv -f ASCII  -t UTF8   < input.txt   > output.txt

#3 #1 : Check the file format
$file output.txt

Tuesday, May 13, 2014

Error -ora-28267: invalid namespace -ADF With Jdeveloper


There was a requirement to validated the Local Entity Attribute value against the Remote Database. For this we set-up the DB link. Local DB is 11g and remote is 10g.
During the query validation in JDEV we go the issue."ora-28267: invalid namespace" .

To Fix this in JDV.

Replaced the jar file  (ojdbc6dms.jar) with ojdbc6.jar in below loaction in Jdeveloper..

"C:\Oracle\Middleware11.1.1.7.0\oracle_common\modules\oracle.jdbc_11.1.1\"

You can find ojdbc6.jar in  C:\Oracle\Middleware11.1.1.7.0\wlserver_10.3\server\lib

C:\Oracle\Middleware11.1.1.7.0\=Middleware Home