Creating a Java Interface
Process Developer provides an easy way for Java developers to use existing Java projects to build Java endpoints in a BPEL process. Your project can include a POJO (plain old Java object) or EJB. (A JavaBean can be used for all application servers except for Apache Tomcat). You can either start with or build a package that includes an interface and a Java class that implements the interface.
Using one of the techniques that Process Developer provides, you can automatically generate a WSDL and schema from your Java interface. The WSDL includes the port type, operation, and messages to create receives, replies, and invokes.
Process Developer also provides built-in features to automatically include all the JAR and other files required for deployment to the server.
Stateless or Stateful Invokes
Using the Java Interface, you can easily create invoke activities in BPEL. These invokes can be stateless or stateful.
- •A stateless invoke means that each time the Java code is called from the BPEL process, a new instance of the Java class is instantiated.
- •A stateful invoke is based on a Java class that is marked implementing the java.io.Serializable marker interface. With a stateful invoke, the process uses the same Java instance throughout the lifetime of the partnerLink useing it. Multiple invokes on the same POJO partner link result in method calls on the same POJO instance.
Setting up Your Java Project in Process Developer
To create a Java interface for a BPEL process, you can start with an existing Java project or create a new Java-enabled orchestration project.
Setup a Java project a Java Project:
- 1. Select File > New > Orchestration Project.
- 2. Name your project and click Next.
- 3. Select Java Enabled Orchestration.
- 4. In the orchestration project, import or create a new Java Project. The Java project must contain:
- - A Java interface with at least one method.
- - Concrete implementation of the Java interface.
Tip: If you have a Java project open in Eclipse, you can switch perspectives from the Eclipse Java Perspective to Process Developer. Then in the Project Explorer, right-mouse click on the project, and select Add Orchestration Nature.
When you add an orchestration nature to your Java project, a background validation builder ensures that you are aware of errors and problems in your process, imported WSDLs, and its other resources. Also, the builders automatically synchronize the generated WSDL with changes that might be made to the source Java.
After adding the Java project to Process Developer, you can generate a WSDL that is the BPEL-oriented interface needed to create activities. For details, see Generating WSDL and Schema from a Java Interface.
See also:
- •Constraints for your Java Project
- •Creating a Java Interface
Constraints for your Java Project
The following requirements exist for Java classes used in a Java Interface implementation:
- •The Java interface's method parameter types are limited to JavaBeans and the following primitive Java types:
- - byte, short, int, long, float, double, boolean, char
- - Byte, Short, Integer, Long, Float, Double, Boolean, Character
- - String
- - BigInteger
- - Date
- •Java checked exceptions are modeled as faults, but the Java method must throw the same exception at runtime for the fault to be properly thrown.
- •The Java interface to the WSDL generator is performed by JAXB, and support for JavaBeans is inherited from JAXB.
- •Arrays and Collections are not currently supported as arguments to Java methods; however, Collections are suwpported if they are wrapped in JavaBeans.
- •The class that implements the interface must have a default constructor.
- •The class that implements the interface can be stateless or stateful. A stateful class is one that is marked implementing the java.io.Serializable marker interface.
See also Creating a Java Interface.
Generating WSDL and Schema from a Java Interface
No WSDL? You can use the New Interface wizard as a quick start to generating the basics of a WSDL.
Generating WSDL and Schema from a Java Interface
Once you have set up your Java project in Process Developer's Project Explorer, you can generate WSDL and schema. A BPEL process requires a WSDL interface, and Process Developer automatically generates it from your Java interface.
Additionally, Process Developer automatically synchronizes the generated WSDL with any changes that you might make to the source Java.
To generate WSDL and schema:
- 1. In your Java orchestration project, create a new BPEL process in the bpel folder.
- 2. In Participants view, right-mouse click on Partner Service Provider and select New Partner Service Provider.
- 3. In the Partner Service Provider dialog, select Generate Interface.
- 4. In the New Interface wizard, select From a Java Interface.
- 5. Browse to your Java interface and select it.
- 6. Notice that the new WSDL is generated in the wsdl folder of your project.
- 7. Select Finish, and then select OK in the Partner Service Provider dialog.
WSDL Generation
The following actions occur when you generate a WSDL and schema from a Java interface:
- •All methods in the Java interface manifest as WSDL operations.
- •All method arguments manifest as top-level XML schema element declarations. The arguments are generated with generic names, such as "argl_string". To generate actual argument names, see Generating Argument Names for Schema Elements.
- •The method return type manifests as a top-level XML schema element declaration.
- •All declared exceptions on the method manifest as WSDL faults.
- •The WSDL is commented with "Do Not Edit" since it is a derived file that can be automatically updated.
The resulting WSDL contains the following constructs:
- •One Partner Link Type named [JavaInterfaceName]PLT
- •One Port Type named [JavaInterfaceName]
- •One Operation within the port type for each method in the Java Interface
- •Two messages for each Java interface method:
- - One message for the method's arguments named [methodName] with a single part of the same name.
- - One message for the method's return value named [methodName]Response with a single part of the same name.
- •Two embedded schema elements for each Java interface method:
- - One element to model the Java interface method's arguments named methodName.
- - One element to model the Java interface method's return value named [methodName]Response.
- •A schema complexType and a schema element for each Java class used by the interface.
Schema Generation
- •Top-level element declarations are created for each of the explicit class references.
- •The implicit declarations manifest as top-level complexTypes and are reused throughout other parts of the schema (if applicable).
More Ways to Generate WSDL and schema:
Technique to Generate WSDL | Result |
---|
In the Interfaces View, select the New Interface toolbar button. | The New Interface Wizard opens for you to select a Java Interface |
In the Project Explorer, select the interface from your Java project. From the right-mouse menu, select Generate WSDL | WSDL and schema are generated in the location you select |
From your Java project, drag and drop a Java interface method to the Process Editor canvas | The Create Activity wizard opens so that you not only generate WSDL and schema, you also create a new Web Services activity (such as a receive). |
See also:
- •Updating Your Java Project and Your BPEL Process Concurrently
- •Creating a Java Interface
Generating Argument Names for Schema Elements
When you generate a WSDL file, as described in Generating WSDL and Schema from a Java Interface, a method’s argument are generated as schema elements. The elements have generic names, such as arg1_string, as shown:
<xs:element form="unqualified" name="arg1_string" type="xs:string"/>
You can generate schema elements with the actual argument names by adding a JAR file called ae_rt.jar to the project's Java build path list of external jars and adding annotations to your interface prior to generating the WSDL.
To generate argument names:
- 1. In the Project Explorer, right-mouse click on your project, and select Properties > Java Build Path.
- 2. Select the Libraries tab.
- 3. Select Add External JARs.
- 4. Browse to [Designer Installation]\designer\plugins\org.activebpel.enginep_[version_number]\server\shared\lib
- 5. Select ae_rt.jar, as shown:
- 6. Open your Java interface file and add the @AeWsdlParam annotation to each argument. For example:
Public interface IMyInterface {
public void execute(
@AeWsdlParam("someValue") String someValue);
}
- 7. Generate (or regenerate ) a WSDL by right-mouse clicking on a Java interface, and selecting Generate WSDL.
Process Developer generates the schema element with the argument name; for example:
<xs:element form="unqualified" name="someValue" type="xs:string"/>
Notes:
- •You should not edit the generated WSDL. If you update the Java interface, you must regenerate the WSDL.
- •You do not need to deploy ae_rt.jar. It is already on the server's classpath.
- •If you upgrade Process Developer to a new version, you must remove the older version of ae_rt.jar and re-add the new one.
Updating Your Java Project and Your BPEL Process Concurrently
You can actively develop both the Java code that is being invoked and the BPEL that is invoking it. Process Developer regenerates the WSDL and schemas whenever the source Java interface or classes change. For example, if you add a new method to the Java interface, Process Developer automatically regenerates the generated WSDL and all generated schemas.
If the WSDL changes, you will see unresolved WSDL references indicators in your BPEL process. Error messages indicate the fixes you need to make for each activity using the WSDL.
See also Creating a Java Interface.
Deployment Requirements for a Java (POJO) Endpoint
Select the Java class that will be created and invoked at runtime.
For details on EJB Service, see Deployment Requirements for Java (EJB) Endpoint.
After you develop a BPEL process with a WSDL based on a Java interface, you're ready to deploy by creating JAR files. You will then provide deployment details specific to the Java interface. When you create the Process Deployment Descriptor (PDD) file for the process, you must provide details for the Java class that is created and invoked at runtime.
To provide required POJO deployment details:
- 1. Open the PDD Editor, as described in Creating a Process Deployment Descriptor File.
- 2. On the Partner Links tab, select the partner role that invokes the Java interface.
Notice that the selection is set to Java Service for the invoke handler.
- 3. In the Java Invoke Handler Properties dialog, select the Java class that is created and invoked at runtime.
- 4. Select the Java classpath to be used when instantiating and invoking the Java class. The classpath includes not only the JAR (or local "src" workspace directory) that contains the class being invoked, but also any JARs that contain classes referenced directly or indirectly by that class.
Note that the Inherit server classloader checkbox is selected by default. If you disable this option, you will only have access to the JARs on your classpath, not the JARs that are deployed to the server. You can also select Parent classloader last when inheriting Process Server classloader.
Deployment Details
When you select a Java invoke handler for the partner role implementing the Java interface, the Java resources are added to the resource catalog and deployed with the process. This includes all of the JARs included in the classpath.
Also, there is no endpoint reference information needed for a Java service.
See also Creating a Java Interface.
Deployment Requirements for Java (EJB) Endpoint
Select the Java class that will be created and invoked at runtime.
For details on setting up and designing a BPEL process with an EJB service, see Creating a Java Interface.
If you have developed a Web service implemented as an EJB, you can deploy the JAR files and other resources using the partner role invoke handler called EJB Service. Note that in the PDD Editor, the invoke handler detects your EJB project as a POJO and automatically selects Java Service. Be sure to select EJB Service.
Also note that an EJB Service cannot be used on Apache Tomcat. It is supported on other application servers.
The EJB Service handler performs a JNDI lookup to obtain the EJB home to instantiate the object used to call the method.
To fill in the EJB Service Invoke Handler Properties Dialog:
- 1. For a JNDI Name, specify the JNDI name as defined in your application server's EJB file, such as the JBOSS ejb-jar.xml file, the WebLogic weblogic-ejb-jar.xml file, or the WebSphere ibm-ejb-jar-bnd.xml file.
- 2. For EJB Home, specify the home interface as defined in application server's ejb-jar.xml file.
This property is required for WebSphere, but is optional for JBoss and WebLogic.
- 3. In the Classpath box, select the Java classpath that is used when instantiating and invoking the Java class. The classpath includes not only the JAR (or local "src" workspace directory) that contains the class being invoked, but also any JARs that contain classes referenced directly or indirectly by that class.
Note that the Inherit server classloader checkbox is selected by default. If you disable this option, you will only have access to the JARs on your classpath, not the JARs that are deployed to the server.
When you select an EJB invoke handler for the partner role implementing the EJB interface, the Java resources are added to the resource catalog and deployed with the process. This includes all of the JARs included in the classpath.
Also, there is no endpoint reference information needed for an EJB service.
Running a BPEL Process with a POJO EJB Endpoint
At runtime, when an invoke activity based on a Java endpoint executes, Process Developer invokes the Java method as follows:
- •Unmarshalls the WSDL message into Java objects. (For a POJO, reflection is used. For an EJB, a JNDI lookup is used.)
- •Instantiates the concrete Java class.
- •Invokes the appropriate method, based on the WSDL operation name.
- •Marshalls the method return value into a WSDL message (or marshalls the Java exception into a WSDL fault).
Comparing the POJO EJB Interface to a Custom Java Invoke Handler
The Java Interface is designed for ease-of-use. A WSDL is generated for you and the JARs and other resources are automatically deployed in a BPR file. However, you must keep the Java project simple by following the requirements outlined in Constraints for your Java Project.
If your BPEL process requires custom Java code that handles asynchronous call-backs, policy assertions, and other details, you can use the Java wrapper custom invoke handler, as described in EJB/Java Invoke Handler Properties Dialog.