Web Services in Eclipse
Sistemi Informativi Aziendali – A.A. 2012/2013
Outline
Apache Axis
Web Service Clients
Creating Web Services



2
Sistemi Informativi Aziendali
A.A. 2011/2012
Apache Axis
Web Services in Eclipse
WS basics (I)
Web services are described by their WSDL file
Starting from the information in the WSDL, a WS client
must:










4
Prepare call data parameters
Encapsulate them in a SOAP XML message
Send the message to the specified endpoint, using the right
encoding and protocol
Wait... (remotely)
Receive the SOAP XML response message
Decode the message and extract the response data values
Handle possible errors and exceptions, and report them to the
caller
Return the response data to the caller
Sistemi Informativi Aziendali
A.A. 2011/2012
WS basics (II)
The provider of the WS (the server side) must:










5
Publish the WSDL corresponding to its calling methods
Wait for incoming requests as SOAP XML messages
Decode the request parameters and validate their data types
Identify the called method, and invoke the right class for
handling it (business method)
Wait... (locally)
Get the response from the business method
Catch any exception and possibly create an XML exception
message
Encapsulate the response values in a SOAP XML message
Return the response message to the caller
Sistemi Informativi Aziendali
A.A. 2011/2012
Welcome, Axis
Project Axis (axis.apache.org) aims at simplifying and
automating all the above steps, as much as possible
Automatically creates Java «proxy» classes for calling web
services




You call a method on the local object
The method call is translated into a WS request/response
Helps transforming business methods into Web Services



6
Starting from a Java class, creates the WSDL and the Servlets
to handle the WS request (bottom-up creation)
Starting form a WSDL, create the servlet and Java interfaces to
handle the requests (top-down)
Sistemi Informativi Aziendali
A.A. 2011/2012
Axis architecture (client pipeline)
7
Sistemi Informativi Aziendali
A.A. 2011/2012
Axis architecture (client pipeline)
import localhost.axis.Bing_jws.*;
public class MyBingClient {
public static void main( String args[] ) throws Exception
{
BingService service = new BingServiceLocator();
Bing myBing = service.getBing();
// call instance methods on myBing, ex., say, myBing.foo()
myBing.doSomething("hello") ;
}
}
http://wiki.apache.org/ws/FrontPage/Axis/WritingYourClient
8
Sistemi Informativi Aziendali
A.A. 2011/2012
Axis architecture (server pipeline)
9
Sistemi Informativi Aziendali
A.A. 2011/2012
Axis architecture (server pipeline)
public interface BingService {
public String doSomething (String argument);
public ComplexTO retrieveResult(OtherTO value);
}
public class BingServiceImpl implemente BingService {
public String doSomething (String argument)
{ ... }
public ComplexTO retrieveResult(OtherTO value)
{ ... }
}
10
Sistemi Informativi Aziendali
A.A. 2011/2012
Web Service Clients
Web Services in Eclipse
Guided example


Remote Login Service downloadable from the course
web site
Offers 2 operations:

isValidUser



getUserData


12
Two input parameters: username and password (hashed with the
SHA1 algorithm)
One output parameter: true if the user is valid (i.e., username and
password have a corresponding entry in the db, false otherwise)
Two input parameters: username and password (hashed with the
SHA1 algorithm)
One output parameter: a UserData object representing the user data
stored in the db.
Sistemi Informativi Aziendali
A.A. 2011/2012
AuthenticationInterface WSDL (Eclipse)
13
Sistemi Informativi Aziendali
A.A. 2011/2012
Parameter data types (isValidUser)
14
Sistemi Informativi Aziendali
A.A. 2011/2012
Parameter data types (getUserData)
15
Sistemi Informativi Aziendali
A.A. 2011/2012
SOAP messages (isValidUser): request
POST /AuthenticationInterfaceImple HTTP/1.1
Host: …
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:q0="http://login.services.sistinfo.elite.polito.it"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<q0:isValidUser>
<q0:username>user1</q0:username>
<q0:passwordHash>
lkjgirhierhghrihrhoeirh
</q0:passwordHash>
</q0:isValidUser>
</soapenv:Body>
16
Sistemi Informativi Aziendali A.A. 2011/2012
</soapenv:Envelope>
SOAP messages (isValidUser): response
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<isValidUserResponse
xmlns="http://login.services.sistinfo.polito.it">
<isValidUserReturn>false</isValidUserReturn>
</isValidUserResponse>
</soapenv:Body>
</soapenv:Envelope>
17
Sistemi Informativi Aziendali
A.A. 2011/2012
SOAP messages (getUserData): request
POST /AuthenticationInterfaceImple HTTP/1.1
Host: …
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:q0="http://login.services.sistinfo.polito.it"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<q0:getUserData>
<q0:username>user1</q0:username>
<q0:passwordHash>
70153d7bc22acc55ea60ae45bf3af72b254a142c
</q0:passwordHash>
</q0:getUserData>
</soapenv:Body>
18
Sistemi Informativi Aziendali A.A. 2011/2012
</soapenv:Envelope>
SOAP messages (getUserData): response
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getUserDataResponse
xmlns="http://login.services.sistinfo.polito.it">
<getUserDataReturn>
<address>
Viale dei giusti, 32
</address>
<city>Topolinia</city>
<name>Ermenegildo</name>
<phoneNumber>
+99033786453
</phoneNumber>
<surname>Basettoni</surname>
<username>user1</username>
<zipCode>14654</zipCode>
</getUserDataReturn>
</getUserDataResponse>
</soapenv:Body>
</soapenv:Envelope>
19
Sistemi Informativi Aziendali
A.A. 2011/2012
Creating the WS client
20
Sistemi Informativi Aziendali
A.A. 2011/2012
Creation results
Axis libraries in project
21
Client proxy and methods
Sistemi Informativi Aziendali
A.A. 2011/2012
Generated classes
<<interface>>
AuthenticationInterfaceImpl
Service
implements
org.apache.axis.client.
Service
extends
AuthenticationInterfaceImplServi
ceLocator
.getAuthenticationInterfaceImpl()
User
Code
returns
org.apache.axis.client.
Stub
<<interface>>
AuthenticationInterfaceImpl
. isValidUser( username,
passwordHash)
implements
AuthenticationInterfaceImplProxy
implements
AuthenticationInterfaceImplSoap
BindingStub
Wrap calls
22
extends
Sistemi Informativi Aziendali
A.A. 2011/2012
User code example
WSDL Service
I
AuthenticationInterfaceImplServiceLocator
authImplLocator = new
C
AuthenticationInterfaceImplServiceLocator();
I
AuthenticationInterfaceImpl authImpl =
authImplLocator.getAuthenticationInterfaceImpl();
WSDL Port
valid = authImpl.isValidUser(username, pwdHash);
WSDL Operation
23
Sistemi Informativi Aziendali
A.A. 2011/2012
References



Axis Architecture Guide,
http://axis.apache.org/axis/java/architecture-guide.html
Currency Convertor Web Service,
http://www.webservicex.net/ws/wsdetails.aspx?wsid=10
JAX-RPC specification v 1.1,
http://jcp.org/en/jsr/summary?id=101
24
Sistemi Informativi Aziendali
A.A. 2011/2012
Licenza d’uso


Queste diapositive sono distribuite con licenza Creative Commons
“Attribuzione - Non commerciale - Condividi allo stesso modo 2.5
Italia (CC BY-NC-SA 2.5)”
Sei libero:



Alle seguenti condizioni:




di riprodurre, distribuire, comunicare al pubblico, esporre in pubblico,
rappresentare, eseguire e recitare quest'opera
di modificare quest'opera
Attribuzione — Devi attribuire la paternità dell'opera agli autori
originali e in modo tale da non suggerire che essi avallino te o il modo in
cui tu usi l'opera.
Non commerciale — Non puoi usare quest'opera per fini
commerciali.
Condividi allo stesso modo — Se alteri o trasformi quest'opera, o se
la usi per crearne un'altra, puoi distribuire l'opera risultante solo con una
licenza identica o equivalente a questa.
http://creativecommons.org/licenses/by-nc-sa/2.5/it/
25
Sistemi Informativi Aziendali
A.A. 2011/2012
Scarica

Web services in Eclipse - e-Lite