This article shows how one can quickly develop an SOA (Service Oriented
Architecture) application which involves Web Services and processing business
elements with Netbeans. To see this happen, let us take a simple example of an
order (of products or services) processing application. The business of order
processing would involve a couple of elements like — order number and order
status. Order number is the basic input of an order processing application. At
the very first step, it must be verified that the order number given by the
customer to the application, is valid. Sounds easy to do, right?
Step into the world of SOA. Here your application is providing services in a
B2B or B2C scenario. The order number will come from any type of application
written in any language (Java, C#, VB) and deployed on any platform (Web,
desktop, mobile). As one would know, this issue of language and platform is
popularity solved by Web services.
Next, the validation of the order number may be different for different
customers or products. For example, orders coming from customer ABC may have the
ABC prefix in the order number and so on. What can make it worse is when a third
customer comes into picture or when the format of order number changes and as a
result, processing of the business elements change. What if there is a graphical
tool that can depict and change the processing of business elements and the
required code gets generated under the hood, automatically. Last but not the
least, the processing of business elements must integrate with the input and
output provided by and through a Web service.
Netbeans 5.5 with Java EE bundle allows you to quickly create Web services
for input and output of business elements and provides a graphical tool called
BPEL (Business Process Execution Language) Mapper for their processing.
Integrating Web services with the business elements is through one single drag
and drop. The sample application that we will create now will take an order
number as input from a Web service and produce an output (true or false)
indicating whether the order number is a valid one. It will do so by checking
whether it is prefixed with ABC. This checking or validation of the order number
is done via the BPEL Mapper. Note that all this (writing a Web service and
validation) is done without writing a single line of Java code.
Install and start Netbeans
After logging in to PCQLinux 2007 desktop, issue startx to start X Window. To
install Netbeans, click on the desktop icon named 'Install Java EE 5 Tools
Bundle with Netbeans IDE'. Please note that the graphical installer may take
some time to pop up. Follow the wizard to install Netbeans.
Switch the PCQLinux 2007 desktop to Java Workstation (refer to the article
Configuring Desktop in this story) Click on Applications>PCQLinux>Netbeans 5.5.
This will start the Netbeans IDE.
While writing XML schema files is tedious, with Netbeans XML Schema Design, dragging and dropping elements does it all |
On Netbeans, click on File>New Project>Service Oriented Architecture>BPEL
Module. For Project Name, type in OrderNumberBpelModule and click on Finish. In
the right pane, right click on Process files under OrderNumberBpelModule and
select New File/Folder>XML>Xml Schema. Click on Next. For file name type in
orderNumberXmlSchema. Click on Finish. With the orderNumberXmlSchema.xsd is
highlighted on the left panel, click on the Design tab. From the palette (on the
right pane) drag and drop the 'element <>' under Elements in the Design pane (in
the middle). Rename newElement to orderNumber. Right click on orderNumber and
select Properties. For definition, click on the Ellipsis button. Under 'Built-in
Types', select String. Similarly, drag and drop another element, rename it to
'valid' and select Boolean from the 'Built-in Types'. We just finished writing a
simple XML schema for input (order number) and output (whether the order number
is valid or not). This schema will be used by the WSDL (Web Service Definition
Language) file for the Web service for our SOA application.
Netbeans allows the biz process to be integrated with a Web service by dragging and dropping a WSDL file. This is the first step and last step to integrate your biz processing with the input and output given by and given to, respectively, the outside world |
orderNumberWSDL for Web service
Right click on Process Files and select New>WSDL Document. For file name, type
in orderNumberWSDL. Check the box labeled 'Import XML Schema Files'. Click on
Browse and select src/orderNumberXmlSchema.xsd. Click on Next. In the Input
section, click on the Ellipsis button and select OrderNumberBpelModule>src/orderNumberXml
Schema.xsd >Elements>orderNumber. Similarly in the output section, select
OrderNumber BpelModule>src/orderNumberXmlSchema.xsd>Elements>valid. Click on
Next, select Document Literal and Finish.
Integrate Web service & Biz Process
Right click on Process Files and select New>BPEL Process. For file name, type in
orderNumberProcess and click on Finish. You will see a simple flow diagram in
the middle pane.
From the right palette, drag and drop 'Receive'
under Web Service between the 'Process Start' and the rectangular box. While
dropping, a circle will aid you on where to drop the 'Receive'. Once dropped,
double click on Receive. Similarly, drag and drop, 'Reply' between the
rectangular box and the 'Process End' button. Next, drag and drop the
orderNumberWSDL.wsdl from the left pane, onto the diagram. Simply click on OK on
the pop-up dialog. Double click on Receive1. For Partner Link, select
PartnerLink1 from the dropdown. Click on Create and then OK on the pop-up
dialog. Double click Receive1. For Partner Link, select PartnerLink1. Select
'Normal Response' radio button. For the Output Variable, click on Create. On the
pop up dialog, click on OK.
Use datetime, mathematical functions, etc (see icons at the top menu of the BPEL Mapper) to process business elements |
Define biz element processing
Select the rectangular box in the diagram and delete it by pressing the Delete
key. Drag an Assign (under Basic Activities) on the right pane and drop it
between Receive1 and Reply1. Right click on Assign and select 'Show BPEL Mapper'.
The BPEL Mapper will open up at the bottom. On the BPL Mapper pane, click on
String>Starts With. This will show a block with string1, string2 and 'return
boolean' in the middle pane of the BPEL Mapper. Expand
OrderNumberWSDLOperationIn1 (on the left pane of the BPEL Mapper). Drag and drop
part1 onto string1. Double click on string2 and type in ABC. With this, we have
specified that the order number, which comes from the Web service as an input,
must start with ABC.
Next expand OrderNumberWSDLOperation-Out1on the right pane. Drag and drop
'return boolean' onto part1 under OrderNumberWSDLOperationOut1. With this, we
have specified that the result of the string processing (ie, the 'starts with'
function) is sent as an output of the Web service. The operation will return
true if the order number starts with ABC else it will return false. Our BPEL
module is ready. Now we get into using this module in a J2EE SOA app.
An SOA app with BPEL module
Click on File>New Project>Service Oriented Architecture>Composite Application.
For Project Name, type in myapp and click on Finish. Under myapp (on the left
pane), right click on JBl Module and select 'Add JBl module'. Select
OrderNumberBpelModule and click on Add Project JAR Files.
Next we will need to deploy the application onto Sun Java System Application
Server which is bundled along with the Netbeans IDE. Click on Runtime tab on the
left pane. Expand Servers, right click on Sun Java System Application Server 9
and select Start.
Next, click on the Projects tab on the left pane. Right click on Myapp and
select 'Deploy Project'.
Test out your SOA app
Under Myapp, right click on Test and select New Test Case. Click on Next. For
step 2 (select the WSDl Document), expand OrderNumberBpelModule and select the
WSDL file.
Click on Next and select orderNumberWSDLOperation. Expand TestCase1 and
double click on Input. Modify the line:
to
With this, we pass ABC123 as the order number to the Web Service. Right click
on TestCase1 and click on Run. Expand TestCase1 and double click on 'Output'.
You will see a line as follows:
This means the Web service has returned a true - indicating a valid order
number. You can enter an invalid order number in the input and upon re-running
TestCase1 you will see that the test case fails because of a false value being
returned.
Last but not the least, tomorrow if you want to add a new validation to the
order number, it can be done by using the BPEL Mapper, as we did today for
validating an ABC prefix — no touching of code.