Web services & BPEL

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

10 Νοε 2012 (πριν από 4 χρόνια και 5 μήνες)

191 εμφανίσεις

ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

Web Services & BPEL

Design of Distributed Software

Objectives

After this lab session you should be able to


Create a
Web Service


Create composite applications using
BPEL


Use the following technologies:
WSDL, BPEL, SOAP, Web
Service annotations,
Jax
-
WS


Web Service


A
service

is a self
-
contained software module that performs a
predetermined task


Web Services are services accessible on the
web


BPEL (Business Process Execution Language)


provides a relatively easy way to
compose

several Web
Services into new
composite services
called
business
processes


ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
2







What you should know for Exercise1


ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
3


Jax
-
WS: @WebService()

@WebService(


name="CatalogService",


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

)



This annotation makes clear that this class
is a Web Service



Default

behavior


The
targetNamespace

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
same 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




ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
4


Jax
-
WS: @WebMethod()

@WebMethod(operationName=”searchMyCatalogForSong”)

Public CDLookupOperation(String track){


return null;

}



Will declare a method in your class as being a
web method



Default

behavior


No

@WebMethod() annotations:
all public methods
exposed as web
service operations


One or more
@WebMethod() annotations: only those methods exposed as
web service operations


Relates to an
operation

in a portType in the
WSDL


Gives the WSDL operation the
same name as the java method



This annotation can off course also be
customized


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



ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
5


Jax
-
WS: @WebParam()

CDLookupOperation(

@WebParam(name="song",targetNamespace=“http://ods.intec.ugent.be/operat
ion”,header=true) String track){


return null;

}



Gives control over how the
arguments

of the methods are mapped onto
the Web Service operation



Default

behavior


Names

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
: declares that the xml of this parameter should be transmitted in the
SOAPHeader

instead of the SOAPBody. This is recommended for transmitting
metadata
.


ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
6


Invoking a Web Service

Code
generated

by
Netbeans


When creating the Web Service client: fill in the
URL

of the
WSDL

of the Web
Service


In the
methods

of your client


Right
-
click and select Web Service Client Resource


call Web Service operation


The operations of the Web Service will be shown


choose one


Netbeans generates the
skeleton code
!


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


Prepare the
input

for the operation


Write some code to process and display the
result (output)


ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
7


public static void main(String[] args) {


try {


// Call Web Service Operation


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


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


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


service.getCatalogServicePort();




// initialize WS operation arguments


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


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


java.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) {


ex.getStackTrace();


}

}


ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
8








坨慴Wy潵 獨潵汤 歮潷k景爠䕸f牣楳i′



ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
9


BPEL


BPEL stands for
Business Process Execution Language
for
Web Services



It provides a relatively easy way to
compose

several Web
Services into new
composite services
called
business
processes



The
NetBeans BPEL designer
allows you to
graphically

construct BPEL processes



On the right you will a
palette

with all the
BPEL 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


ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
10


Structure of a BPEL Process


Generally it looks something like this:


<
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
--
>


</partnerLinks>


<
variables
>


<!
--

The declaration of variables
--
>


</variables>


<
sequence
>


<!
--

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


</sequence>

</process>



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.



ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
11


Partner Links


A BPEL
-
file consists of a series of activities describing the
execution flow
of the process



Some of these activities handle the
communication

between
the process and external services


called the
external
services Partners


includes the
Web services
the BPEL process invokes


Includes the
client

that invokes the BPEL process



The Partner links define the parties that interact with the BPEL
Process


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 (input/output)


ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
12


Invoke


The invoke activity can be used to
invoke one of the partner
links
involved in the process



How to?


Drag

an invoke activity on the BPEL designer


Connect

this activity to the operation of the partner link you want to invoke


Create input and output variables
for this invoke operation


ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
13


Assign


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



How to?


Drag

an assign activity on the BPEL designer


The
BPEL Mapper
is used to copy data from one variable to another


You copy data
from left to right


In the center column you can place
operations

that perform
transformations

on the data


ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
14


Reply


Used to return the result to the client partner link



How to?


Drag

a reply activity on the BPEL designer


Connect

this activity to the operation of the client partner link


Create an output variable
for this reply activity


Use an assign activity to assign data to this output variable


ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
15


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 you’ll see that this mapping is
done using an
Xpath expression



Predicates

are used when the selection is not as trivial as the
previous examples

ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
16


Predicates and Xpath: Example


A
variable

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


ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
17


Predicates and Xpath: Example


We are interested in the value of the cell where the
name
attribute equals the string ‘unit’



To get this you must add a
predicate


Editing the predicate is similar to defining for example an IF condition


using the
mappertool


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


ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
18


Predicates and Xpath: Example


You want to select the
first row
in an array of rows


Assign in the
predicate editor
a
number literal
to the predicate


The resulting code is an
Xpath expression


According to the Xpath specification
the first element in an array of
elements has index 1
!


ODS


Introduction to Web Services and BPEL Vakgroep Informatietechnologie

p.
19