Sunday, June 22, 2008

invoking BPEL from java using RMI

I would like to list down some of the issues I faced and their workarounds while trying to invoke a BPEL process from JAVA program using RMI

Some of you would be aware that sample RMI code is available in the samples provided by SOA Suite.I am explaining the steps you need to follow to make the program working.

Create a java project and add the 2 jars required for compilation namely orabpel.jar and xmlparserv2.jar

The code should first set the properties required for RMI invocation

Properties props = new java.util.Properties();

Map map = new HashMap();

map.put("java.naming.factory.initial","com.evermind.server.rmi.RMIInitialContextFactory");

map.put("java.naming.provider.url", "opmn:ormi://$hostname:$opmn_port:$oc4jinstance/orabpel");

map.put("java.naming.security.principal","$username");

map.put("java.naming.security.credentials","$password");

props.putAll(map);


Then use the Locator class to connect to domain with password and properties

Locator locator = new Locator("default","welcome1",props);

IDeliveryService deliveryService = (IDeliveryService)locator.lookupService(IDeliveryService.SERVICE_NAME );


DeliveryService is used for invocation of the process. Will explain the methods during the invocation.

Create the input xml message to be given to the BPEL process

String xml = "<ns1:BPELProcess2ProcessRequest xmlns:ns1=\"http://xmlns.oracle.com/BPELProcess2\">\n" +

" <ns1:input>geo</ns1:input>\n" +

" </ns1:BPELProcess2ProcessRequest>";

You can get the xml snippet by running the process once in you BPEL console and copy the request tags .Now create a NormalizedMessage object which will be passed with the invocation.

NormalizedMessage nm = new NormalizedMessage( );

nm.addPart("payload", xml );


As you would be knowing there are 2 types of invocations.

One-way invocation and two-way invocation


So for one-way invocation use Post method of the DeliveryService


String processid = "OneWayHello";

String operation = "initiate";

deliveryService.post(processid, operation, nm);


For two-way invocation use request method of the DeliveryService

String processid = "TwoWayHello";

String operation = "process";

NormalizedMessage res = deliveryService.request(processid, operation, nm);


To view the response message use XMLHelper

Map payload = res.getPayload();

Element partEl = (Element) payload.get("payload");

System.out.println( "HelloWorld is " + XMLHelper.toXML(partEl) );


To run the RMI program you need to have some more additional jars in your classpath

Oc4j.jar,oc4jclient.jar,,rmic.jar and commons-logging.api.

If the oc4jinstance is wrongly mentioned like you have specified home instead of oc4j_soa then you will be getting following exception

java.lang.Exception: Failed to create "ejb/collaxa/system/DeliveryBean" bean; exception reported is: "javax.naming.NameNotFoundException: ejb/collaxa/system/DeliveryBean not found

Your code should be up and running and be able to interact with BPEL process.

Saturday, June 14, 2008

difference of syntax - wsadmin md5encode between 10.1.3.1 and 10.1.3.3

For file based authentication in OWSM we will be using a md5encode utility. Those who follow the Oracle® Web Services Manager Quick Start Guide 10.1.3.1 for starting with OWSM will face some issues while trying to encode the password using md5encode utility in 10.1.3.3.

The issue is that the syntax for using md5encode has changed from 10.1.3.1 to 10.1.3.3.

After creating a text file and add a user name and password in the following format: user_name:password (Save as .htpassword file).Use md5encode operation to encode a password associated with a user to the specified password file.

Syntax (10.1.3.3)
>wsmadmin md5encode htpasswdfile username

Parameters

htpasswdfile – Name of the file containing the user name and password

username – User name in the text file

Syntax(10.1.3.1)

>wsmadmin md5encode username password htpasswdfile

Parameters

username – User name in the text file

password – Password assigned to the user

htpasswdfile – Name of the file containing the user name and password

Since I referred to the old tutorial I was faced with wrong syntax issue and to finally use the md5encode utility I had to manually edit the xml file(md5encoder.xml) which invokes the md5encode utility from wsadmin bat file.

From wsadmin bat file it calls the build file wsm.xml and target wsm.md5encode which is defined in md5encoder.xml.I hard coded the arguments in md5encoder.xml build file and executed it separately for generating the encoded .htpasswd file. I never had an idea that the syntax will change so much between 10.1.3.1 and 10.1.3.3. So always refer to the version specific tutorials for the correct syntax.

Wednesday, June 11, 2008

MDB EJB’s inside BPEL Server

There are 2 important message driven beans(MDB) in the BPEL server which takes care of handling the requests. The entries of these ejb’s are located in orion-ejb-jar.xml @ Oracle_Home\j2ee\home\application-deployments\orabpel\ejb_ob_engine.

WorkerBean

Oracle BPEL Server uses an MDB called WorkerBean to perform processing of requests. In the case of one-way invocation(durable process) the request to the server is placed in a queue. Inside Oracle BPEL Server, WorkerBean monitors the queue for invocation requests and then it is dequeued and assigned a new thread for servicing the request

<message-driven-deployment name="WorkerBean">

</message-driven-deployment>

InvokerBean

The invoker bean is used only for nonblocking invoke activities. It depends on the setting of nonBlockingInvoke BPEL Property. This property comes into picture while executing multiple branches of a flowor flowN activity. By default, Oracle BPEL Process Manager executes in a single thread, executing the branches sequentially instead of in parallel. When this property is set to true, BPEL Server spawns a new thread to execute the invocation. InvokerBean is the one which creates new threads to service the request.

<message-driven-deployment name="InvokerBean">

</message-driven-deployment>


The number of threads used by these ejbs has to be taken into account while configuring the number of connections to database. I will write more on these in coming blogs.


Thursday, June 5, 2008

How to utilize Logical Name Option in ESB

I used to get queries on how you can add logical names to different values used in a ESB application. I like editing files more than using UI . So I am adding this blog on how to manually enter property-value sets in ESB


In BPEL you can edit bpel.xml to add end point properties and its easy to do it from JDEVIn BPEL you can edit bpel.xml to add end point properties and its easy to do it from JDEV. In the case of ESB you need to open the ESBsvc file outside the JDEv and add the following tags . Hope it helps you.


The tag to be added

<endpointProperties>

<property name="Dir" value="c:\temp"/>

<property/>

</endpointProperties>

Sample ESBsvc file

<service name="TestService" …>

<serviceDefinition>

<wsdlURL> </wsdlURL>

<portType>tns:initiate_ppt</portType>

<endpointDefinition>

</endpointDefinition>

</serviceDefinition>

<operations>

<operationInfo>

<routingRules>

<routingRule ">

<targetOperation />

</routingRule>

</routingRules>

</operationInfo>

</operations>

<endpointProperties>

<property name="Dir" value="c:\temp"/>

</endpointProperties>

</service>