Friday, July 25, 2014

Handling Parallel events through OnEvent event handlers – Oracle SOA Suite

This post will explain, how to handle Parallel events through OnEvent event handlers in Oracle SOA Suite 11g

Download Handling_Parallel_events_ OnEvent_event_handlers_V1.pdf

Thursday, July 24, 2014

Cipher not initialized exception while invoking the Salesforce service through OSB

We are getting the "Cipher not initialized" exception wile invoking the Salesforce services through OSB.

We are able to invoke the URL successfully and able to receive the session id, also this exception was thrown only for a particular sandbox but the all other sandbox invocation is successful.

The "Cipher not initialized" exception will be thrown when there is no common Ciphers available between the client and server while negotiating the SSL communication.

We have raised a case with Salesforce regarding this and receive the response as "We recently upgraded our Cipher suites for SSL. To resolve the issue upgrade latest version of Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files- 6 for JDK1.6 on middleware."

After upgrading the Unlimited Strength Jurisdiction Policy Files in all the servers nodes we are able to invoke the service successfully.

Follow the below steps to resolve the issue

  • Download the Unlimited Strength Jurisdiction Policy Files from Additional Resources" section), for java 1.6 use
  • Unzip the downloaded zip 
  • Copy local_policy.jar and US_export_policy.jar to the $JAVA_HOME/jre/lib/security in all the OSB nodes.
  • Restarts the servers.
Now you will be able to invoke the service successfully.

Thursday, July 10, 2014

Integrating Adobe CQ5 with REST services

The below document explains the approach to integrate Adobe CQ5 with REST services.

Download Integrating_CQ5_with_RESTServices.pdf

Saturday, July 5, 2014 Server returned HTTP response code: 400 - While invoking the Salesforce login url from java to get the access token

I was getting the below exception while invoking the Salesforce login url to get the OAuth access_token from java. Server returned HTTP response code: 400 for URL:
at RestCaller.execute(
at RestCaller.main(

This exception will happen normally when the values of client_id, client_security, username and password are not specified correctly while invoking the login url - to get the OAuth access token.


In my case, I have specified all the values properly but still it was not working, it worked after resetting the password and getting the new security token - password(password+security token)

Calling Salesforce REST based webservice from Java

This post will explain the approach to call the Salesfore REST based webservice through java.
I have exposed a Apex class as REST service from salesforce to fetch the account details.

global with sharing class AccountDetails {

    global static Account doGet() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        System.debug('Account Id:'+accountId);
        Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE Id = :accountId];
        return result;

The communication is of two steps

  •  getting the access_token 
  •  invoking the service endpoint by attaching the access_token to the request.

To obtain an access token, we will send an HTTP POST request to the authentication endpoint exposed by Salesforce -  with the details client_id, client_secret, username and password.This values can be get from the configured Connected Apps from salesforce.

Friday, July 4, 2014

Ignoring the Host Name verification while invoking the HTTPS service through HttpsURLConnection

Sometimes you may receive the Host Name mismatch exception while invoking the HTTPS service from the Java client even though the valid certificate is installed to the key store. No name matching <Host Name> found

The root cause of the exception is the CN name of the certificate is not matching with the host name used to connect the service.

In real scenario while the certificate is signed with third party certificate authority , the CN name will be specified as the host name of the server where the service is hosted or wildcard name will be specified e.g * to represent all sub domains in a domain. So there will not be any issue while connecting to the service.

This mismatch exception will happen most of the time communicating with self signed certificate, the certificate is signed with CN name that is not matching with the host name.

To resolve the issue, the certificate should be signed with proper CN name or we can create a custom host name verifier to customize the host name verification functionality.

We have to return true from the custom host name verifier for the host name for which the CN name is mismatching.This will connect to the service irrespective of the host name used .


public class HTTPCaller {
static {
       public boolean verify(String hostname,
      sslSession) {
           if (hostname.equals("localhost")) {
               return true;
           return false;

    public static String execute() {
        String targetURL="https://localhost/test"
        URL url;
        HttpURLConnection connection = null;
        try {
            url = new URL(targetURL);
            url = new URL(url.toString());              

            connection = (HttpURLConnection)url.openConnection();
            connection.setRequestProperty("accept", "application/xml"); //for GET service to return xml payload

            InputStream is = connection.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(is));
            System.out.println("\n Received response" + System.currentTimeMillis());

            String line;
            StringBuffer response = new StringBuffer();
            while ((line = rd.readLine()) != null) {
            return response.toString();
        } catch (Exception e) {
            return (e.getClass().getName()+":"+e.getMessage().toString());
        finally {
            if (connection != null) {

Wednesday, July 2, 2014

Encrypting XML Payload through XSLT in Spring WS

The below document explain the approach to This document will explain the approach to encrypt the critical elements of XML payload while invoking the services in Spring WS or storing the data to a database table through XSLT.


Tuesday, July 1, 2014

Unit Testing the Velocity Templates in spring

It is painful to test the Velocity Template  by deploying to the server while doing frequent changes.
The unit testing  will help as to overcome this and do proper testing without deploying the project to the server.
This post will explain the approach to unit test the Velocity Templates through eclipse.

Create a Velocity-test.xml configuration file to configure the velocity bean - instead of creating separate configuration file we can also use the project configuration file that has the velocity bean configuration (e.g. application-context.xml)

Change the vm template path accordingly.

Create a test java class (
import java.util.ArrayList;
import org.apache.velocity.context.*;
import org.springframework.context.ApplicationContext;
import com.thomson.ecom.core.velocity.VelocityContextBuilder;
public class VelocityTest
public static void main(String[] args) throws Exception
ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:velocity-test.xml");
ArrayList<Employee> employeeList=new ArrayList<Employee>();

Employee emp1=new Employee();
emp1.setEmail("[email protected]");

Employee emp2=new Employee();
emp2.setEmail("[email protected]");

Employee emp3=new Employee();
emp3.setEmail("[email protected]");

VelocityEngine engine = ctx.getBean("velocityEngine", VelocityEngine.class);
Context velocityCtx = VelocityContextBuilder.getInstance().buildContext();
velocityCtx.put("empList", employeeList);

Writer w = new FileWriter(new File("D:\\Albin\\velocity.html"));
engine.mergeTemplate("EmployeeEmailTemplate.vm", velocityCtx, w);


Change the velocity.html file path and the vm template name accordingly.
Pass the required inputs to the velocityCtx map.
Execute the; this will generate the velocity.html file in the specified location.

Resolving cvc-elt.1: Cannot find the declaration of element 'beans' in Spring

I was receiving the following exception while running the Spring application in standalone mode with mavan and eclipse.

Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 11 in XML document from class path resource [encrypt/encrypting-test.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(

Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)

Unfortunately i could not able to find any issue in my bean configuration file.
<beans xmlns=""

<bean id="encryptXMLPayload" class="com.encrypt.EncryptXMLPayload">
<property name="encryptor" ref="encryptor" />
<property name="messageStylesheet" value="classpath:encrypt/encryptXMLPayload.xslt" />

<bean id="encryptor" class="com.encrypt.Encryptor" init-method="init">
<property name="keyData" value="pYOkcj4_kf-4hn-A-IkclLWDBJI-T5bd"/>

After analysis the issue is with version mismatch between the pom.xml(spring version configured) and the schema version  configured in the bean configuration file


<beans xmlns=""

The issue got resolved after changing the schema version to 3.0 in the bean configuration file as shown below

<beans xmlns=""

The spring version configured in the pom.xml and the schema version used in the bean configuration files should be matching.

Loading configuration properties from Database Table in Spring Application

This is better approach to store the configuration properties to a database table so that this can be managed easily.
This post will explains the approach to store and retrieve the configuration properties from database table in spring project.

Configure the below bean definition to the spring context file

<!--  Loads properties to set environment-specific values within the DB table for that environment -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="properties">
<bean class="org.apache.commons.configuration.ConfigurationConverter"
<bean class="org.apache.commons.configuration.DatabaseConfiguration">
  <ref bean="propertyDataSource"/>
     <constructor-arg value="Properties"/>  <!--  DB Table -->
     <constructor-arg value="prop_key"/> <!-- DB Key Column -->
   <constructor-arg value="prop_value"/> <!--  DB Value Column -->

The Properties table should be pre-created with the required configuration values


The datasource ref bean  propertyDataSource should be configured in the context file.

<jee:jndi-lookup id="propertyDataSource" jndi-name="java:comp/env/jdbc/propertyDS"/>

Here i am using the Tomcat server, the actual datasource - jdbc/propertyDS should be configured in context.xml file of the Tomcat server.

<Resource name="jdbc/ propertyDS "
password="property "

Now the properties can be referred as shown below

<bean id="ftp" class="com.doc.FTPService">
<property name="host" value="${}"/>
<property name="user" value="${ftp.user}"/>