Web Services Slides2

  • Uploaded by: Uday Kumar
  • 0
  • 0
  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Web Services Slides2 as PDF for free.

More details

  • Words: 1,841
  • Pages: 8
Overview

My Java “Hallo World” Web Service

1. Introduction to Web Services 2. Overview of Web Services architecture 3. Web services platforms (Java, .Net) “Hallo World” tutorials for Java and .Net 4. Key Web Services technologies: XML schemata and namespaces, SOAP, WSDL, and UDDI 5. Interoperability 6. Web Services Orchestration 7. Web services security

ƒ Simple hands-on introduction to ƒ Java Web Services: available libraries ƒ Apache – Tomcat – Axis: server concept

ƒ Examples ƒ Write some simple test Web Services and Clients ƒ Write a Web Service that is a client to the Google Web Service

1

2

Apache HTTP Server

Tomcat Application Server

http://httpd.apache.org

http://jakarta.apache.org

ƒ Apache HTTP Server: open-source HTTP server ƒ Secure, efficient, extensible, standard, open source HTTP server ƒ Working for UNIX and Windows. ƒ Basic transport protocol

ƒ Tomcat application server ƒ Reference implementation for ƒ Java Servlet ƒ Java Server Pages

ƒ Allows to access Java applications provided via an (apache) HTTP server

3

4

Axis Libraries

Java Libraries

http://ws.apache.org/axis

http://java.sun.com/webservices

ƒ Axis is a SOAP engine: a framework for constructing SOAP documents on clients and servers ƒ Support for WSDL ƒ Generate WSDL out of Java interfaces ƒ Generate Subs and Skeletons out of WSDL

ƒ Document processing ƒ Java API for XML Processing (JAXP) processes XML documents using various parsers ƒ Java Architecture for XML Binding (JAXB) maps Java objects to XML and vice versa

ƒ Remote computation ƒ Java API for XML-based RPC (JAX-RPC) using SOAP with Attachments API (SAAJ) to sends SOAP method calls to remote parties and receives the results ƒ Java API for XML Registries (JAXR) provides a standard way to access business registries and share information

ƒ Used by application servers, e.g., Tomcat

5

6

1

API for XML processing JAXP

API for XML Binding (JAXB)

We need to parse and transform XML: ƒ XML parsers with different interface levels: SAX-event and DOM-tree levels ƒ Document Object Model (DOM) implementation itself ƒ XSLT processing of XML translation

ƒ In Web Services, there is no standard binding between data types in a language (e.g. Java) and XML Schema ƒ Best practices and guarantee for interoperability due to WS-Interoperability organization ƒ JAXB as used by default follows this recommendation

ƒ Special closed world applications could benefit from tailored mappings ƒ JAXB additionally provides the framework to define special mappings 7

API for XML-based RPC (JAX-RPC)

8

SOAP with Attachments API (SAAJ)

ƒ Default serialization / deserialization of Java data types ƒ Remote Procedure Call (RPC) to endpoint addresses ƒ Support for WS-I

ƒ Used by JAX-RPC and using itself JAXP ƒ Writing SOAP messages directly ƒ SOAP is a messaging and processing framework that goes beyond its use in Web Services.

ƒ Basic Profile 1.1 ƒ Attachment Profile 1.0 ƒ Simple SOAP Binding Profile 1.0 9

10

API for XML Registries (JAXR) ƒ Access to UDDI registries ƒ Access to ebXML registries not supported. (More specifically: JAXR supports Version 2 UDDI registries but not to Version 1 UDDI registries.)

WS-Security BPEL UDDI

Using Java XML Libraries

Axis

SOAP XML

Apache - Tomcat (

11

WSDL

HTTP, FTP

)

12

2

Simple Web Service public class TestWS { public String testMethod(String in){ return in + "?"; } }

WS-Security BPEL UDDI

Using / Implementing Java XML Libraries

WSDL

Axis

SOAP XML

Apache - Tomcat (

HTTP, FTP

)

13

Simple Web Client

14

Simple Web Service deployment % ftp /TestWS.java <webapp>/TestWS_.jws

import …

public class TestClient { public static void main(String [] args) throws Exception { JAX-RPC endpoint = Objects String "http://localhost:80/axis/TestWS.jws"; Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress(new URL(endpoint)); Actual call.setOperationName("testMethod"); Call call.addParameter("in", XMLType.XSD_STRING, ParameterMode.IN); call.setReturnType( XMLType.XSD_STRING ); String ret=(String) call.invoke(new Object[]{“test”}); System.out.println("Got result: " + ret); } 15

}

16

Compile and Start the Client % javac –classpath "…" TestClient.java % java –classpath "…" TestClient % Got result : A test client ?

Client

Server

ƒ Create a handle for the server and a request object

ƒ Gets SOAP request ƒ Possibly compiles/loads the requested WS class and creates object of that class ƒ Executes the method on the actual parameters and computes the result (if any) ƒ Returns the SOAP reply

ƒ Set target WS ƒ Set parameter types ƒ Set actual parameter

ƒ Call ƒ Serializes request to SOAP ƒ Deserializes the SOAP reply to a Java object

17

18

3

Java Web Services (JWS) Pros: ƒ Simple to create ƒ Simple to deploy ƒ Simple to start with

SOAP Monitor ƒ Allows you to check for SOAP messages exchanged between client and server ƒ Works like a proxy:

Cons: ƒ No user defined binding of service name and implementation class ƒ No WSDL ƒ Hard to publish ƒ Hard to administrate ƒ No remote transparency

ƒ Client calls localhost’s monitor with the SOAP request ƒ Monitor displays the SOAP request and forwards it to the actual server ƒ SOAP reply gets displayed and forwarded to client

19

20

Start the SOAP Monitor % java –classpath “…” org.apache.axis.utils.tcpmon

New call target Unique new Port: e.g. http://localhost:1234/axis/TestWS.jws

% TCPmonitor.bat

Original call target Target Host and Port: e.g. http://localhost:8180/axis/TestWS.jws

Add monitor

21

New monitor …

Change Simple Web Client Monitor address public class TestClient { public static void main(String [] args) throws Exception { String endpoint = "http://localhost:1234/axis/TestWS.jws"; Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress(new URL(endpoint)); call.setOperationName("testMethod"); call.addParameter("in", XMLType.XSD_STRING, ParameterMode.IN); call.setReturnType( XMLType.XSD_STRING ); String ret=(String) call.invoke(new Object[]{“test”}); System.out.println("Got result: " + ret); import …

… waits for messages

One could actually run several monitors at the same time

}} 24

4

Re-compile and Re-start the Client % javac –classpath "…" TestClient.java % java –classpath "…" TestClient

Recent calls

% Got result : A test client ? SOAP request

SOAP reply

25

Custom Deployment – WSDD ƒ Web Services Deployment Descriptor SOAP request HTTP Message Header

SOAP Body encoding actual call

ƒ XML format ƒ Axis specific, Not W3C/Web Services standard !

ƒ Specifies ƒ Services to (un-)deploy, i.e. (de-)activate ƒ Mapping of logic Web Service name to

SOAP Envelop

• Implementation classes • Runtime objects thereof in a session

SOAP reply

ƒ Further administration information ƒ… 28

A Deployment Descriptor

An Undeployment Descriptor

WS to implementation <deployment mapping xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <service name=“TestWS2" provider="java:RPC"> <parameter name="className“ value=“test.TestWS2"/> <parameter name="allowedMethods" value="*"/> <parameter name="scope" value="Request"/>

<service name="TestWS2"/>

WS to object mapping Session | Request | Application

29

30

5

Deploying / Undeploying

Another Web Service package test;

% java -classpath "…" org.apache.axis.client.AdminClient -h -p<port> -u<user> -w<password <deployment file>.wsdd

public class TestWS2 { private int count = 0; public String testMethod(String in){ return in + "(calls: " + count++ + ")"; } }

% java -classpath "…" org.apache.axis.client.AdminClient -h … .wsdd

31

32

Another Web Client

Compile and deploy

Default WS location

import …

public class TestClient2 { public static void main(String[] args) throws Exception { String endpoint = "http://localhost:8180/axis/services/TestWS2"; String serviceClass = "TestWS2"; String method = "testMethod"; /* basically as before */ Still use … SOAP monitor call.setOperationName(new QName(serviceClass, testMethod)); … String ret = (String) call.invoke( newObject[]{“test”} ); System.out.println("Got result: " + ret); }}

% javac test/*.java % java -classpath "…" org.apache.axis.client.AdminClient –hlocalhost –p8180 –uUser –wPassword test/deploy.wsdd % ftp /test/TestWS2_.class <webapp>/WEB-INF/classes/test/TestWS2.class % ./deploy.bat % ftp /test/TestWS2.class <webapp>/WEB-INF/classes/test/TestWS2.class

33

34

Start the Client Server

% java -classpath "…" test.TestClient2

Client

% Got result 2: tested (calls: 0)

ƒ Basically as before ƒ Create a handle for the server and a request object ƒ Set target WS ƒ Set parameter types ƒ Set actual parameter

ƒ Call ƒ Serializes request to SOAP ƒ Deserializes the SOAP reply to a Java object 35

ƒ Gets SOAP request ƒ According to WSDD ƒ Maps logic WS name to WS class ƒ Creates object

ƒ Executes the method on the actual parameters and computes the result (if any) ƒ Returns the SOAP reply

36

6

Web Services Classes – deployment using WSDD

Pros: ƒ Still pretty simple to create, deploy ƒ User defined binding of service name and implementation class

Remote transparency: WSDL

Cons: ƒ No WSDL subs & skeletons: No remote transparency

Remote Remote Client Client

Local Local Client Client

Server Server

WSDL WSDL Generated Generated stub stub

WSDL WSDL Generated Generated stub stub

WSDL WSDL Generated Generated skeleton skeleton

SOAP (HTTP) Local SOAP (HTTP) Remote 37

Generate WSDL: Java2WSDL

38

Java2WSDL Example

ƒ Web Services Description Language (WSDL) corresponds to an interface of a Web Service ƒ Information can be extracted ƒ WSDL encoding can be generated

WSDL name

% java -classpath "…" org.apache.axis.wsdl.Java2WSDL Target WS -o GoogleWS.wsdl -l "http://localhost:8180/axis/services/GoogleWS" WS namespace -n "urn:WSCPtutorial" -p "tutorial" "urn:WSCPtutorial" tutorial.GoogleWS Mapping WS namespace Java package

% Java2WSDL.bat Fully qualified Java class name

39

Generate Stubs: WSDL2Java

40

WSDL2Java Example

ƒ Stub classes from a Java interface/class *:

% java -classpath "…" org.apache.axis.wsdl.WSDL2Java -Nurn:WSCPtutorial tutorial GoogleWS.wsdl

ƒ *.java: New interface file with appropriate remote usages. ƒ *SoapBindingImpl.java: default server implementation WS, modify manually to actual implementation. ƒ *Service.java: client side service interface. ƒ *ServiceLocator.java: client side service implementation factory. ƒ *SoapBindingSkeleton.java: Server side skeleton. ƒ *SoapBindingStub.java: Client side stub. ƒ (data types): Java files produced for non-standard types.

% WSDL2Java.bat

Mapping WS namespace Java package

Just created WSDL file name

ƒ deploy.wsdd / undeploy.wsdd: (Un-)deployment descriptors

41

42

7

Web Service deployment

Compile and Start the Client % javac -classpath "…" GoogleClient.java % java -classpath "…" GoogleClient search WSCC

% javac tutorial/ *.java % java -classpath "…" org.apache.axis.client.AdminClient -hlocalhoset –p8180 –uUser –wPassword tutorilal/deploy.wsdd % ftp /tutorial/*.class <webapp>/WEB-INF/classes/tutorial/*.class

% Answer: … [ URL = "http:// http://wscc http://wscc.info/ wscc.info/" .info/ Title = "This site was created using SiteDirect from Wipmind ..." Snippet = "This site was created using SiteDirect from Wipmind webbpublicering webdesign web
content management publiceringsverktyg wcm e-handel e-business e-shop webshop ... " Directory Category = {SE="", FVN=""} Directory Title = "" Summary = "" Cached Size = "2k" Related information present = true Host Name = ""

% deployGoogle.bat % ftp /tutorial/*.class <webapp>/WEB-INF/classes/tutorial/*.class

],



43

Client

Server

ƒ Create a locator object ƒ Get a stub ƒ Call stub as if it was a local service ƒ Stub manages the SOAP request to / reply from Skeleton

ƒ Skeleton gets SOAP request ƒ Calls WS impl as if it as a local client ƒ WS returns to skeleton ƒ Skeleton manages the SOAP reply to Stub

44

WS Interface

WS Interface Implements

Client

Implements

Binding Impl

call

Get Stub

Service Locator

Service/ Actual WS implementation

call

new

Binding Stub

SOAP request

Binding Skeleton

45

Web Services –

46

Resources

generated using WSDL

ƒ Java Web Services Tutorial Pros: ƒ Easy to create, deploy ƒ User defined binding ƒ Can be published ƒ Remote/Language transparency ƒ Static invocation is faster

Cons: ƒ Static invocation is less flexible ƒ More complex

http://java.sun.com/webservices/docs/1.1/tutorial/doc ƒ Great for the XML APIs ƒ Refers to a complete installation ƒ Leaves out Axis

ƒ Axis User's Guide:

http://ws.apache.org/axis/java/user-guide.html ƒ Great for getting hands on Axis ƒ Assumes some knowledge on XML APIs ƒ Standards: http://www.w3c.org 47

48

8

Related Documents

Web Services Slides2
November 2019 17
Web Services
November 2019 38
Web Services
November 2019 48
Web Services
November 2019 43
Web Services
November 2019 37
Web Services
December 2019 33

More Documents from "idoctrine"

Web Services Slides
November 2019 13
Wsdlcontracts
November 2019 13
Jax-ws
November 2019 13
Wsdl11soap12
November 2019 17
Hibernate Join Fetch
October 2019 19