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.
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.
org.packt.bpel.sync.gen
contains the files that are used for transformation between XML and Java.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.
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.
@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.
helloworldprocess_client_ep = new Helloworldprocess_client_ep(); HelloWorldProcess helloWorldProcess = helloworldprocess_client_ep.getHelloWorldProcess_pt();
String
type as follows:String input = "Jurij"; String output;
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);
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.