After trying out with Result Caching feature in OSB, i tried to use the coherence in integration with BPEL to store and retrieve the frequently used data in cache. As OTN puts it, “Coherence provides replicated and distributed (partitioned) data management and caching services on top of a reliable, highly scalable peer-to-peer clustering protocol”. In this post, i want to explain the setup i tried with using SOA Suite 11.1.1.3. The weblogic 10.3.3 installer comes with coherence 3.5
Starting Servers
To use coherence in conjunction with BPEL, the servers have to be started in the following order:
- Coherence server (cache-server.cmd)
- Admin and SOA managed server.
Open cache-server.cmd file present in $FMW_HOME\coherence_3.5\bin and set the coherence_home variable as shown below. Replace $FMW_HOME with actual path as per your SOA suite installation.
set coherence_home = $FMW_HOME\coherence_3.5
Open command window and issue the following commands to start the cache server.
$<DOMAIN_HOME>\bin\setDomainEnv.cmd or set $JAVA_HOME
set %PATH% = %JAVA_HOME%\bin;%PATH%
cache-server.cmd
By default, multicasting is used for communication within coherence cluster. The multicast address and port will be visible in cache server start logs as shown below.

In setDomainEnv.cmd file, modify EXTRA_JAVA_PROPERTIES variable to use above multicast address and port.

In startWeblogic.cmd file, modify CLASSPATH variable to include coherence jar in server classpath.
SOA Composite Creation
We will create a simple BPEL process to demonstrate the use of coherence API to store and retrieve cache entries.
Create a sample SOA project in JDeveloper. Add coherence.jar to project libraries which can be found at location $FMW_HOME\coherence_3.5\lib. Create a BPEL process that accepts a string and returns another string.

Create a java embedding activity with following code to verify whether the cache contains a value or not.
String cacheToken= ((oracle.xml.parser.v2.XMLElement) getVariableData ("varInput","payload","/client:process/client:input")).getFirstChild().getNodeValue();
//create new cache or to get the existing cache
NamedCache cache = CacheFactory.getCache("myCache");
//verify whether the key exists or not
setVariableData("valExists", cache.containsKey(cacheToken));
setVariableData("var1", cache.get(cacheToken));
Create a switch case in BPEL flow to call the actual service if the cache value does not exist for the token used. The following expression can be used in the switch case.
bpws:getVariableData(‘valExists’)=string(true())
If the value is retrieved from cache, copy the value stored in ‘var1’ variable to output variable and do reply from BPEL process. Otherwise store the value we have got from the actual service in cache by using another java embedding activity with following code.
String cacheToken= ((oracle.xml.parser.v2.XMLElement) getVariableData("varInput","payload","/client:process/client:input")).getFirstChild().getNodeValue();
String cacheValue= ((oracle.xml.parser.v2.XMLElement) getVariableData("InvokeOutputVariable","parameters","/ns1:getResponse/val")).getFirstChild().getNodeValue();
NamedCache cache = CacheFactory.getCache("myCache");
cache.put(cacheToken,cacheValue);
setVariableData("var1",cache.get(cacheToken));
Execution of BPEL:
When result is not in Cache:
Run the BPEL by giving the value for ‘input’ element that does not exist in the cache currently. Here in this case, we are sending it as ‘NewUser’.


Observe that partner link has been called to get the result.

When result is in Cache:

Observe that partner link is not called and the result is fetched from the cache as expected.

Strategies to Flush/Refresh the Cache:
- Create a configuration parameter or BPEL property to specify whether cache has to be cleared or not. Modify the above switch condition to include this OR condition so that the existing cache will be reset by fetching the value again by calling the partner link.
- Restarting the coherence server.
Like this:
Like Loading...