Web Service Workshop

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 16

Web Services

http://javapostsforlearning.blogspot.in/2013/03/web-
service-tutorial.html
Agenda:
# !" vs !eb applications
# #ntroduction to !"
# #ntroduction to "$A%& !"'(& )''#
# *A+-!" ,ello !orld %rogram: glassfish
# *A+-!" ,ello !orld %rogram:tomcat
# *A+-!" annotation in depth
# )nderstanding !"'(
# )nderstanding "$A%
#)sing "$A% )#
###########################################
###########################################
######
Web application vs WS
-. ,ow !" is different than other web
applications /
2 t0pe of !eb applications:
%resenation-oriented:
--. A presentation-oriented web application
generates interactive web pages
--. containing various t0pes of mar1up
language 2,34(& +4( etc.5 and d0namic content in
response to re6uests.
"ervice-oriented:
--. A service-oriented web application
implements the endpoint of a web service.
Presentation-oriented applications are
often clients
of service-oriented web applications.
###########################################
###########################################
######
Introduction to WS
!hat is !"/
--. !eb services are !eb-based enterprise
applications that use open& +4(-based standards and
transport
protocols to e7change data with calling
clients
--. "$A
--. 'ifferent "$A based tech grown over the
0ear in the industr0
8$9:A& '8$4& 94#& ;*:& 9;4$3#<=
!h0 !"/
"ome feature of !"
--. have <o )#
--.#nteracts with applications 24 to 45
--. !or1s with an0 browser client
Application area !"
--. 'ata providers: e.g.& a service
providing stoc1 6uotes
--. : to : process integration: e.g.&
purchase orders
--. ;nterprise application integration ;A#
-.'ifferent applications wor1 together
simpl0 b0 adding a webservice wrapper
Arch of !"
30pe of !"
--. "$A% based
--. 9;"3>)( !"
###########################################
###########################################
#####
Introduction to SOAP, WSDL, UDDI
3hree 1e0 components of "$A% based !"
==> UDDI (Universal Description, Discovery
and Integration)
==>WSDL (Web Services Description Language)
==>SOA (Si!ple Ob"ect Access rotocol)
,ow does !" !or1s
WSDL
8onsumer --------. #nterfce-----------
.#mplemetation
--.(ets sa0 i have a ws & how i share details of
its to customer/
,ow to provide an interface 2contract5 to the
consumer and that language independent too?
--.>ormat that is understood b0 all the client
irrespective of technologies/
--. !e need +4( doc that is called !"'(
--. !"'( contain information about what is the
method & arguments and return t0pe etc.
--. 3ools generate it
--. A !"'( document is a set of definations
with a single root element&"ervice can be defined
using following elements:
!"'( describing the following:
--. !hat a service does
- the methods that the service provides
--.,ow a service is accessed
- details of the data formats and
--.protocols necessar0 to access a service
operations
--/ !here a service is located/
- details of the protocol specific networ1
address& such as a )9(
"$A% messages
--. ,ow to pass java "tring to 8@@
application A e7change of data/7ml formate
--. !hat 8@@ app does with java seriliBed
data/
--.+4( protocol that all to transmit data b/w
client and service provider
basic idea how "$A% !or1/
--. "$A% wor1s same as
marshling/unmarshling in 94#
!ho does the conversion A form *ava object to
"$A% objects/
--.8onversion is done b0 ";# 2"ervice end
point interface5
--.3ranslate whole ws call to "$A% A so
that other side can understand it
--. ";# is specific to appliction to client sideA
we need seperate ";# to handle 8@@ client
--. tools gernate itA wsimport
--. it translate java call to ws call ?
*A+-9%8 vs *A+-!"
--. *A+-!" is annotation based
--.*A+-9%8 is older st0le
###########################################
###########################################
#####
JA-WS !ello World Pro"ra#
*ava A%# for +4( !eb "ervices 2*A+-!"5
*A+-!"
--. specification 2*"9 22C5 provided b0 "un
which consists
of a set of A%# used for creating !eb
"ervices
--. *A+-!"& is divided into 2 parts:
3he >irst part
-. 8onsists of an A%# 2*"9 5 provided
b0 ")<.
-. 3he A%# consists of a set of
interfaces& annotations&
7ml files and abstract classes
2sometimes ma0be a few base classes5
which are to be used when using that
featureD
3he "econd part
-. is the implementation.
4ultiple reference implementations b0 different
vendors:
--."un 2*'E 1.F5
--.Apache 28+>& A+#" 25
--.#:4 2!eb sphere5
--.$9A8(; 2!eblogic App "erver5
--.=lassfish 24etro5.
!eb service design approaches
--. 8ontract last or :ottom up approach
--.!rite implementation first
--. then generate !"'(
--. 8ontract first or 3op 'own Approach
--. !rite !"'( 28ontract5 first
--. 'efine and fi7 the contract and
then write the implementation
"teps to create *ava :ottom up approach
1. 8reate an implementation class that
annotate with G!eb"ervice annotation
2. Annotate the methods to be e7posed with
G!eb4ethod annotation
3. =enerate !"'(& +"' and :inding
classes using wsgen functionalit0 2glassfish5
C. 'eplo0 the service on server 2=lassfish5
H. =et !"'(
F. 3est service using ;clipse !eb "ervice
;7plorer
I. 8alling !" from an client %rogram
'emo !" using *A+-!"
1. 8reating !eb "ervice ;ndpointA and deplo0 on
glassfish
pac1age sampleA
import java7.jws.!eb"erviceA
G!eb"ervice
public class 8alculator
J
public int sum2int param1& int param25
J
return param1 @ param2A
K

public int multipl02int param1& int
param25
J
return param1 L param2A
K
K
http://localhost:M0M0/'emo!":$A/8alculator"ervice
2. 8reating !" client
)se wsimport
--. 3he wsimport command-line tool
processes an e7isting file and generates
the re6uired portable support classes for
developing *A+-!" web service applications.
--.;ssentiall0& it is going to automaticall0
generate all of the class files involved with the "$A%&
+4( and communication aspects of our
web service?
<ow from scr issue:
wsimport -1eep
http://localhost:M0M0/,ello!orld!"/8alculator"ervice
/wsdl
it will generate re6uired
classess..................
<ow 8reate clinent of !"
pac1age sampleA
public class 8alculator8lient J
public static void main2"tringNO args5 J
8alculator"ervice service - new
8alculator"ervice25A
//create pro70
8alculator pro70 -
service.get8alculator%ort25A
//invo1e
"0stem.out.println2P"um of the arguments -
P @ pro70.sum22&355A
"0stem.out.println2P4ultiple of the
arguments - P @ pro70.multipl02I&255A
K
K

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy