By Ramkumar Menon on May 7, 2008 9:03 PM
You might have run into a requirement where you need to compute the total value of all items in a purchase order. Consider the PO XML shown below.
<?xml version="1.0" encoding="UTF-8" ?>
<po xmlns="http://www.example.org">
<Items>
<item>
<price>1</price>
<qty>2</qty>
</item>
<item>
<price>3</price>
<qty>4</qty>
</item>
<item>
<price>5</price>
<qty>6</qty>
</item>
</Items>
</po>
You might want to compute the total value of all items in the purchase Order. For computing this, you would need to multiply the price and qty for each item, and add them up. In XSLT 1.0, I guess the way to do this would be to recursively invoke a template that computes the sum total. In XSLT 2.0, this can be done in a very elegant single expression.
<xsl:variable name="itemVar" select="/tns:po/tns:Items/tns:item"/>
<xsl:template match="/">
<tns:poSummary>
<tns:totalValue><xsl:value-of select="sum(for $i in $itemVar return ($i/tns:price * $i/tns:qty))"/></tns:totalValue>
</tns:poSummary>
</xsl:template>
</xsl:stylesheet>
By Ramkumar Menon on May 16, 2008 3:30 PM
EJB session beans can be invoked from a BPEL process through WSIF. Oracle BPEL PM ships with a WSIF provider for invoking EJBs.
For demonstrating this, lets create a new EJB session bean. The session bean shall have one single business method namely "greetUser" that takes in a string argument userName, and returns a string value "Hello <USERNAME>".
Step 1: Creating the HelloWorld Session Bean.
- Create a new BPEL empty process project.
- Open up the New Gallery and choose to create a new EJB session bean.
- Choose the option for creating EJB 2.1 session bean. Give the Bean the name"HelloWorld", accept the remaining defaults and finish the wizard.
- Double click on the EJB in the Applications Navigator to bring up the EJB Module Editor". Specify the new business method in the "Methods" tab. Type in the parameter name and type manually in the text editor
- CLick ok to accept the changes. Click on the "orion-ejb-jar.xml" in the Applications Navigator. Here you need to provide the JNDI locaiton of the session bean. For this, add a "location" attribute on the <SESSION-DEPLOYMENT>to provide the JNDI "ejb/session/HelloWorld".
- Your bean is now ready for deployment. Build the project and deploy to an OC4J container.
Step 2: Build the BPEL Process
- Create a new BPEL Process project.
- Create a new WSDL document in the project directory and name it HelloWorldEJB.wsdl.
- Add the bindings section that allow the process to invoke the EJB through WSIF. The salient portion of the bindings section is the jndiProviderURL. For an Application Server install, use the opmn ormi jndi provider URL. For standalone installations,use plain ormi provider URLs. The ejbName in the provider URL is the ejbName value in the ejb-jar.xml that was created as a part of the EJB session bean creation.
<?xml version="1.0" ?>
<definitions targetNamespace="http://samples.otn.com/"
xmlns:tns="http://samples.otn.com/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:format="http://schemas.xmlsoap.org/wsdl/formatbinding/"
xmlns:ejb="http://schemas.xmlsoap.org/wsdl/ejb/"
xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<!-- message declns -->
<message name="HelloWorldRequestMessage">
<part name="userName" type="xsd:string"/>
</message>
<message name="HelloWorldResponseMessage">
<part name="message" type="xsd:string"/>
</message>
<!-- port type declns -->
<portType name="HelloWorldPT">
<operation name="greetUser">
<input name="HelloWorldRequest" message="tns:HelloWorldRequestMessage"/>
<output name="HelloWorldResponse"
message="tns:HelloWorldResponseMessage"/>
</operation>
</portType>
<!-- binding declns -->
<binding name="EJBBinding" type="tns:HelloWorldPT">
<ejb:binding/>
<format:typeMapping encoding="Java" style="Java">
<format:typeMap typeName="xsd:string" formatType="java.lang.String"/>
</format:typeMapping>
<operation name="greetUser">
<ejb:operation methodName="greetUser" parameterOrder="userName"
interface="remote" returnPart="message"/>
<input name="HelloWorldRequest"/>
<output name="HelloWorldResponse"/>
</operation>
</binding>
<!-- service decln -->
<service name="HelloWorldService">
<port name="EJBPort" binding="tns:EJBBinding">
<!-- Put vendor-specific deployment information here -->
<ejb:address className="helloworldbean.HelloWorldHome"
jndiName="ejb/session/HelloWorld"
initialContextFactory="com.evermind.server.rmi.RMIInitialContextFactory"
jndiProviderURL="opmn:ormi://serverHost:opmnRequestPort:oc4jInstanceName/ejbName"/>
</port>
</service>
<plnk:partnerLinkType name="HelloWorldService">
<plnk:role name="HelloWorldServiceProvider">
<plnk:portType name="tns:HelloWorldPT"/>
</plnk:role>
</plnk:partnerLinkType>
</definitions>
- Create a partnerlink for the WSDL that you just created and an invoke activity that can be used to invoke the plnk.
- Provide the username/password for connecting to the OC4J Instance that hosts the EJB within the bpel.xml deployment descriptor. This is typically the oc4jadmin user.
<?xml version = '1.0' encoding = 'UTF-8'?>
<BPELSuitcase>
<BPELProcess id="HelloWorldBPELClient" src="HelloWorldBPELClient.bpel">
<partnerLinkBindings>
<partnerLinkBinding name="client">
<property name="wsdlLocation">HelloWorldBPELClient.wsdl</property>
</partnerLinkBinding>
<partnerLinkBinding name="HelloWorld_plt">
<property name="wsdlLocation">HelloWorldEJB.wsdl</property>
<property name="java.naming.security.principal">oc4jadmin</property>
<property name="java.naming.security.credentials">welcome1</property>
</partnerLinkBinding>
</partnerLinkBindings>
</BPELProcess>
</BPELSuitcase>
- Copy the EJB compiled classes from the EJB project created earlier into the $ORACLE_HOME/bpel/system/classes directory and restart the BPEL runtime. These classes are required for BPEL to get a hold on the home interface of the EJB to create an invoke the business method.
- Deploy the BPEL Process and see the results for yourself
The demo EJB and BPEL Client project can be downloaded from this link.