Wednesday, July 30, 2008

Find the OPMN Port for Java BPEL API Calls

Frequently, you'll need the OPMN request port for doing Java BPEL API calls.

You can find this value by looking at the opmn.xml file on the mid tier application server. It is in the $ORACLE_SOA_HOME/opmn/conf directory. Around the 5th line down in the "port" tag, you'll need to use the port number specified in the "request" attribute.

Wednesday, July 16, 2008

Add attachment to BPEL Human Task at creation

Consider the sample BPEL flow below, which contains a Human Task activity. It may be useful at times to have BPEL attach data to the task as an attachment file. How can this be done?




















We can do this by expanding the human task activity and providing some custom initialization code in the first, the AssignTaskAttributes, assignment section.




By adding four additional Copy directives to the existing assignment block, we can effectively cause the file attachment to be created:


<copy>
<from>
<attachment xmlns="http://xmlns.oracle.com/bpel/workflow/task">
<name/>
<mimeType/>
<content/>
</attachment>
</from>
<to variable="initiateTaskInput" part="payload"
query="/taskservice:initiateTask/task:task/task:attachment"/>
</copy>

<copy>
<from expression="string('text/plain')"/>
<to variable="initiateTaskInput" part="payload"
query="/taskservice:initiateTask/task:task/task:attachment[1]/task:mimeType"/>
</copy>

<copy>
<from expression="string('Test.txt')"/>
<to variable="initiateTaskInput" part="payload"
query="/taskservice:initiateTask/task:task/task:attachment[1]/task:name"/>
</copy>

<copy>
<from expression="string('Some string of text content here...')"/>
<to variable="initiateTaskInput" part="payload"
query="/taskservice:initiateTask/task:task/task:attachment[1]/task:content"/>
</copy>


The first copy block, creates a new attachment element and adds to the task. The next three copies initialize the properties of that attachment including the mime type, file name, and content.

In the above example we will have attached a simple text document with the name of Test.txt to the human task. Mime type can be any type desired, one of the more useful being application/octet-stream. Using that type I will show in my next article how to send a file attachment from a JSP/Servlet to the BPEL process and have it attached to the Human Task.

Monday, July 14, 2008

Invoke BPEL Process with Java API

This is a frequently asked question on the Oracle BPEL Forums, so I thought I would address it here.

import com.oracle.bpel.client.Locator;

import com.oracle.bpel.client.NormalizedMessage;
import com.oracle.bpel.client.delivery.IDeliveryService;

public class InvokeBpel {

public static void main(String args[]) {
Properties props = new java.util.Properties();
Locator locator = null;
IDeliveryService svc = null;
NormalizedMessage msg = null;

try {

// load the propertiess object with the server info
props.put("orabpel.platform", "ias_10g");
props.put("java.naming.factory.initial",
"com.evermind.server.rmi.RMIInitialContextFactory");
props.put("java.naming.provider.url",
"opmn:ormi://ibp103.mascocs.com:6012:OC4J_BPEL/orabpel");
props.put("java.naming.security.principal", "oc4jadmin");
props.put("java.naming.security.credentials", "test123");

// get the reference to the locator object
locator = new Locator("default", "test123", props);

// get the service provider
svc = (IDeliveryService)locator.lookupService(IDeliveryService.SERVICE_NAME);

// create a normalized message with our xml string as the payload
String xmlString = "Your valid XML goes here";

msg = new NormalizedMessage();
msg.addPart("payload" , xmlString);

// async request so we post/initiate it
svc.post("TestBPELProcess", "initiate", msg);

// for a sync request we would request/process it like so:
//
// resp = svc.request("TestBPELProcess", "process", msg);
//
// our resp would be the NormalizedMessage response from the server

} catch (Exception e) {
e.printStackTrace();
}

} // end of main()

} // end of class