1 DISTRIBUTED SYSTEMS Practical Lab
WebServices 2 A pragmatic Introduction
WS - Overview 3 Problem Sockets / RMI / CORBA requires open ports for communication Active firewalls may prohibit proprietary communication protocol Idea Use http based messages for remote method invocations Messages, Interfaces and the Communication are defined/realized using standardized protocols SOAP / WSDL and HTTP (defined by W3C)
WS - Overall Architecture 4 Requester / Provider and Service Broker
WebServices - Overview 5 Architecture – Programmers Perspective Server offers its service via a Web Container (not stand alone) E.g. Apache Tomcat, WebSphere , … Messages are encoded using SOAP (XML file format) Interfaces are defined using WSDL (XML based description) Communication is realized using HTTP (requires a webserver) JVM - A JVM - B Client Service Gen. Artefacts Web Container SOAP/HTTP
SOAP – The message protocol 6 Former: Simple Object Access Protocol XML based message exchange format SOAP-ENV: Envelope SOAP-ENV: Header SOAP-ENV: Body See: http://de.wikipedia.org/wiki/SOAP
WSDL – Interface Specification 7 Web Services Description Language XML base description language of service interfaces Defines (examples): Endpoints – connection information Ports/Interfaces – the service interface (collection of operations) Operations – one “method” offered by the interface Messages – used to encode arguments for operations See: http://en.wikipedia.org/wiki/Web_Services_Description_Language
WebServices in Java 8
Building a WebService using Java 9 Requires WebService Framework Various implementations available Apache Axis - http://ws.apache.org/axis/ Apache CXF - http://cxf.apache.org/ JAX-WS – part of SDK since Java 6 J2EE Container specific implementations We will use JAX-WS (requires Java 6)
Defining an Interface (JAX-WS) 10 Can be an interface or an actual implementation Definition marked using @WebSphere annotation => see DemoWS.java in WS Demo Additional markup options offered via annotations See package javax.jws in Java API Potential types for parameters and return types are heavily restricted See http://download.oracle.com/javaee/5/tutorial/doc/bnaz q.html#bnazs
Implement a Server 11 Server instantiates implementation of Service Publishes service using an Endpoint See: Server.java in WS demo Endpoint.publish("http://localhost:8080/services", new DemoWS()); JAX-WS is automatically generating WSDL for Service Can be accessed via the URL http://localhost:8080/services?wsdl while the server is running.
Implementing a Client 12 To access the server, code has to be generated based on the WSDL Generation tool: wsimport (part of JDK) wsimport -d ../../ -keep -p demo.ws.gen <URL> - d … root for code generation - p … package name - keep … preserves generated files Note: files are compiled after generating them May lead to problems with eclipse => delete *.class Generates code for “complex” classes, independent of original classes The tool does not support all kind of WSDL features
Implementing a Client (2) 13 Use generated classes to access Service XYZService … to obtain remote reference (Port) Use generated interface to invoke methods See: Client.java Attention: generated classes are incompatible to original classes
WS – RMI comparison 14 RMI WebService Uses “native” Java Uses XML files for means (Serialization) communication Supported by the JVM Requires additional tools (part of SDK) Full support of user- defined data types Complexity for parameters / results is limited Supports synchronous Synchronous and asynchronous calls invocations only Independent of Java Only for Java
Recommend
More recommend