Java embedding activity is a means of embedding Java and J2EE code directly inside Oracle BPEL process. Even though java embedding can provide enhanced functionality (since you can plug in any java code here!!), this should be avoided as much as possible – since the code would be harder to manage and will not be “SOA” like. Since this is an Oracle extension, it is not part of BPEL standard spec – hence won’t be portable!!
In this example, we have a simple hello java project which takes an input value and returns simple hello response back to the user. The process modifies the instance title, adds audit trail entries for more detailed logging in process flow. In this example, the java code is part of SOA application and hence will be compiled and be available in the class path after deployment. You can add jar files of the java project to the classpath (either at project level or at system level) if the functionality is part of another system or if you want to manage it separately!!
Create a simple java class for calling from embed activity
Java Embedding activity
Use Java embedding activity in BPEL to call the custom java class directly from BPEL.
Use import statements to import classes and libraries before using in java embedding. Easiest way is to use bpelx:exec statement import attribute.
Initialize Output Variable
Before you can set a particular element in a variable (for eg. outputVariable/processResponse/result), the variable needs to be initialized. Note that Oracle BPEL auto initializes these variables with the correct structure first time its used (for eg. in assign statement). So, either initialize the message structure yourself in java embedding or do a dummy assign to outputVariable such that it gets initialized!!!
Final BPEL Flow
Finally the BPEL flow looks like below.
Instance Flow Trace
Instance flow trace has additional audit trail entries we have added from java.
Instance title has been successfully modified from java embedding.