Titel Naam

braintreesmileΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 5 χρόνια και 3 μέρες)

492 εμφανίσεις









Vakgroep

Informatietechnologie


Design of Distributed Software
2008
-
2009


Lab Session I
II: Java Web Services and BPEL
-

Guidelines




Design of Distributed Software (
w
eb
site
: http://minerva.ugen
t.be,
e
-
mail: ods@atlantis.ugent.be
)

Vakgroep Informatietechnologie
-

Gaston Crommenlaan 8, bus 201, B
-

9050 Gent
-

www.intec.UGent.be






1.
Introduction


The purpose of this document is to make you familiar with the
technologies
Java Web Services and
BPEL (
Busin
ess Process Execution Language)
. This document contains tutorials

and exemplary
programs, explaining how you can create Java Web
Services and compose business processes with
them using BPEL.



2. Introduction to
Web Services


A service is a self
-
contained software module that performs a predetermined task. Web services are
services accessible on the web. They are web based applicat
ions that use open, XML
-
based standards
and transport protocols to exchange data with clients. A client communicates with a Web Se
rvice by
sending XML over HTTP.
Web services are to machines what web pages are to humans.

SOA
(Service Oriented Architectures
)
is an architectural style of building software based on services.
Services are loosely coupled so reusability is maximized.



2
.1
.

The example:
Organizing your CD collection


We will create a Web Service that gives you information about your own CD colle
ction. We can get
information about a song by inputting its name. The Web Service will return information about the CD
that features this particular song.

The information includes the tracklist, the artist and the name of the
CD.



2
.2.
Creating a Web appl
ication in NetBeans









Task 0: Create a
new Web Application in NetBeans

1.

Click File


new⁰牯 散t



S敬散琠瑨攠W敢⁣慴a杯ry



Select “Web Applic
ation” project
=

=
Click “Next”
=

=
mr潪散琠乡t攺ejyC䑃慴慬潧
=

=
䍬ick=
“Next” and
“Finish”
=





Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


2
/
20





2.3
.
A WSDL Document


WSDL (Web Services Description Language) is an XML
-
based language for describing Web services.
A WSDL document (.wsdl) specifies the locations of the service, its operations, and the messages that
are exch
anged
.

A WSDL document can define one or

more related services.
The following elements
are used in the definition of a service:




Types:
a container for data type definitions using some type system (such as XSD).



Message:

an abstract, typed definition of th
e data being communicated.



Operation:

an abstract description of an action supported by the service.



Port Type:
an abstract set of operations supported by one or more endpoints.



Binding:

a concrete protocol and data format specification for a particular po
rt type.



Port:

a single endpoint defined as a combination of a binding and a network address.



Service:

a collection of related endpoints.

We will now go into more details about these different elements.


2.3
.
1.

Types


Types provide

data type definitions us
ed to describe the messages exchanged
. An example can be
seen below. Here the CD type is defined. A CD consists of an artist, a title and a collection of tracks.


<definitions targetNamespace="http://mycdcatalog" name="CDCatalogServiceService">


<types>


<xsd:schema xmlns:xsd=
http://www.w3.org
/2001/XMLSchema


targetNamespace=
http://ods.intec.ugent.be/pract/ws/schema/CD


xmlns:tns=
http://ods.
intec.ugent.be/pract/ws/schema/CD


elementFormDefault="qualified">


<xsd:element name="CD" type="tns:CDType"/>


<xsd:complexType name="CDType">


<xsd:sequence>


<xsd:element name="
Artist
" type="xsd:string"/>


<xsd:element name="
Title
" type="xsd:string"/>


<xsd:element name="
TrackList
">


<xsd:complexType>


<xsd:sequence>



<xsd:element ref="tns:
Track
" maxOccurs="unbounded"/>


</xsd:sequence>


</xsd:complexType>


</xsd:element>


</xsd:sequence>


</xsd:complexType>


<xsd:element name="Track" type="xsd:string" />


</xsd:schema>


</types>

Task 1: Create a Java Class that represents the same data structure

1.

Right Click your Web Application and select new Java Class

2.

Enter Class Name: CD and
p
rovide a package name
: src

3.

Click Finish

4.

Edit the class so it looks like the code below






Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


3
/
20





public class CD {




private String artist;


private String title;


private A
rrayList<String> trackList;



public CD(String artist, String title, ArrayList<String> trackList){


this.artist = artist;


this.title = title;


this.trackList = trackList;


}



Public CD(){}
//needed to be used in a Web Servi
ce message




public String getArtist(){…}


public void setArtist(String artist) {…}


public String getTitle(){…}


public void setTitle(String title) {…}


public ArrayList<String> getTrackList(){…}


public void setTrackList(ArrayList<S
tring> trackList) {…}

}


2.3
.
2
.

Messages


SOAP (Simple Object Access Protocol) is a simple XML
-
based protocol to let applications exchange
information over HTTP.

SOAP is used to transfer messages from one endpoint to another over HTTP. It is a way to pac
kage the
messages. A SOAP message consists of a SOAP
-
Envelope. An envelope has 2 parts: a SOAP
-
Header
and a SOAP
-
Body. The soap header can contain metadata and the body contains the actual xml
message.


A message consists of one or more logical parts. Each

part is associated with a type from the XSD.



Element:

refers to an XSD element using a QName



Type:

refers to an XSD simpleType or complexType using a QName



2.3
.
3
.

Port Types


A port type is a named set of abstract operations and the abstract message

involved.

An example of a
Request
-
Response message can be seen below.

<message name="CDLookupOperationRequest">


<part name="part1" element="ns:
Track
"/>

</message>

<message name="CDLookupOperationReply">


<part name="part1" eleme
nt="ns:
CD
"/>

</message>


<portType name="CatalogServicePortType">


<operation name="CDLookupOperation">


<input name="input1" message="tns:CDLookupOperationRequest "/>


<output name="output1" message="tns: CDLookupOperation
Reply "/>


</operation>


</portType>





Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


4
/
20







Four types of operations are possible:



One
-
way:

The endpoint receives a message.



Request
-
response:

the endpoint receives a message, and sends a correlated message.



Solicit
-
response:

T
he endpoint sends a message and receives a correlated message.



Notification:

The endpoint sends a message.


public class MyCDCatalogService {


public MyCDCatalogService() {}



public CD CDLookupOperat
i
on(String track){return null;}

}


2.3
.
4
.

Bindi
ngs


A binding defines message format and protocol details for operations and messages defined by a
particular portType.

Recommended reading:
http://www.ibm.com/developerwork
s/webservices/library/ws
-
whichwsdl/


2.3
.
5.

Service


A port defines an individual endpoint by specifying a single address for a binding.

A service groups a set of related ports together.


Task
2
:
Create a Java Class with one operation similar to the operation defined in the above
example. We will expose this class later as a Web Service.

1.

Right Click your Web Application and select new Java Cla
ss

2.

Enter Class Name: MyCDCatalogService

and p
rovide a package name
: src

3.

Click Finish

4.

Add an empty operation with the correct arguments and return type

as indicated in the
code below. The empty constructor is required if we want to expose this class as a We
b
Service later.


<binding name="CatalogServiceBinding" type="tns:CatalogServicePortType">


<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>


<operation name="CDLookupOperation">


<soap:operatio
n/>


<input name="input1">


<soap:body use="literal"/>


</input>


<output name="output1">


<soap:body use="literal"/>


</output>


</operation>


</binding>





Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


5
/
20






2
.4
.
Web Service Development


2
.4
.
1.

Code Generation


A lot of to
ols exist to generate code for you so the complexity of Web service invocation is hidden for
the developer.
A lot is done for you:




Wsgen
: generates portable artifacts from a service implementation class needed for web
service invocation and web service de
ployment



Wsimport
: generated portable artifacts from a WSDL

These are tasks that can be invoked from CLI, but Net
B
eans takes care of them for you. These tools
can also be invoked by the application server upon deployment.


2.4
.
2.

Contract First vs. Contrac
t Last


There are two ways to start creating web services: Contract First and Contract Last. When 2 business
partners come together and want to exchange data they need to agree on an interface to do that.
Writing a WSDL file is doing exactly that. When the

WSDL exists the service provider can go to work to
implement the service and in parallel the service consumer can start implementing his client side
application. This procedure is called
Contract First

development and has its analogy in the Object
Oriente
d world with API programming. You program against an API not knowing the implementation
behind it. To generated code from the
WSDL

the
wsimport

command is used.

With
Contract Last

development we first implement our Service Endpoint Interface (SEI) and
gene
rated the
WSDL

from that

using
w
sgen
. Parallel implementation of client side and server side is
harder this way, since the client side will need the
WSDL

anyhow to generate the stubs to invoke the
web service.

Contract First method is recommended on long r
unning project with multiple development partners.
Contract Last method is good enough when you have the freedom to determine the

interface of your
web service.
In this session we will go for the Contract Last method.


2.5
.
Jax
-
WS: Java
TM

API for XML
-
based

Web Services


Jax
-
WS is an API for building web services and clients.

What can it do for you?



Easy development of web services with extensive support for customizations using annotations



Takes care of complexities of invoking a web service. The use of web

services is completely
transparent for the consumer.



Automatically does marshalling/unmarshalling of the XML messages to Java object and vice
versa using JAXB 2.0

2.
6.

Jax
-
WS

annotations


2.6.1. @WebService()



<service nam
e="CatalogServiceService">


<port name="CatalogServicePort" binding="tns:CatalogServiceBinding">


<soap:address location="http://dummylocation.com"/>


</port>


</service>

</definitions>





Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


6
/
20





We will first make a web service out of the
“MyCDCatalogService” class. This means that we will create
a web service with all public methods of the class exposed as web service operations.






Your web service is now ready to be tested.




IF the Web Service is tested with the song title “Believ
e”, the following messages can be viewed:



Task
3
:

Add the @WebService() annotation
to transform the class into a Web Service.

1.

Type @WebService() just before the class keyword

2.

Press Ctrl+S to save your file

3.

Netbeans immediately recognizes the class to be a web service and adds it to a new node
in the project tree

as can be seen in the fig
ure below

Task
4
:

Test the Web Service

1.

In Netbeans right
-
click the
MyCDCatalog project

in the Project Navigator

2.

Click
Undeploy and
Deploy (this may take a few seconds)

3.

Right
-
c
lick
the Web Service in the Project Navigator and select
test web service

4.

A Web
page will pop open which allows you to test the Web Service.

5.

Take a look at the soap messages that went over the wire





Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


7
/
20







To understand the default behaviour of
the @WebService()
annotation it’s a good idea to study the
resulting WSDL file.


The WSDL file is the combination of the
code
snippets we have seen in section 2.3. Also
note that:



The targetNamespace

(
=
http://src/
)

for the generated WSDL definition is generated from the
package name
.



The name of the PortType corresponds to the name of your class
-
file



The operation name in the portType has the sam
e name as the method in your class.



All public methods in your class are now available in the web service

The @WebService() annotation can also be customized:



Name
: Change the name of the PortType



targetNamespace
:
Change the targetNamespace


2.6.2. @WebMethod()


This annotation will declare a method in your class as being a web method. If no
@
WebMethod
()

annotat
ions are mentioned in the class then all public methods will be exposed as web services. If one
or more
@
WebMethod
()

annotations are declared, only the method
with such an annotation will be
exposed as web service operations.

A @WebMethod
()

annotation insi
de a class with a @WebService
()

annotation in Java world relates to an operation in a portType in WSDL world.


The default behaviour of the @WebMethod() annotation is to give the WSDL operation the same name
as the java method. This annotation can off cour
se also be customized:



operation
Name
: Change the name of
the operation in the portType.

@WebService(



name="CatalogService",


targetNamespace=”
http://ods.intec.ugent.be/catalog


)

@WebMethod(operationName=”searchMyCatalogForSong”)

Public CDLookupOperation(String track){


return null;

}

Task
5
:

Take a look at the generated WSDL file

1.

In the
services

tab, right
-
click the
GlassFish V2

node and select View Admin Console

2.

Log i
n using the default username and password (admin/adminadmin)

3.

Navigate to the Web Service
s

node in the tree on the left

4.

Select your web service

(MyCDCatalogService)

5.

Click on the
“View WSDL” link to view the WSDL file
=
Task
6
:

Customize the @WebService() ann
otation

1.

Customize the @WebService() annotation in the MyCDCatalogService class to reflect the
above example

2.

Deploy the Web Service again

3.

Take a look at the newly generated WSDL file

4.

Note that the name of the PortType and the targetNamespace have changed





Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


8
/
20









2.6.3. @WebParam()


With this annotation you have so
me control over how the arguments of the the methods are mapped
onto the Web Service operation.


The default behaviour of the @WebParam() annotation is:



The default names chosen for the parameters is the WSDL file are arg0, arg1,…



The namespace where these

parameters are defined is also derived from the package name of
the class file.

This annotation can off course also be customized:



Name
: the name of the parameter



targetNamespace
: the namespace the parameter will be defined in



Header
: this can be used to

declare that the xml of this parameter should be transmitted in the
SOAPHeader instead of the SOAPBody. This is recommended for transmitting metadata.










CDLookupOperation(

@WebParam(name="song",targetNamespace=
http://ods.intec.ugent.be/operation
,


header=true
)

String track){


return null;

}

T
ask
7
:

Add the @WebMethod() annotation to the CDLookUpOperation

1.

Add the @WebMethod() annotation above the CDLookOperation in the
MyCDCatalogService class

2.

Customize the annotation as indicated in the above example.

3.

Deploy the Web Service again

4.

Take a look
at the newly generated WSDL file

5.

Note that the name of the
operation in the portType has changed

Task
8
:

Add the @WebParam() annotation to the track parameter of the CDLookupOperation

1.

Add the @Web
Param
() annotation
before the track parameter of the CDLook
upOperation
in the

MyCDCatalogService class

2.

Customize the annotation as indicated in the above example

3.

Deploy the Web Service again

4.

Test the Web Service. Notice that there is an extra parameter now. This parameter can be
used to indicate the medadata that

has to be added to the header

5.

Take a look at the SOAP messages that went over the wire

6.

Note that the name
of the parameter and the targetNamespace has changed





Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


9
/
20







2.
7.

Calling the Web Service from a client


The Resulting code:

public static void main(String[] args) {


try {


// Call Web Service O
peration


be.ugent.intec.ods.catalog.MyCDCatalogServiceService service = new


be.ugent.intec.ods.catalog.MyCDCatalogServiceService();


be.ugent.intec.ods.catalog.CatalogService port =



service.getCatalogServicePort();



Task
9
:

Write a standalone Java Application to invoke and test this application

1.

Create new Java

Application project

called CDCatalogClient

2.

Right click the project node and select new


web service client

3.

Select the WSDL URL radio button and fill in the URL to the WSDL. (see task 5 to find
that URL)

4.

C
lick finish

5.

Right click in your main method and se
lect Web Service Client Resource


call Web
Service operation

6.

Select the operation you want to execute

(it might take a while until it appears)

7.

Netbeans generates some skeleton code you that’s almost ready to execute

8.

The method on the port object executes
the web service operation for you and hides all
its complexity.

9.

Prepare the input for the operation

10.

Write some code to properly display the result





Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


10
/
20
















3.
Introduction to BPEL



BPEL stands for Busin
ess Process Execution Language for Web Services. It provides a relatively eas
y
way to compose several Web Services into new composite service
s

called business processes.


3.1
.

The example: Displaying famous movie quotations


The process we will create during this tutorial is a simple process that is able to display a famous quote
f
rom a certain movie.
The goal of the process is to fetch a quotation from a given movie title and format
it as follows:


Gunnery Sergeant Hartman


“You're so ugly you could be a modern art masterpiece.”


Thi
s
quote is
of course from the legenda
ry movie “
Full Metal Jacket”.

An external Web Service, which has a small proof
-
of
-
concept database with quotations, is deployed on
an application server on the network. This service accepts a movie title and returns the quotation in
XML form using 2 elements: name
and quote. The WSDL of this service can be found at:


h
ttp://chaos164.test.atlantis.ugent.be
:
8080
/QuotationRespository/Quotations
RepositoryService?
wsdl


The possible movie titles are
:




The Untouchables



Scarface



Allo Allo



Holy Grail



Full Metal Jacket


// initialize WS operation arguments


be.ugent.intec.ods.catalog.SearchMyCatalogForSong parameters = new


be.ugent.intec.ods.catalog.SearchMyCatalogForSong();


ja
va.lang.String song = "Believe";




// process result


be.ugent.intec.ods.catalog.SearchMyCatalogForSongResponse result =


port.searchMyCatalogForSong(parameters, song);


System.out.println("Result

= "+result);




} catch (Exception ex) {


System.err.println(ex);


ex.getStackTrace();


}

}





Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


11
/
20






The f
ormatting of the quotation will be done using a BPEL activity.



3.2. Creating a Business Process in NetBeans



The Net
Beans BPEL designer will open, which allows you to graphically construct
BPEL processes
.
On
the right you will a palette with all the BP
EL Activities you can use to construct the process. A BPEL file
is an XML file and you can take a look at the XML source by clicking on the Source button in the BPEL
Designer.


3.3. The structure of a BPEL Process


Generally a BPEL Process will look
somet
hing
like this:


The Process element is the root of
the process. Here you can name
the process and declare prefixes
for namespaces used in the process definition.


3.3
.
1.

Partner Links


A BPEL
-
file consists of a series of activities describing the executio
n flow of the process. Some of these
activities handle the communication between the process and external services that need to be called
from the process. We call these external services Partners.



The Partner links define the parties that interact with
the BPEL Process. Each PartnerLink is linked to a
PartnerLinkType which is defined in the WSDL of the partner service.
Partner link types represent the
interaction between a BPEL Process and the involved parties, which include the Web services the
Task 0: Create a Business Process

1.

Create new Project (Categories: Service Oriented Architecture

(SOA)
, BPEL
Module)

2.

Name the project: QuotationProcess, click Finish

3.

Right click the QuotationProcess/Process files folder, and select new BPEL Process

4.

Name it “QuotationProcess”, click finish
=

<process


name="QuotationProcess"


targetNamespace=
http://enterprise.netbeans.org/bpel/


QuotationProcess/QuotationProcess


xmlns=
http://docs.oasis
-
open.org/wsbpel/2.0/process/executable


xmlns:xsd=
http://www.w3.org/2001/XMLSchema


xmlns:tns=
http://enterprise.netbeans.org/bpel/QuotationProcess/


QuotationProcess
>



<partnerLinks>


<!
--

The declaration of partner links
--
>


</p
artnerLinks>


<variables>


<!
--

The declaration of variables
--
>


</variables>


<sequence>


<!
--

The definition of the BPEL business process main body
--
>


</sequence>

</process>





Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


12
/
20





BPEL pro
cess invokes and the client that invokes the BPEL process.
There are two partner links in this
process. One is of

course the client, and the other is
the external
QuotationsRepositoryService
.



Each partner link type can have one or two roles
:



myRole: the
role of the business process



partnerRole: the role of the partner

For

each role we must specify the portType it uses. For synchronous operations, there is a single role
for each partner link type because the operation is only invoked in a single direction.

For asynchronous
call back operations, you have to specify two roles. The first role describes the invocation of the
operation by the client. The second role describes the invocation of a call back operation.


We will now create the client Partner Link. W
e need to create a WSDL file that represents the interface
of to this business process
.
This WSDL file is very simple. It takes a string as its input (the title of the
movie) and it returns a string (the formatted quotation).
This illustrated the contract
first manner of
creating a Web Service.









Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


13
/
20






Now we have a WSDL file that can be invoked by the client. This WSDL file has to be bound to the
BPEL Process by creating a partnerLink in the BPEL and let it create a process instance when the
WSDL is invo
ked.



Task 1: Create the
WSDL file

1.

Right click the QuotationProc
ess/Process files folder, and select new WSDL Document

2.

Name it “QuotationWSDL”, click next
=

=
䍨散k
=
if=扯瑨tt桥=in灵琠慮d=潵t灵琠潦=瑨t=潰敲慴a潮=co湳is瑳=潦=愠sin杬攠s瑲in朮g
t攠桡ve=
瑯t mak攠愠r敱略st
J
r敳灯湳攠潰敲慴i潮=慳=睥w睡湴=瑯=杩ve=扯瑨t in灵t=E瑨t=m潶i
攠瑩瑬攩=
慮搠 g整e a= r敳畬琠 Et桥= qu潴oF.
v潵= ca渠 c畳瑯tiz攠 t桥= 湡m敳= 潦= 瑨t= 潰敲慴eo渠 慮d=
i湰畴uo畴uu琠t敳s慧攠e慲瑳爠畳攠eh攠e敦慵l瑳.
=
Click⁎數琮
=
=
=
=

=
Make sure “RPC Literal” WSDL
J
styl攠is⁣桥ck敤
=

=
䍬ick⁆楮ish
=

Task
2
: Create the
client Partner Link

1.

Drag
and the drop the WSDL file from the Process Files directory to the BPEL Designer

(orange circles on the left and right of the process)
.

2.

A box will appear. Name the partnerLink “client”
Ⱐ敩瑨敲eby=摯畢l攠clicki湧=瑨t=b潸=潲oby=
s敬散瑩湧⁴桥⁥摩t⁢=t瑯t.


3.

Cl
ick OK

4.

Drag and drop a Receive activity from the palette to the orange circle that appears
in
between the start en the end node of the process.

5.

Select the Receive node from the sequence and then drag the envelope to the operation
of the partnerLink
(e.g. g
etquote)
you added in the first part of this task.






Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


14
/
20






The resulting BPEL Process should look something like this:


3.3.2. Variables


Variables in BPEL processes are used to store, reformat, and transform messages. You usually need a
variable for every message sent to the partners and received from
them.


Now we have a BPEL process that can be invoked using a WSDL and where the input string of the
operation invoked will be stored in a variable called “movietitle”.

Task
3
:
Create a variable to store the input message

1.

Select the receive node and click the edit button that appears above it.

2.

Rename the Receive node from “Receive1” to “Start”

3.

In the dialog box click t
he create button to create a variable that will represent
the input received from the client.

4.

Name the variable “movietitle”









Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


15
/
20





3.4. The Business Logic

(the sequence element)


Every business process has a root sequ
ence which can hold the business logic of the process. In the
following tasks we will implement the business logic by means of invoking an external service and
transforming the output to a single string which then
will be returned to the client.


Business

logic can be grouped logically in sequences and scopes.

The sequence activity is an activity that does nothing more than grouping related activities together for
readability. Sequences can be nested.

A scope is a special kind of sequence where you can def
ine partnerlinks and variables that are only
visible from within the scope.


3.4.1. Invoke


The invoke
activity can be used to invoke one of the partnerLinks involved in this process.

In the
following task w
e
will

create

a process that can take a movie ti
tle as its input and store it in a variable
called “movietitle”. Then we have an activity that has the ability to invoke an external service using an
input variable “GetQuotationInput” that CAN hold a movie title and returns a quotation in a variable
calle
d “GetQuotationOutput”.


3.4.2. Assign


An assign activity is an activity that can be used to assign data to a variable. This data can be copied
from another variable or be the result of a series of XPath expressions.

In our example we need an assign state
ment because the movie title that has been received in the start
node needs to be copied to the variable that will be used as input for the invoke activity.






Task 4: Invoke the QuotationsR
epository
Service.

1.

Use your favorite browser and go to

http://chaos164.test.atlantis.ugent.be
:8080
/QuotationRespository/

Quotations
RepositoryService?wsdl

2.

Save the WSDL file in QuotationProcess/src folder as
QuotationsRepositoryService.wsdl

or

Click right on the project > New > Other (in the XML category choose External
WSDL Document(s) and fill
in the location (see 1.) and click finish.

3.

In Netbeans drag and drop this WSDL to the BPEL Designer to create a new
partnerLink. Name this PartnerLink QuotationsRepository.

4.

Take a look at the other settings in this dialog box.
A new PartnerLinkType will
be

created in the WSDL file of the partner service since there is not yet one
defined. Leave all options as they are and click OK.

5.

Drag an Invoke activity from the Palette to the BPEL Designer and drop it after
the start node already available.

6.

Select the en
velope on the Invoke node and drag it to the GetQuotation
operation on the newly created partnerlink.

7.

Select the Invoke node and click the edit button that appears above it.

8.

Create both input and output variable for this invocation. Name the input variable

“GetQuotationInput” and name the output variable “GetQuotationOutput”.

9.

Rename the Invoke node from “Invoke1” to “InvokeQuotationRepository”

10.

Click OK






Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


16
/
20






The mapping should look something like this:




Now the service will be invoked and it wi
ll return a result stored in the GetQuotationsOutput variable.
You can click the source view in the BPEL Designer to see how the process code really looks like.



3.4.3. Reply


The next step of course is to return the result to the client.






Task
5
:
Prepare the invocation

1.

Drag an Assign activity from the Palette to the orange circle between the

start and
the invoke node.

2.

When the Assign activity is selected Netbeans will open a BPEL mapper (or you
can select the mapper tab at the top of the BPEL screen). The BPEL Mapper is a
visual tool to construct the Assign statements of your BPEL process. Yo
u copy
data from left to right. By dragging and dropping you can copy data from its
source to its destination. In the center column you can place operations which
have handles for both input and output.

3.

For this assign activity we need to copy the data fro
m movietitle/movietitle to
GetQuotationsInput/parameters/movietitle. We can do this by expanding the
source and destination nodes and drag and drop the source to the destination.


Task
6
:
Reply

4.

Drag a Reply activity from the Palette to the orange circle a
fter the invoke activity.

5.

Drag and drop the envelope on the Reply activity to the client partnerlink

6.

Click the edit button to create an output variable named

QuotationWSDLOperationOut1


7.

click OK






Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


17
/
20





No value

has been assigned to this variable yet. So we need another Assign activity to handle this.


The mapping should look something like this:



The complete BPEL should look something like this:

Task
7
:
Prepare the reply

1.

Drag an Assign activity from the

Palette to the orange circle before the Reply
activity.

2.

Go to the BPEL Mapper and select “String” on top the screen. Select “Concat”
and drag the operation to the middle screen.

3.

Select “String” again. Select “String literal” and drag the operation to the
middle of
the screen in front of the Concat operation. Change the literal to “
-
“.

4.

Connect GetQuotationOutput/parameters/return/name to the first String of the
Concat operation.

5.

Connect the String literal “
-

“ to the second String of the Concat operation.

6.

Connect GetQuotationOutput/parameters/return/quotation to the third String of
the Concat operation.

7.

Connect the result of the Concat operation to

QuotationWSDLOperationOut1
/quote






Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


18
/
20





3.5. Deploy and test the process


A business process on the Su
n Application Server can not be deployed standalone but must be part of
a composite application.
In the following task such an application will be created.


Note
:

if you get the following error:

Failed execution of Deploy: /home/.../QuotationsCASA/dist/Quo
tationsCASA.zip

ERROR: (JBIMA1407) Required component sun
-
bpel
-
engine is not installed on target server.

It means that your GlassFish V2 server hasn’t got all the updates yet to deploy a SOA.

Go to the services tab and right click on the GlassFish V2 serv
er. Select view update center.
Go to the available software tab and select “Composite Applications”. Some other packages
will be automatically selected for you. Install these packages and restart the server. If you
deploy your CASA now, everything should w
ork.


We will now test the application:

























Task
8
:
Create a composite application

1.

Create New Project, select category

Service Oriented Architecture and select
Composite Application. Click Next

2.

Name the Project “QuotationsCASA”. (CASA stands for Composite Application
Service Assembly)

3.

Click Finish

4.

Right click the QuotationsCASA project node and select “Add JBI Module” and

select the QuotationsProcess BPEL Module in the file browser.

5.

Right click the CASA and deploy the Assembly on your own AS instance
(Glassfish V2).






Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


19
/
20






4.0 Appendix
Note: more complex assign statements using Predicates and
Xpath


The mapper tool can easily be used to provide mappings between source and target variables. When
you look at the

source view in the above example you’ll see that the selection of the source is done
using an Xpath expression.

Predicates are used when the selection is not as trivial as in the example above.

Take a look at the following example:


Task
9
:
Testing the composite application

1.

Select the CASA in the Project Navigator

2.

Right click the Test fo
lder and select New Test Case

3.

Give it a name (e.g. TestCase1) and click next

4.

Select the QuotationWSDL.wsdl file under the QuotationProcess tree node.

5.

Click next

6.

Select QuotationWSDLOperation (getQuote)

7.

Click finish

8.

Expand the testCase and open the Input no
de. You will see the xml that will be
send to the process.

9.

Replace ?string? by Holy Grail


<soapenv:Envelope
xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchem
a
-
instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:quot="http://j2ee.netbeans.org/wsdl/QuotationWSDL">


<soapenv:Body>


<quot:getQuote>


<movieTitle>Holy Grail</movi
eTitle>


</quot:getQuote>


</soapenv:Body>

</soapenv:Envelope>


10.

Right click the testcase and click run






Design of Distributed Software 2008
-
2009


Lab Session

III: Java Web Se
rvices and BPEL


20
/
20





Here we see a variabl
e named “parameters”. This variable is defined in XMLSchema to represent a
table. It exists of a collection of rows (maxOccurs=”unbounded”) with each row
an unbounded number
of cells.

In the first case we are interested in the value of the cell where the
name attribute equals the string
‘unit’.

To get this you must click the cell (since this is the element you want to select) and select ‘Add
predicate
’. Editing the predicate is simi
lar to defining for example an IF condition.

You can see in the
screenshot
below that the focus is set to a cell, and a filter on those cells is defined using a predicate.



A second example of using predicates is also shown in the first screenshot of this paragraph. The case
is simple: you want to select the first row in an arr
ay of rows.

The only thing you have to do is to assign in the predicate editor a number literal to the predicate. Mind
that the resulting code is an Xpath expression and that according to the Xpath specification the first
element in
an

array of elements ha
s index 1!


Be sure to take a regular look at the source view to fully understand what the Netbeans editor does for
you and to learn how a BPEL file is constructed!