How to embed Java code in Oracle BPEL process?

This section we explain how to incorporate a Java code inside a BPEL process. Oracle BPEL has Java Embedding component which acts as an adapter between the BPEL process and Java code. Using this component, we can communicate to Java, say call a Java method from BPEL process . The following details are explaned here

1. How to create Java classes in BPEL project

2. Why is logging necessary?

3. How to add dependent jar files in to the project

4. How to call a Java method from BPEL process

 

1. How to create Java classes in BPEL project

First, BPEL project requires a JAVA class so from a process we can call the Java method. To create Java class

  • Add your existing project into a JAR file and add it to the project (or)
  • Create a Java classes and packages inside the project.

As shown in the below image, A Java class, and a package were created inside the BPEL project. The Sample.java has one method getNewName() which get a string argument and returns a modified String. We are going to call this method from the BPEL process.

Note: To create a Java class/package, right click on the Project, Select New, Gallery, Select General, and Select Java Class or Java Package

 

122216_0321_HowtoembedJ1 How to embed Java code in Oracle BPEL process?

 

 

Why is logging necessary?

We can audit the BPEL process to see how the data is flowing or to see any errors, in the WebLogic Enterprise manager but what about the errors occur in the Java class. Tracking errors in WebLogic server log is hard and sometimes we not sure which log file the java is writing the errors. To solve this, we can write logging in a custom file in the java class. As mention in the below image, I have added log4j.properties in the java package and used Logger to write information(see above). I enabled file logger in log4j.Properties so whatever the Java class throws it writes

To solve this, we can write logging in a custom file in the java class. As mention in the below image, I have added log4j.properties in the java package and used Logger to write information(see the Java classabove). I enabled file logger in log4j.Properties so whatever the Java class throws it writes in a log file. So after this enabled, we can track Java errors in log file and BPEL errors in audit trial inside WebLogic enterprise manager.

 

122216_0321_HowtoembedJ2 How to embed Java code in Oracle BPEL process?

 

 

3. How to add dependent jar files to the project

Ok, we have added Java class and added log4j. What about the dependent jar files the java class is looking for? Or you built every thing in a jar file and wanted to add it to the project? In this example, log4j.jar is a dependent jar file. To add this jar file

  • Right click on the project, Click Properties, Libraries and Class path, Add Jar file, Select the jar file from your location
  • Also, open your project in file explorer, Go into SOA, SCA-INF, and lib directory. Place your jar file.

Note: If you have any property file that Java is looking, below. add those files in SOA\SCA-INF\classes folder

 

4. How to call a Java method from BPEL process

A) Like Java, we must import the Java class in the BPEL process before using it. Open your BPEL process, Click on the source tab, add the import statement like under the processing element. Replace the class name with yours in the location attribute. I added only one class because I used only one if you use more than one java class than add multiple imports.

 

122216_0321_HowtoembedJ3 How to embed Java code in Oracle BPEL process?

 

 

B) Click on the design tab, Drag and Drop the BPEL Java Embedding into the process as shown below

 

122216_0321_HowtoembedJ4 How to embed Java code in Oracle BPEL process?

 

C) Once added, The BPEL Java embedding will be like below.

122216_0321_HowtoembedJ5 How to embed Java code in Oracle BPEL process?

 

D) Double click to open the BPEL Java Embedding activity. Click on the General tab and add Java code to call the method in Java like below. Here I have used two BPEL variables ‘Name’ and ‘NewName’

Note: Bpel wont through any compile time error if java code contains any error. It throws error at deployment time. 

 

Screenshot of the above code in the  BPEL Java Embedding Activity. 

JAVA_EMBEDDING-300x186 How to embed Java code in Oracle BPEL process?

 

E) The final BPEL process is like below

122216_0321_HowtoembedJ7 How to embed Java code in Oracle BPEL process?

 

 

govindan How to embed Java code in Oracle BPEL process?
Connect me

Govind

Thank you for visiting my personal blog. Myself Govindan, Software Developer by profession since 2006 and hence I started this blog early in 2016 and ever since I've been writing about technologies experienced and learnings of everyday life.

The views expressed on this blog are my personal views and do not necessarily reflect the views of my employer.

Please feeling free to reach me on any comments and feedbacks you have. Would be more than glad to listen and reply šŸ™‚
govindan How to embed Java code in Oracle BPEL process?
Connect me
By | 2016-12-22T15:08:14+00:00 December 21st, 2016|Categories: BPEL|Tags: , , , |0 Comments
Like us on Facebook.
Connect!