DISTRIBUTED SYSTEMS Practical Lab WebServices 2 A pragmatic - - PowerPoint PPT Presentation

distributed
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

DISTRIBUTED SYSTEMS

Practical Lab

1

slide-2
SLIDE 2

A pragmatic Introduction

WebServices

2

slide-3
SLIDE 3

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)

slide-4
SLIDE 4

WS - Overall Architecture

4

 Requester / Provider and Service Broker

slide-5
SLIDE 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)

WebServices - Overview

5

JVM - B Client

  • Gen. Artefacts

SOAP/HTTP Service Web Container JVM - A

slide-6
SLIDE 6

SOAP – The message protocol

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

slide-7
SLIDE 7

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

slide-8
SLIDE 8

WebServices in Java

8

slide-9
SLIDE 9

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)

slide-10
SLIDE 10

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

slide-11
SLIDE 11

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.

slide-12
SLIDE 12

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

slide-13
SLIDE 13

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

slide-14
SLIDE 14

WS – RMI comparison

 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