Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
BPEL and Java Cookbook

You're reading from   BPEL and Java Cookbook Written by an SOA guru to help you orchestrate web services, the 100 recipes in this book will make integrating Java and BPEL a smooth process. Using the examples you'll avoid common problems and learn sophisticated techniques.

Arrow left icon
Product type Paperback
Published in Sep 2013
Publisher Packt
ISBN-13 9781849689205
Length 382 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Jurij Laznik Jurij Laznik
Author Profile Icon Jurij Laznik
Jurij Laznik
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Calling BPEL from Java FREE CHAPTER 2. Calling Services from BPEL 3. Advanced Tracing and Logging 4. Custom Logging in the Oracle SOA Suite 5. Transforming and Validating the BPEL Services 6. Embedding Third-party Java Libraries 7. Accessing and Updating the Variables 8. Exposing Java Code as a SOAP Service 9. Embedding Java Code Snippets 10. Using XML Facade for DOM 11. Exposing Java Code as a Web Service Index

Calling a synchronous BPEL process from Java

This recipe explains how to call a synchronous BPEL process from Java. When a client calls a synchronous BPEL, it gets blocked until the BPEL process finishes the processing and returns the response. Usually, synchronous BPEL processes are designed for cases where the operation will be completed in a relatively short time. For long-running operations, we instead design asynchronous BPEL processes. This recipe will also cover how to prepare a Java package for integration with Java applications. From the client perspective, a synchronous BPEL process can be invoked in the same way a synchronous web service could. The client is most commonly called proxy , and it is used to ease the connection between the two technologies. In our case, we would like to call the BPEL process, which is mainly the XML content, from Java and proxy is helping us to get across the gap between those two technologies.

How to do it…

In order to call a synchronous BPEL process, we will develop a Java client using the JDeveloper wizard. After completing this recipe, we will be able to call a synchronous BPEL process from the Java client application.

  1. First, we create another project in JDevelper. On the previously created BPEL sample project, we right-click, and select New…. From the Business Tier category, we select Web Services and then we select Web Service Proxy under Items as shown in the following screenshot:
    How to do it…
  2. Then, we click on OK, which shows the welcome screen, and then we click on Next. We have to enter the WSDL location of the BPEL process in the next window. We also have the ability to choose whether we want to copy the WSDL file into the project.
    How to do it…

    Note

    We can either choose the file location from the hard drive or enter the URL for the WSDL location of the BPEL process.

  3. In the next window, we have to enter the name of the Java packages. We have to enter the package name of the proxy files (that is, Root Package for Generated Types) and Package Name, which is where the files for the XML serialization will be placed, as shown in the following screenshot:
    How to do it…
  4. We have inserted all the mandatory fields necessary to create the BPEL process proxy, so we conclude the wizard by clicking on Finish.
  5. In JDeveloper, we see that a number of files were generated in a separate project. The package org.packt.bpel.sync.gen contains the files that are used for transformation between XML and Java.
  6. Let us check the Process.java file. We see that the class contains only one member as follows:
        @XmlElement(required = true)
        protected String input;

    The code is annotated with the @XmlElement annotation, which indicates the usage of JAXB (Java Architecture for XML Binding). The JAXB implementation enables conversion from Java to XML and vice-versa. We need this conversion because data in Java is stored in objects, while BPEL holds data in XML format.

    Note

    This variable presents the input parameter of the BPEL process. The class also contains two helper methods for setting the value and getting the value of the variable. Similarly, we can check the ProcessResponse.java class file which contains the output parameter of the BPEL process.

    The most interesting generated file is HelloWorldProcess_ptClient.java. This file contains skeleton prepared to call the BPEL process.

  7. The code starts with the reference to the BPEL process. Since the BPEL process is exposed as a web service, the code is as follows:
      @WebServiceRef
      private static Helloworldprocess_client_ep helloworldprocess_client_ep;

    We can also note the @WebServiceRef annotation, which is used by JAX-WS (Java API for XML Web Services). The annotation indicates a reference to the web service port, or in our case, the BPEL process port.

  8. We need to instantiate the proxy to the BPEL process and get the reference to the endpoint as follows:
      helloworldprocess_client_ep = new Helloworldprocess_client_ep();
      HelloWorldProcess helloWorldProcess = helloworldprocess_client_ep.getHelloWorldProcess_pt();
  9. We define the input and output variables as the String type as follows:
      String input = "Jurij";
      String output;
  10. Remember that the BPEL process is taking string as an input. As a result, the BPEL process returns a concatenated string starting with Hello, followed by the input string, and concluded with three exclamation marks. Finally, we call the BPEL process and write results to the output as follows:
      output = helloWorldProcess.process(input);
      System.out.println("Business process returned:" + output);
  11. As a result of the BPEL process call, we receive the following output to JDeveloper:
    How to do it…
  12. We can see that the BPEL process was executed in the Oracle Enterprise Manager Console as shown in the following screenshot:
    How to do it…
  13. We can now see that the BPEL process completed successfully.

How it works…

With the wizard in JDeveloper, we prepare the Java proxy for calling the BPEL process using the wizards in JDeveloper. When the client is executed, it converts the parameters from Java types to XML types via JAX-WS. Then, the call to the BPEL process is performed, and after the BPEL process finishes, the client receives the result in XML. The XML types are then converted back to Java types.

There's more…

We can define different options when creating the BPEL process proxy as follows:

  • By creating asynchronous methods
  • By defining the security policies for the BPEL process
  • By defining the handlers which deal with the web service messages
You have been reading a chapter from
BPEL and Java Cookbook
Published in: Sep 2013
Publisher: Packt
ISBN-13: 9781849689205
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image