Monday, August 30, 2010

File Adapter : Process Files Sequentially

Issue : I have a BPEL process where I have a job and corresponding to a single job I need to load n number of xml files to database. I create a unique job in database and then keep updating that row with whatever number of xml files I loaded in the database for that job. The problem was since BPEL was doing parallel processing so all the xml files were getting processed at the same time and were trying to update the same row. Due to Oracle's read consistent property all of them were getting the loaded value as 0 initially and each one of them updated the xmlLoaded column to 1; where as what I wanted was that if I load 11 xml's then the load should happen sequentially as well the count shall be sequentially updated to 11.

Resolution : To fix this issue you will have to add the following two properties in the jca file for the file adapter


               <property name="SingleThreadModel" value="true"/>
               <property name="MaxRaiseSize" value="1"/>



These properties go between the </activation-spec> tag in the file adapter.

DB Adapter : Cache Issue with Using Native Sequence (Oracle)

I had faced an issue with the Oracle Sequences while using DB adapter in BPEL.

Just to give you a little background. I have a file adapter that polls for new files. The file contains only one record which I have to insert into database. During insertion I use the Native Sequencing to insert primary key  into the table. My sequence is incremented by 1 with no cache specified.

Issue : After some loads I started getting the constraint voilation errors on the primary key.
Observation : Suppose my sequence was initially started by 1 then, now if I check the currval of the sequence in database it was 50 whereas the BPEL still is using values much lesser than that; which lets me come to an obvious conclusion that somehow weblogic is caching the sequence numbers.

After reading a lot of blogs I could understand that while configuring your database connections from Weblogic, weblogic by default keeps some values there for performance. The DBAdapter resource controlls the caching of the sequences using the sequencePreallocationSize parameter.

If anyone lands into the same issue then follow the following instruction 


On the Weblogic Admin Console 

  1. Click on Deployments -> Resource Adapter DbAdapter
  2. Click on Configuration Tab
  3. Click on Outbound Connection Pools
  4. Expand the javax.resource.cci.ConnectionFactory Expand Node javax.resource.cci.ConnectionFactory
  5. Click on your own Connection Pool factory
  6. Modify parameter sequencePreallocationSize to 1 
  7. Press Keyboard Enter and click on Save to save.
  8. Click on View changes and restarts to see if starts are requierd





Thursday, August 26, 2010

Pass Variables from Bpel to XSL

There is often need to pass variables from BPEL to XSL; in my case I was dealing a lot with file adapters and database adapters. I had to get the filename from file adapter and pass it to XSL so that it could be saved in database

Following are the steps to do so - :
1. Create a file anywhere and name it params.xsd (you can name it whatever u want)
2. Copy the following schema definition in the file
<?xml version= '1.0' encoding= 'UTF-8' ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.oracle.com/service/bpel/common" targetNamespace="http://schemas.oracle.com/service/bpel/common" elementFormDefault="qualified"> <xsd:element name="parameters"> <xsd:complexType> <xsd:sequence> <xsd:element name="item" minOccurs="1" maxOccurs="unbounded"> <xsd:complexType> <xsd:sequence> <xsd:element name="name" type="xsd:string"/> <xsd:element name="value" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>


Note : Press ctrl+shift+l in jdeveloper for formatting



3. In your BPEL create a variable e.g. varBpelXsl
  • Choose variable type as Element
  • Click on search option
  • On the top right corner of the "Type Chooser" popup click on "Import Schema file"
  • Browse for the params.xsd that you created above
  • Select any partner link type (You have to do this as that is the only way that your schema is imported in BPEL)
4. Add the following code in your BPEL


 <assign name="assignPropertyValues1">
<copy>
<from>
<parameters xmlns="http://schemas.oracle.com/service/bpel/common">
<item>
<name>ParamOne</name>
<value/>
</item>
<item>
<name>ParamTwo</name>
<value/>
</item>
</parameters>
</from>
<to variable="varBpelXsl" query="/ns3:parameters"/>
</copy>
</assign>
<assign name="assignPropertyValues2">
<copy>
<from expression="substring-before(bpws:getVariableData('varFileName'),'_')"/>
<to variable="varBpelXsl"
query="/ns3:parameters/ns3:item[1]/ns3:value"/>
</copy>
<copy>
<from expression="bpws:getVariableData('varFileName')"/>
<to variable="varBpelXsl"
query="/ns3:parameters/ns3:item[2]/ns3:value"/>
</copy>
</assign>
NOTE: The {ns3} above shall be replaced by the namespace provided to the schema definition imported while creating the variable

5. Modify the transform activity to include the 3rd parameter

&lt;from expression="ora:processXSLT('xsl/transformationLoadProperty.xsl',bpws:getVariableData('varPropertyFile','body'),bpws:getVariableData('varBpelXsl'))"/&gt;

6. Now to use the variable in XSL Mapping file
  • Define two variable in the XSL before the XSL:template tag
<xsl:param name="ParamOne">
<xsl:param name="ParamTwo">
  • Use the parameters as $ParamTwo and $ParamOne in your transformation