Ntg web services
-
Upload
farag-zakaria -
Category
Technology
-
view
447 -
download
3
Transcript of Ntg web services
![Page 1: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/1.jpg)
Web ServicesFarag Zakaria
ITI-JAVA 30
![Page 2: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/2.jpg)
Agenda
•Web services concept.•Why web services?•When to use web services•Web services architecture•SOAP •WSDL• JAX-WS• JAX-WS vs. JAX-RPC•RESTful web services
![Page 3: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/3.jpg)
Web services concept
•Web service is a software system identified by a URI whose public interfaces and bindings are defined ,described and discovered by XML artifacts.(W3C)
•Client server application•Application to application communication•Interoperability (standard
communication) •Neutral (platform & language
independent).
![Page 4: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/4.jpg)
Agenda
•Web services concept.•Why web services?•When to use web services•Web services architecture•SOAP •WSDL• JAX-WS• JAX-WS vs. JAX-RPC•RESTful web services
![Page 5: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/5.jpg)
Why web services
•Interoperability (SOAP messaging).•Economical (recycled components, no
installation and tight integration of software).
•Accessible (applications are exposed and accessed on the web.)
•Available (services are on any device, any where, anytime.)
•Scalable (no limit on scope of application and their number.)
![Page 6: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/6.jpg)
Example
![Page 7: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/7.jpg)
Agenda
•Web services concept.•Why web services?•When to use web services?•Web services architecture•SOAP •WSDL• JAX-WS• JAX-WS vs. JAX-RPC•RESTful web services
![Page 8: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/8.jpg)
When to use web services? •Applications do not have severe
restrictions on reliability and speed.•Cooperation among different application.•Upgrading services independently from
clients without changing the WSDL.•Services can be easily expressed with
simple request/response semantics and simple state
•
![Page 9: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/9.jpg)
Agenda
•Web services concept.•Why web services?•When to use web services?•Web services architecture•SOAP •WSDL• JAX-WS• JAX-WS vs. JAX-RPC•RESTful web services
![Page 10: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/10.jpg)
Web services architecture
![Page 11: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/11.jpg)
Agenda
•Web services concept.•Why web services?•When to use web services?•Web services architecture•SOAP •WSDL• JAX-WS• JAX-WS vs. JAX-RPC•RESTful web services
![Page 12: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/12.jpg)
SOAP messaging
![Page 13: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/13.jpg)
SOAP(Simple Object Access Protocol)
•Define communication format between client and web service(XML message format).
•Wire protocol extension for conveying RPC calls.
•SOAP is not a transport protocol. You must attach your message to a transport mechanism like HTTP.
![Page 14: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/14.jpg)
SOAP structure• A SOAP message is contained in an envelop.• The envelop element in turn contain (in order)
1. An optional header with one or more child entries. (security , transaction) 2. A body element that can contain one or more child entries. These child entries may contain arbitrary XML data.(application data)
• Header entries may optionally have a “mustUnderstand” attribute. mustUnderstand=1 recipient must process header mustUnderstand=0 optional header
![Page 15: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/15.jpg)
SOAP structure(cont.)
•The body contains the XML message that you are transmitting.
• The message format is not specified by SOAP.The <Body></Body> tag pairs are just a way to notify the recipient that the actual XML message is contained therein.The recipient decides what to do with the message.
![Page 16: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/16.jpg)
Agenda
•Web services concept.•Why web services?•When to use web services?•Web services architecture•SOAP •WSDL• JAX-WS• JAX-WS vs. JAX-RPC•RESTful web services
![Page 17: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/17.jpg)
WSDL(Web Service Description Language)•Defines what your service does and how it
is invoked.•Guideline for constructing SOAP message.•XML language for writing
APIs(generating client code to use the web service).
•Verbose
![Page 18: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/18.jpg)
WSDL documents parts
•Data definition (in XML) for custom types.•Abstract message definitions (request,
response)•Organization of messages into “ports” and
“operations” (classes and methods).•Protocol bindings (to SOAP, for example)•Service point locations (URLs)
![Page 19: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/19.jpg)
WSDL document parts(cont.)
![Page 20: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/20.jpg)
WSDL document parts(cont.)
![Page 21: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/21.jpg)
WSDL document parts(Data Definition)
![Page 22: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/22.jpg)
Agenda
•Web services concept.•Why web services?•When to use web services?•Web services architecture•SOAP •WSDL•JAX-WS• JAX-WS vs. JAX-RPC•RESTful web services
![Page 23: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/23.jpg)
JAX-WS
•Simpler way to develop/deploy web services- POJO + Annotation.- No deployment descriptor is needed.- Layered programming model
•Layered programming model- Server side- Client side- Business layer
![Page 24: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/24.jpg)
Programming model(server side)•Write a POJO implementing the service•Add @WebService annotation to it•Deploy the application•Point your clients at the WSDL
http://mysite/myapp/service.wsdl
![Page 25: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/25.jpg)
Example(Server side)
@WebService(name="AddNumbers", portName="CalculatorPort", serviceName="CalculatorService")public class NumbersWebService{ @WebMethod(operationName="add") @WebResult(name="result") public int add(@WebParam(name="first") int first,
@WebParam(name="second") int second) { return first + second; }}
![Page 26: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/26.jpg)
Programming model(client side)•You need to know the url of WSDL•Generate service classes and interfaces.•Create object from service class•Get a proxy using a
get<ServiceName>Port method.•Invoke any remote operations.
![Page 27: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/27.jpg)
Example(Client side)
•CalculatorService service = new CalculatorServiceLocator();
AddNumbers calc = service.getCalculatorPort();
System.out.println(calc.add(3, 4));
![Page 28: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/28.jpg)
Agenda
•Web services concept.•Why web services?•When to use web services?•Web services architecture•SOAP •WSDL• JAX-WS•JAX-WS vs. JAX-RPC•RESTful web services
![Page 29: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/29.jpg)
JAX-WS vs. JAX-RPCJAX-RPC JAX-WS
Map to JAVA 1.4 Map to JAVA 1.5 and higher
Support SOAP 1.1 Support SOAP 1.1 and SOAP 1.2
Has its own data mapping model Data mapping model (JAXB)
Support MTOM through (JAXB)
Asynchronous communication
![Page 30: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/30.jpg)
JAX-WS Demo
![Page 31: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/31.jpg)
RESTful web services
![Page 32: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/32.jpg)
Agenda
•REST Architecture principales •RESTful web services & WADL.•REST vs. Traditional web services•RESTful advantages
![Page 33: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/33.jpg)
REST Architecture principales
•Representational State Transfer.•Every thing is a resource.•Resources are addressable.•Resources have an interface(operations
and data types).•Protocol is client-server, stateless,
cacheable, layered.
![Page 34: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/34.jpg)
Agenda
•REST Architecture principales •RESTful web services & WADL.•REST vs. Traditional web services•RESTful advantages
![Page 35: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/35.jpg)
RESTful web services & WADL.
•REST applied to web services.- web service accessible through URI.- operations are HTTP primitives(PUT,GET,..).- Web services returns a MIME type(XML, JSON, …).
•More resource efficient than SOAP•RESTful web services
- java class + annotations (for URI, operations, Data types).
![Page 36: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/36.jpg)
RESTful web services & WADL.(cont.)
•Annotations- @Path(“”) for URI of service.- @GET,@POST,.. for Http methods.- @Produces(“…”) to define format of returned data- @Consumes (“…”) to define format of accepted input data
![Page 37: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/37.jpg)
RESTful web services & WADL.(cont.)
<servlet> <servlet-name>ServletAdaptor</servlet-name> <servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class> <load-on-startup>1</load-on-startup></servlet><servlet-mapping> <servlet-name>ServletAdaptor</servlet-name> <url-pattern>/resources/*</url-pattern></servlet-mapping>
![Page 38: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/38.jpg)
RESTful web services & WADL.(cont.)
@Path("/hello")
@Consumes("text/html")
public class RESTWSTest{ @GET @Produces("text/html") public String sayHello(@QueryParam("name") String name) { return "<html><body><h1>Hello " + name +
"</h1></body></html>"; }
}
![Page 39: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/39.jpg)
RESTful web services & WADL.(cont.)
• WADL web application description language.- easy to understand.- HTTP assumed.
• XML-based language.• Development language + platform neutral.• Aligned with REST terminology.• WADL elements
- resources- methods- representations
![Page 40: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/40.jpg)
WADL<application><doc jersey:generatedBy="Jersey: 1.1.4 11/10/2009 05:36
PM"/><resources
base="http://localhost:8080/WebServicesREST/resources/"><resource path="/hello"> <method id="sayHello" name="GET"> <request> <param name="name" style="query" type="xs:string"/> </request> <response> <representation mediaType="text/html"/> </response> </method></resource></resources></application>
![Page 41: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/41.jpg)
Agenda
•REST Architecture principales.•RESTful web services & WADL.•REST vs. Traditional web services•RESTful advantages
![Page 42: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/42.jpg)
REST vs. Traditional web services
•Traditional web services- a lot of custom methods(ports according to business).- use http to transport soap
•RESTful- fixed methods(Http methods).- Http is the protocol.
![Page 43: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/43.jpg)
Agenda
•REST Architecture principales •RESTful web services & WADL.•REST vs. Traditional web services•RESTful advantages
![Page 44: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/44.jpg)
RESTful advantages
•More secure over http (use web port 80)•Ease of testing (only browser needed).•Thin client.•Save memory.(no need to build xml tree in memory).
![Page 45: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/45.jpg)
RESTful Demo
![Page 46: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/46.jpg)
Any Questions!??
![Page 47: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/47.jpg)
If time allowed
•SOAP Handler Demo
![Page 48: Ntg web services](https://reader036.fdocument.pub/reader036/viewer/2022062319/554f93d7b4c905435d8b520b/html5/thumbnails/48.jpg)
References •JavaPassion web site•Sun Java JEE6 tutorial•Sun Java Web Services tutorial