Showing posts with label Java Embedding. Show all posts
Showing posts with label Java Embedding. Show all posts

Saturday, July 19, 2008

How to deploy Java Classes with BPEL Process

While implementing a business process using BPEL, sometimes it is required to use Java to implement a functionality required by a business process. You can embed your Java code in BPEL process using Java embedding activity provided by Oracle BPEL. If your Java code is of few lines you can paste it inside the Java embedding editor and you can manage it but if you are planning to implement a functionality which requires lines of code, it is better to create java classes inside your BPEL Process Project. You can leverage JDeveloper’s Java editor to write and manage Java code.

You can import Java classes in the BPEL process using <bpelx:exec import....>. If you deploy the BPEL process from JDeveloper it compiles the Java code and bundle required classes and libraries inside the BPEL suitcase. You can use JDeveloper to deploy your processes on the development server. To deploy a business processes on Test/Performance/Production servers its better to use deployment scripts, because its not wise to modify endpoint URL and other connectivity information manually for each server in your BPEL process project and deploy it.

Using deployment scripts you can
  • Customize WSDL/XSL/XSD end-point locations.
  • Customize JNDI address of Data source/JMS Queue or Topics.
  • Checkout latest code from SVN/CVS/VSS repositories.
  • Deploy BPEL/ESB/Java on the development/test/performance/production environments.

JDeveloper generates an ant build script for each BPEL process project, it uses ant script to build and deploy business process. If your BPEL process is using java classes and you would deploy it from JDeveloper the process will be deployed successfully. All the Java classes and required libraries will be bundled in BPEL-INF folder of the BPEL suitcase.

If you try to execute the same script from the command prompt it will throw an exception like the one given below:

ORABPEL-00017
Java compilation failed.
Failed to compile file(s) "HelloWorldProcess.bpel".
Exception reported is: HelloWorldProcess.bpel:3: Class build.test.HelloWorld not found in import.import build.test.HelloWorld;

If you see the deployment script it does not have an ant task to compile java code. It works in JDeveloper because JDevloper compile the java classes first and then executes this script so the bpelc task is able to find the required Java classes. To make this script work from command prompt you need to do the following:

• Add a task to compile the java classes.

<target name="compileJava" description="Compile Java files">
<echo>
--------------------------------------------------------------
Compiling java files
--------------------------------------------------------------
</echo>
<javac destdir="${process.dir}/output" encoding="UTF-8" source="1.5" target="1.5">
<src path="${src}"/>
</javac>
<mkdir dir="${process.dir}/lib"/>
<jar destfile="${process.dir}/lib/${bpel.classes.jar}">
<fileset dir="${process.dir}/output"/>
</jar>
</target>

• Modify target "compile" and add dependency for target "compileJava".

<target name="compile" depends="compileJava">
• Modify the bpelc task to add classpath for the compiled java classes so bpelc will be able to find the required classes.
<bpelc input="${process.dir}/bpel/bpel.xml" out="${process.dir}/output"
rev="${rev}" home="${bpel.home}" classpath="${env.classpath};${process.dir}\output">

• As some libraries are business process specific, you want to keep them inside the BPEL suitcase rather then adding them to shared libraries or copying to <ORASOA_HOME>/j2ee/home/applib folder. If you copy the libraries to applib folder or add to shared libraries by modifying server.xml you need to bounce the SOA server. To copy the BPEL process specific dependency jars and the classes in the BPEL-INF folder of BPEL suitecase, you need to add <lib> tag in the bpelc task:

<bpelc input="${process.dir}/bpel/bpel.xml" out="${process.dir}/output"
rev="${rev}" home="${bpel.home}" classpath="${env.classpath};${process.dir}\output">
<lib dir="${process.dir}/lib" includes="bpelclasses.jar"/>
<lib dir="${bpel.lib}" includes="**/*.jar"/>
</bpelc>

Save the build script and execute it from command prompt, don’t forget to set username/password for SOA suite and all other environment related properties in build.properties.


Friday, May 9, 2008

How to Make Libraries Available to BPEL Process

I have seen many integration developers struggling with the classpath settings in Oracle SOA Suite. If you don't know the right place to store libraries or the configuration files where you can add required libraries, you can easily waste hours or even days to make libraries available to your BPEL process.

While developing Oracle BPEL Process you need to add the required libraries in Jdeveloper. To add a library in Jdeveloper right click on the BPEL Process project and select “Project Properties” from the context menu. Click on Libraries in the Project Properties tree. From Libraries page you can add a predefined library or you can add jars or folders in the classpath.

If you want to use standalone ant scripts to compile and build your BPEL process flow you need to set classpath in ant build scripts. You need to add libraries in the bpelc task. Add your libraries as given below, add a pathelement for each library:

<classpath>
<pathelement location="Library you want to add into classpath"/>
</classpath>

If you want to use common jars in multiple projects, add the files into classpath of obsetenv.bat or obsetenv.sh based on the platform you are using to run ant build scripts. Edit the obsetenv file and add the libraries in the MY_CLASSPATH variable. e.g.

set MY_CLASSPATH=%Existing Libraries%;<new libraries>

If you are using Java embedding activity in your BPEL process and this activity is referring classes and jars those are not part of the BPEL suite case , you need to add those libraries in the classpath of BPEL Process compiler. BPEL Process Manager generates Java files and compile them at the deployment time so it is required to set all the referenced libraries in BPEL compilers classpath.

You can add the referenced libraries in BPEL Process compiler's classpath by modifying the domain.xml or from the BPEL Process Manager's Console. I am mentioning both procedures, you can use any of them.

  • Edit Domain Configuration file-
    • Edit <Oracle SOA Home>/bpel/domains/<Domain Name>/config/domain.xml

    • Add referenced libraries the file as given below:
      <property id="bpelcClasspath">
      <name>BPEL process compiler classpath</name>
      <value>list of jars separated by ; or : based on the platform you are using</value>
      </property>

    • Restart Oracle BPEL Server.

  • Use BPEL Process Manager Console

    • Open BPEL Process Manager Console and click on “Manage BPEL Domain”. Go to Configuration tab.

    • Enter all the referenced libraries(including path of the libraries); in the value field of bpelcClasspath property..

    • Click on Apply button.

    • Restart Oracle BPEL Process Manager..

    After deployment you will definitely want to test the BPEL process. You need to add the required libraries into Oracle Application Server's classpath, so the referenced libraries would be available for your BPEL process at runtime. Follow the steps given below to add libraries into Oracle Application Server's classpath:

  • Open <Oracle Home>/j2ee/home/config/application.xml and find a shared library named oracle.bpel.common.

  • Add <code-source path="Your library path"/> for each required jar file. You can create a separate library and import it inside the oracle.bpel.common shared library.