DISTRIBUTED SYSTEMS
Practical Lab
1
DISTRIBUTED SYSTEMS Practical Lab WebServices 2 A pragmatic - - PowerPoint PPT Presentation
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
1
3
Problem
Sockets / RMI / CORBA requires open ports for
Active firewalls may prohibit proprietary
Idea
Use http based messages for remote method
Messages, Interfaces and the Communication are
SOAP / WSDL and HTTP (defined by W3C)
4
Requester / Provider and Service Broker
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)
5
JVM - B Client
SOAP/HTTP Service Web Container JVM - A
6
Former: Simple Object Access Protocol XML based message exchange format See: http://de.wikipedia.org/wiki/SOAP
SOAP-ENV: Header SOAP-ENV: Body SOAP-ENV: Envelope
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
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)
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
See
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.
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
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
RMI Uses “native” Java
means (Serialization)
Supported by the JVM Full support of user-
defined data types
Synchronous
invocations only
Only for Java WebService Uses XML files for
communication
Requires additional
tools (part of SDK)
Complexity for
parameters / results is limited
Supports synchronous
and asynchronous calls
Independent of Java
14