Thursday, September 1, 2011

Calling custom APIs in BPEL using java embedding

Any Java API can be used in bpel using java embedding activity.Please follow the previous post of custom logging using log4j.Same approach can be used to call any Java API from BPEL

selectionFailure fault while updating the output variable in Java Embedding

In my java embedding i was updating the outvariable of the bpel  using the setVariable method.But i was getting the following error in doing so.
{{http://docs.oasis-open.org/wsbpel/2.0/process/executable}selectionFailure}

messageType: {{http://schemas.oracle.com/bpel/extension}RuntimeFaultMessage}
parts: {{
summary=
 
There can be 2 reasons for this either the Xapth expression is wrong.
Second in 11g before setting the value of the outvariable in java embedding it should be intialized.Put an assign activity before java embedding and  initialize the variable and than set the value in java embedding and it will work.

Custom logging in BPEL 2.0 using Log4j

We can use Java Embedding activity to do custom logging using log4j.
Download log4j
Extract the zip file and use the log4j.jar file from that.There are two approaches of using the jar file.
First approach is to put the jar file at the server so that all the applications can use it.
For  doing to do the following steps.
1. Copy the log4j,jar at the following location  /Oracle_SOA1/soa/modules/oracle.soa.ext_11.1.1/
2. Open the command prompt and go the the above location.
3. Set the following enironment variables
ANT_HOME -where your ant is installed
PATH -path to bin folder of ant
JAVA_HOME -path to jdk
4.Run the ant command.
5. Check the oracle.soa.ext.jar file in the path log4j.jar path gets added in the jar file
6. Restart the managed server.
Now create log4j.properties file
 # logging: Log4j_BPEL
log4j.category.Log4j_BPEL=info,Log4j_BPEL
log4j.appender.Log4j_BPEL=org.apache.log4j.RollingFileAppender
log4j.appender.Log4j_BPEL.File=D:\\Log4j_BPEL.log
log4j.appender.Log4j_BPEL.MaxFileSize=5MB
log4j.appender.Log4j_BPEL.MaxBackupIndex=10
log4j.appender.Log4j_BPEL.layout=org.apache.log4j.PatternLayout
log4j.appender.Log4j_BPEL.layout.ConversionPattern=%d{ISO8601} %-5p [%t] [%c] [%x] %m%n
Copy this file in any location on the server.Say D:\log4j.properties
Import the classes in .bpel file for bpel 2.0
          For importing the classes in bpel 1.1 use the following


importType="http://schemas.oracle.com/bpel/extension/java"/>


importType="http://schemas.oracle.com/bpel/extension/java"/>

Now in your java embedding activity enter the following java code
/*Write your java code below e.g.            
                System.out.println("Hello, World");           
*/           
try{    
String sLog4jFile = "D:\\log4j.properties";             
PropertyConfigurator.configure(sLog4jFile);             
Logger logger = Logger.getLogger("Log4j_BPEL");      
logger.info(">>>> Message log for instance: " + getTitle());         
XMLElement input= (XMLElement)getVariableData("inputVariable", "payload","/client:process/client:input");         
addAuditTrailEntry("input is: " + input.getTextContent());        
logger.info("Input Value :"+input.getTextContent());       
setVariableData("outputVariable","payload","/client:processResponse/client:result", input.getTextContent());    
}catch(Exception e)    
{    
e.printStackTrace();    
}

Deploy the composite and check log file gets created in the location mentioned in the properties file.
Other approach is to copy the log4j.jar in the composite folder under /SCA-INF/lib folder.