Monday, May 11, 2015

How to test REST service from CURL


Here is the command to test the REST from curl


curl -i -H "Content-Type: application/json" -X POST -d '{"firstName": "Harish"} ' http://ussumsdsoaapp04:7001/hellorest/

If you need to pass the request payload from a file then use @filenamme 

curl -i -H "Content-Type: application/json" -X POST -d @hello.json http://ussumsdsoaapp04:7001/hellorest/

Content of  hello.json 

{"firstName": "Harish"}

Thursday, April 30, 2015

API Gateway -LDAPS with Active Directory




Error -
ested fault: simple bind failed: devad.mycompay.com:636: javax.naming.CommunicationException: simple bind failed: devad.mycompay.com:636 [Root exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target] at com.sun.jndi.ldap.LdapClient.authenticate(LdapClient.java:197) at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2694) at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:293) at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:175) at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:193) at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:136) at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:66) at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288) at javax.naming.InitialContext.init(InitialContext.java:223) at javax.naming.InitialContext.<init>(InitialContext.java:197) at javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:82) at com.vordel.common.ldap.LdapLookup$CachedContext.<init>(LdapLookup.java:239) at com.vordel.common.ldap.LdapLookup$ContextCache.factory(LdapLookup.java:255) at com.vordel.common.ldap.LdapLookup$ContextCache.factory(LdapLookup.java:247) at com.vordel.system.PoolCache.hold(PoolCache.java:37) at com.vordel.common.ldap.LdapLookup$InContext.runCached(LdapLookup.java:176) at com.vordel.common.ldap.LdapLookup$InContext.run(LdapLookup.java:158) at com.vordel.common.ldap.LdapLookup.search(LdapLookup.java:540) at com.vordel.common.ldap.LdapLookup.search(LdapLookup.java:505) at com.vordel.circuit.attribute.AttribLdapLookup.getAttributes(AttribLdapLookup.java:155) at com.vordel.circuit.attribute.AttributeExtractLdapProcessor.getAttributes(AttributeExtractLdapProcessor.java:122) at com.vordel.circuit.attribute.AttributeExtractBaseProcessor.invoke(AttributeExtractBaseProcessor.java:149) at com.vordel.circuit.InvocationEngine.invokeFilter(InvocationEngine.java:160) at com.vordel.circuit.InvocationEngine.invokeCircuit(InvocationEngine.java:52) at com.vordel.circuit.InvocationEngine.processMessage(InvocationEngine.java:241) at com.vordel.circuit.SyntheticCircuitChainProcessor.invoke(SyntheticCircuitChainProcessor.java:36) at com.vordel.dwe.http.HTTPPlugin.invokeDispose(HTTPPlugin.java:300) at com.vordel.dwe.http.HTTPPlugin.invoke(HTTPPlugin.java:166) Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1649) at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:241) at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:235) at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1206) at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:136) at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:593) at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:529) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:893) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1138) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:753) at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75) at java.io.BufferedInputStream.fill(BufferedInputStream.java:218) at java.io.BufferedInputStream.read1(BufferedInputStream.java:258) at java.io.BufferedInputStream.read(BufferedInputStream.java:317) at com.sun.jndi.ldap.Connection.run(Connection.java:808) at java.lang.Thread.run(Thread.java:662) Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:323) at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:217) at sun.security.validator.Validator.validate(Validator.java:218) at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:126) at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:209) at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249) at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1185) ... 12 more Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:174) at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:238) at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:318) ... 18 more

Solution
1. Add the Root certificate of the Active Directory in java keystore cacerts . Keystore cacerts is located in following directory.
/opt/oracle/OAG-11.1.2.1.0/apigateway/Linux.x86_64/jre/lib/security/

Command to import -
keytool -import -trustcacerts -alias ADRoot -file CelgeneCertificates/RootIntCA.cer -keystore cacerts


2. 
Restarts the gateway servers

Start Admin Node Manager:
/opt/oracle/OAG-11.1.2.1.0/apigateway/posix/bin/nodemanager -d

Stop:

/opt/oracle/OAG-11.1.2.1.0/apigateway/posix/bin/nodemanager -k


Stop API Gateway Server

/opt/oracle/OAG-11.1.2.1.0/apigateway/posix/bin/startinstance -g "DevGroup1" -n "DevGateway1" -k

/opt/oracle/OAG-11.1.2.1.0/apigateway/posix/bin/startinstance -g "DevGroup1" -n "DevGateway1" -d

Wednesday, April 29, 2015

How To Extract File having tar.gz file


For example you need to set-up the Apache LDAP explorer and you downloade the file "ApacheDirectoryStudio-linux-x86_64-2.0.0.v20130628.tar.gz"


So first step:
gzip -d ApacheDirectoryStudio-linux-x86_64-2.0.0.v20130628.tar.gz
This will create the  "ApacheDirectoryStudio-linux-x86_64-2.0.0.v20130628.tar" file

Second step: tar command

tar -xvf ApacheDirectoryStudio-linux-x86_64-2.0.0.v20130628.tar

Sunday, February 22, 2015

JDev 12c installation



1) Download the "Oracle SOA Suite" from OTN Release 12c (12.1.3.0.0) . Downloade zip file name is "jsonedit-repository-0.9.7.zip" 

http://www.oracle.com/technetwork/middleware/soasuite/downloads/index.html

2) Extract the file and it will have two jar files .

drwxr-xr-x 2 harish hgroup       4096 Feb 22 09:32 jsonedit-repository-0.9.7

[celapp@myhost Jdev]$ cd jsonedit-repository-0.9.7/

[myhost@myhost jsonedit-repository-0.9.7]$ ls
fmw_12.1.3.0.0_soa_quickstart2.jar  fmw_12.1.3.0.0_soa_quickstart.jar

[myhost@myhost jsonedit-repository-0.9.7]$ java -jar -Xms4g fmw_12.1.3.0.0_soa_quickstart.jar 

Launcher log file is /tmp/OraInstall2015-02-22_09-50-41AM/launcher2015-02-22_09-50-41AM.log.
Insufficient free space in /tmp/orcl6637823415702905917.tmp to extract the installer.  Actual 2691 MB.  Required 3053 MB.

[myhost@myhost jsonedit-repository-0.9.7]$ java -jar -Djava.io.tmpdir=/opt/tmp/tmp -Xms4g fmw_12.1.3.0.0_soa_quickstart.jar 
Launcher log file is /opt/tmp/tmp/OraInstall2015-02-22_09-53-47AM/launcher2015-02-22_09-53-47AM.log.
Extracting files................................
Starting Oracle Universal Installer

Checking if CPU speed is above 300 MHz.   Actual 2128.002 MHz    Passed
Checking monitor: must be configured to display at least 256 colors.   Actual 16777216    Passed
Checking swap space: must be greater than 512 MB.   Actual 8388600 MB    Passed
Checking if this platform requires a 64-bit JVM.   Actual 64    Passed (64-bit not required)
Checking temp space: must be greater than 300 MB.   Actual 18121 MB    Passed


Preparing to launch the Oracle Universal Installer from /opt/tmp/tmp/OraInstall2015-02-22_09-53-47AM
Log: /opt/tmp/tmp/OraInstall2015-02-22_09-53-47AM/install2015-02-22_09-53-47AM.log
You can find the log of this install session at:
 /opt/tmp/tmp/OraInstall2015-02-22_09-53-47AM/install2015-02-22_09-53-47AM.log

 Oracle JDeveloper 12c 12.1.3.0.0
 Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.

Logs successfully copied to /home/myhost/oraInventory/logs.
[myhost@myhost jsonedit-repository-0.9.7]$ 


Saturday, February 14, 2015

API Gateway Certificate Import -Can Not decode x509 object



Importing the certificate in Oracle API gateway


We received the self signed certificate from our partner and while importing in API gateway we received the Error 
"Can Not decode x509 object"





The simple way to resolve this issue  is to use Windows "Certificate Export Wizard" and choose copy to file option .
 In Export File format export screen choose "DER Encoded binary X.509 (.CER).



 Use this exported .cer file to successfully import the certificate.


- 

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; 
} 
}