Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java...
-
Upload
lizette-halbrooks -
Category
Documents
-
view
228 -
download
0
Transcript of Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java...
![Page 1: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/1.jpg)
Faculty of Information Technology
31242/32549 Advanced Internet ProgrammingAdvanced Java Programming
Web services Intro
![Page 2: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/2.jpg)
Faculty of Information Technology
2
Web Applications
• Presentation-oriented: – PAGE based– App generates Markup pages (HTML, XHTML etc)– “Human oriented”:
• user interacts with page: Request/Response – B2C & B2C
• Service-oriented: “web services”– Service based– Application provides “Remote Procedure Calls/Remote
Methods” – “Machine oriented”:– Application interacts with Application:
• Request/Response (RPC) • Message oriented
![Page 3: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/3.jpg)
Faculty of Information Technology
3
Web Services – problems solved
• Before Web: – Traditional approach:
“Remote Procedure Calls” or “Remote Method Invocation”
– Tied to the underlying architecture– Binary message formats– Compatibility issues– Proprietary technologies and implementations– Expensive, Inflexible, Complex– Not firewall friendly
![Page 4: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/4.jpg)
Faculty of Information Technology
4
Web services – problems solved
• After Web:– Different vendors attempted HTTP based solutions– Web based RPC:
• Just send and receive plain text via a URL
– XML based RPC:• Send/receive requests as XML
XML-RPC “standard” (http://en.wikipedia.org/wiki/Xml-
rpc)– Language & technology neutral, but not a
standard Influenced standards formalised as SOAP.
![Page 5: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/5.jpg)
Faculty of Information Technology
5
Web services - definition
• “Web services are self-contained, self-describing, modular applications that can be published, located, and invoked across the web.”
• “Web service applications are encapsulated, loosely coupled web ‘components’ that can bind dynamically to each other.”
• Web Services a distributed computing platform
![Page 6: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/6.jpg)
Faculty of Information Technology
6
W3C web services standard
W3C standard for web services:
• An application (Consumer) connects to another application (Provider) via SOAP
• The Consumer knows how to connect to the Provider because the interface is described with WSDL.
• The Consumer can find the Provider because the provider’s details are published in a UDDI registry.
• Both communicate using the web protocol, HTTP.
• The data exchange is via XML and XML Schema
![Page 7: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/7.jpg)
Faculty of Information Technology
7
Web Services Introduction
![Page 8: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/8.jpg)
Faculty of Information Technology
8
SOAP
• “Simple Object Access Protocol”
• SOAP message contains:– Envelope:
describes the message and how to process it
– Header: contains the features of the SOAP message
– Body: contains the primary information for the message receiver
![Page 9: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/9.jpg)
Faculty of Information Technology
9
SOAP
• SOAP works by transmitting XML between the Consumer and Provider.
• Akin to “Snail Mail” – Envelope is like the mail address, Body is like the content of the letter
![Page 10: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/10.jpg)
Faculty of Information Technology
10
SOAP
SOAP is a XML Message format
Calls and responses are sent as SOAP Envelopes.
The message in a SOAP Envelope has a header (optional) and a body.
The Body is for application level data.Parameters, method calls etc.
The Header is for infrastructure level data.Authentication, coordination etc.Header attributes:
actor (none, next, ultimateReceiver)mustUnderstand (1 or 0)
![Page 11: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/11.jpg)
Faculty of Information Technology
11
SOAP Request Example
<?xml version="1.0"?><soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPrice>
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
getStockPrice(“IBM”)
![Page 12: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/12.jpg)
Faculty of Information Technology
12
SOAP Request Example
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPriceResponse>
<m:Price>34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body></soap:Envelope>
getStockPrice(“IBM”) 34.5
![Page 13: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/13.jpg)
Faculty of Information Technology
13
SOAP Summary
• SOAP is a simple protocol intended for transferring data from one application to another.
• SOAP provides a mechanism for encapsulating RPC calls into SOAP messages (in envelopes).
• SOAP uses existing, recognised standards to solve problems ofdata representation and transport.
Some SOAP downfalls:• No mechanisms for reliability, transactions, security…
• SOAP is, in itself, not adequate for all needs in industrial applications
• Extra standards to add missing functionality include – WS-reliable messaging,– WS-Security– WS-Coordination, WS-Transactions
![Page 14: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/14.jpg)
Faculty of Information Technology
14
WSDL
• How do you know how to invoke a web service?– SOAP only specifies the format for message exchange, it
doesn’t say what the message itself should contain!
– What is the address of the web service?– What are the required parameters?– What protocols are used?
• Web Services Description Language (WSDL) specifies the answers to these questions
![Page 15: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/15.jpg)
Faculty of Information Technology
15
WSDL Structure
Service:– collection of endpoints– endpoint = port + binding
Binding: – maps operations to protocols
(e.g. SOAP via HTTP)
Port type: – a set of operations supported
by endpoints (like a function library)
Operation: – abstract description of an
action supported by a service
Message: – typed definition of data
communication (input and output)
![Page 16: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/16.jpg)
Faculty of Information Technology
16
WSDL Elements
• <service>– Groups related ports together– eg. If a portType is bound to two protocols, they
are grouped together
• <port>– Specifies the location of the web service
![Page 17: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/17.jpg)
Faculty of Information Technology
17
WSDL Elements
<service name="CalculatorService"><port name="CalculatorPort" binding="tns:CalculatorPortBinding"><soap:address location="http://localhost:8888/calculator"/></port>
</service>
![Page 18: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/18.jpg)
Faculty of Information Technology
18
WSDL Elements
• <binding>– Specifies protocols used to invoke web service
• Eg. Is this a SOAP web service? Over HTTP?
– The abstract interface defined in <portType> can be bound to different messaging and transport protocols
• Eg. SOAP over HTTP, SOAP over SMTP, …
![Page 19: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/19.jpg)
Faculty of Information Technology
19
WSDL Elements
<binding name="CalculatorPortBinding" type="tns:Calculator">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="add"><soap:operation soapAction=""/><input>
<soap:body use="literal"/></input><output>
<soap:body use="literal"/></output>
</operation></binding>
![Page 20: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/20.jpg)
Faculty of Information Technology
20
WSDL
• <portType>– Defines the interface (similar to Java interface
definition)
• <operations>– Defines the actions (similar to Java methods)
<portType name="Calculator"><operation name="add">
<input message="tns:add"/><output message="tns:addResponse"/>
</operation></portType>
![Page 21: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/21.jpg)
Faculty of Information Technology
21
WSDL Elements
• <message>– Defines a set of parameters– Defined messages are referred to in the
<portType> element
<message name="add"><part name="parameters" element="tns:add"/>
</message><message name="addResponse">
<part name="parameters" element="tns:addResponse"/>
</message>
![Page 22: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/22.jpg)
Faculty of Information Technology
22
WSDL Elements
• <types>– Defines the data types used– Referred to by <message> elements – Usually uses XML schema to define types
![Page 23: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/23.jpg)
Faculty of Information Technology
23
WSDL Elements
<types><xs:schema targetNamespace="http://server/">
<xs:element name="add" type="tns:add"/><xs:complexType name="add"> <xs:sequence>
<xs:element name="arg0" type="xs:int"/><xs:element name="arg1" type="xs:int"/>
</xs:sequence></xs:complexType><xs:element name="addResponse“
type="tns:addResponse"/>…. & so on….
![Page 24: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/24.jpg)
Faculty of Information Technology
24
Agenda
• Introduction to Web Services
• Enabling technologies: SOAP and WSDL, UDDI
• JAX-WS
![Page 25: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/25.jpg)
Faculty of Information Technology
25
JAX-RPC
• JAX-RPC was the older standard for interfacing web services with Java
• This had several flaws – not so easy to use, mainly dealt with RPC style transactions, not built into Java
• JAX-RPC 2.0 was a refresh & got renamed to JAX-WS
![Page 26: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/26.jpg)
Faculty of Information Technology
26
JAX-WS
• Now built into Java 6
• Concept: you write POJO (Plain Old Java Objects) and annotate your code with @WebService and @WebMethod
• (next slides are from Sun Java user group, tech days 2008 (Carol McDonald))
![Page 27: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/27.jpg)
Faculty of Information Technology
27
Developing with JAX-WS
![Page 28: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/28.jpg)
Faculty of Information Technology
28
Writing service
![Page 29: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/29.jpg)
Faculty of Information Technology
29
JAX-WS mapping
![Page 30: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/30.jpg)
Faculty of Information Technology
30
Customising
![Page 31: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/31.jpg)
Faculty of Information Technology
31
Client side
![Page 32: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/32.jpg)
Faculty of Information Technology
32
Client
![Page 33: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/33.jpg)
Faculty of Information Technology
33
![Page 34: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/34.jpg)
Faculty of Information Technology
34
Labs
• We will develop both a server and client using JAX-WS in the labs
![Page 35: Faculty of Information Technology 31242/32549 Advanced Internet Programming Advanced Java Programming Web services Intro.](https://reader035.fdocuments.in/reader035/viewer/2022062219/551ad14e550346856e8b5fa4/html5/thumbnails/35.jpg)
Faculty of Information Technology
35
Questions?