Developing and deploying Java Embedding activity in BPEL 2.0 in SOA Suite 11g calling a custom Java Class that has dependencies on 3rd party libraries

Java Embedded activity can call a custom Java class that relies on 3rd party Java libraries. This means that a lot of existing functionality from the Java open source community is at the disposal of the BPEL developer. This article shows a simple example of developing and deploying a BPEL process that uses Java Embedded Activity that calls a custom Java Class that uses Apache HttpClient to make Http POST calls. The article demonstrates how to develop the BPEL process, the Java Embedded activity, Java Class and how to deploy the SOA Composite application. It also presents the results of running the composite application.

Steps for a simple, straightforward demonstration:

1. Create SOA Composite application in JDeveloper 11g – based on the BPEL template




2. Create the directory Application_Root\project\SCA-INF\lib

3. Copy 3rd party libraries to the directory created in the previous step


4. Create the custom Java Class – in the SCA-INF\src directory


The code of this Java Class is the following – inspired by a previous blog article:

package nl.amis.util;


import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;

public class HttpPoster {

  public static String postMessageToUrl(String url, String message) {

      DefaultHttpClient httpClient = new DefaultHttpClient();
      String response;
        try {
            response = postToURL(url, message, httpClient);
        } catch (UnsupportedEncodingException e) { response = e.getMessage();
        } catch (IOException e) {
            response = e.getMessage();
        }catch (RuntimeException e) {
            response = e.getMessage();
       return response;

  private static String postToURL(String url, String message, DefaultHttpClient httpClient) throws IOException, IllegalStateException, UnsupportedEncodingException, RuntimeException {
      HttpPost postRequest = new HttpPost(url);

      StringEntity input = new StringEntity(message);

      HttpResponse response = httpClient.execute(postRequest);

      if (response.getStatusLine().getStatusCode() != 200) {
          throw new RuntimeException("Failed : HTTP error code : "
                  + response.getStatusLine().getStatusCode());

      BufferedReader br = new BufferedReader(
              new InputStreamReader((response.getEntity().getContent())));

      String output;
      StringBuffer totalOutput = new StringBuffer();
      System.out.println("Output from Server .... \n");
      while ((output = br.readLine()) != null) {
      return totalOutput.toString();


5. Add the 3rd party library JARs to the project definition in JDeveloper:


6. Create the Java Embedding activity in the BPEL process


7. (optionally rename the activity) and Double click the activity to start editing the Java snippet



String input = ((XMLText)getVariableData("inputVariable", "payload", "/client:process/client:input/text()")).getText();
System.out.println("Hello, World from BPEL with Java Embedded - input = "+input);
String message = "Message from BPEL process instance, invoked with input variable with value "+input;
String url = "http://localhost:7101/PostHandler/postbox";
String response = HttpPoster.postMessageToUrl(url, message);
System.out.println("response after posting message to url "+url+" is "+response);
setVariableData("outputVariable", "payload", "/client:processResponse/client:result", response);

8. Add import statements for the non-JKD classes used in the Java snippet


9. Deploy the SOA Composite applications.

Note: all Java classes in SCA-INF/src and all JAR files in SCA-INF/lib are included in the SAR:


10. Test-run the BPEL process through its Web Service interface

The Java snippet reads an input variable, writes some logging to the console, passes the value of the input variable to the custom Java class that performs an HTTP POST request (handled by an extremely simple Servlet that does nothing but write the request contents to the console and return a standard response). This response is put on the outputVariable by the Java snippet.

When making this call to the BPEL process:


This output is found in the SOA Suite console:


And the output from the Servlet is


Finally the response from the BPEL process – including the response from servlet invoked by the Java snippet:



Download a zip-file with the SOA Composite application and the extremely simple Servlet project:

One Response

  1. 9959471355 December 10, 2014