Listing 1: BPELJ insurance automated claim

1 <!- - Process attributes:
2		- expressionLanguage is Java by default. Can be overriden to,
3		say, XPath at the element level
4		- Java code embedded in process goes in to the Java package "com.mike.claim"
5 		- The BPELJ namespace is referenced below.
6 <process name="InsuranceClaim"
7	suppressJoinFailure="yes"
8	expressionLanguage="http://jcp.org/java"
9	bpelj:package="com.mike.claim"
10	targetNamespace="http://mike.com/claim"
11	xmlns:tns="mike.com/claim"
12	xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
13	xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
14	xmlns:bpelj="http://schemas.xmlsoap.org/ws/2003/03/business-process/java">
15
16	<!-- Three partner links: one a web service client interface, the others
17			Java internal stuff -->
18	<partnerLinks>
19		<partnerLink name="client" partnerLinkType="tns:Claim"
20			myRole="ClaimProvider"/>
21		<partnerLink name="claimProcessor"
22	partnerLinkType="bpelj:com.mike.claim.ClaimProcessorEJB">
23	<partnerLink name="jmsPublisher"
24		partnerLinkType="bpelj:javax.jms.TopicPublisher">
25	</partnerLinks>
26
27	<!-- Two variables, one an XML, the other Java -->
28 <variables>
29		<variable name="input" messageType="tns:ClaimsMessage"/>
30		<variable name="jmsMessage" messageType="bpelj:javax.jms.TextMessage"/>
31		<variable name="claimOK" messageType="bpelj:java.lang.Boolean "/>
32		</variables>
33
34	<sequence name="main">
3		<!-- process starts by receiving a claim through the client web service -->
36		<receive name="receiveClaim" partnerLink="client" portType="tns:Claim"
37			operation="initiate" createInstance="yes">
38		<output part="input" variable="input/>
39	</receive>
40
41		<!-- now invoke the Java claims processor as a partner link! -->
42		<invoke name="processClaim" partnerLink="claimProcessor" operation="execute">
43			<input part="input" variable="input"/>
44			<output variable="claimOK"/>
45		</invoke>
46
47		<!-- if claim is ok, publish the original input on a JMS topic -->
48		<switch name="pubIfOK">
49			<case>
50						<condition>claimOK</condition>
51						<bpelj:snippet name="createJMSMessage">
52							<!-- Use partner link topic publisher to allocate a JMS message
53								and populate it with the claim input message.
54								Note "p_jmsPublisher" is the way to reference the partner
55								link "jmsPublisher" in BPELJ -->
56						<bpelj:code>
57							jmsMessage=p_jmsPublisher.getSession( ).createTextMessage(input);
58						</bpelj:code>
59					</bpelj:snippet>
60					<invoke name="PubClaim" partnerLink="jmsPublisher" operation="publish"
61						<input part="message" variable="jmsMessage"/>
62					</invoke>
63				</case>
64				<otherwise>
65					<empty/> <!-- do nothing in this case -->
66				</otherwise>
67			</switch>
68
69		</sequence>
70	</process>

Listing 2: BPELJ sample

1 /**
2 * @bpelj:process process::
3 * <process name="MyProcess">
4 *  <variables>
5 *   <variable name="x" type="bpelj:Integer"/>
6 *  </variables>
7 *   . . .
8 *  <bpelj:snippet>
9 *   <bpelj:code>
10 *    x = self.getRandomValue ( );
11 *   </bpelj:code>
12 *  </bpelj:snippet>
13 * . . .
14 * </process>
15 **/
16 public class MyProcessImpl implements Serializable
17 {
18    Integer getRandomValue( )
19    {
20 		return new Integer(myRand.nextInt( ));
21	 }
22 }