In this recipe, we will embed a snippet of Java code into our BPEL process.
Double-click the Java activity to open the Edit Java Embedding dialog, and enter the Java code to be executed.
BPEL variables can be read by using the getVariableData
method that is predefined. This method takes three parameters, namely the variable name, the message part (if it is a message variable), and the XPath expression (if any). The XPath expression must use appropriate namespace prefixes declared in the BPEL process.
org.w3c.dom.Element elem = (org.w3c.dom.Element)getVariableData("inputVariable", "payload", "/client:process/client:input");
The setVariableData
method is used to write to variables in the BPEL process. This takes up to four parameters, with the fourth parameter being the data that we need to store in the BPEL variable.
setVariableData("outputVariable", "payload", "/client:processResponse/client:result", "Response");
The Java embedding activity causes the Java code to be included in the code that is generated when the BPEL process is compiled. This is actually an instance of an extension of the com.collaxa.cube.engine.ext.bpel.v1.nodes.BPELXExecLet
class. This class is part of the BPEL process and is used to implement the Exec activity. Any namespace prefixes in the scope of the BPEL process may be used in XPath expressions in the embedded Java code.
18.223.106.33