You are on page 1of 8

Overview My Java “Hallo World” Web Service

1. Introduction to Web Services ƒ Simple hands-on introduction to


2. Overview of Web Services architecture ƒ Java Web Services: available libraries
3. Web services platforms (Java, .Net) “Hallo World” ƒ Apache – Tomcat – Axis: server concept
tutorials for Java and .Net
ƒ Examples
4. Key Web Services technologies: XML schemata
ƒ Write some simple test Web Services and
and namespaces, SOAP, WSDL, and UDDI
Clients
5. Interoperability
ƒ Write a Web Service that is a client to the Google
6. Web Services Orchestration Web Service
7. Web services security

1 2

Apache HTTP Server Tomcat Application Server


http://httpd.apache.org http://jakarta.apache.org
ƒ Apache HTTP Server: open-source HTTP ƒ Tomcat application server
server ƒ Reference implementation for
ƒ Secure, efficient, extensible, standard, open ƒ Java Servlet
source HTTP server ƒ Java Server Pages
ƒ Working for UNIX and Windows. ƒ Allows to access Java applications provided
ƒ Basic transport protocol 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 ƒ Document processing
ƒ Java API for XML Processing (JAXP) processes XML
servers documents using various parsers
ƒ Support for WSDL ƒ Java Architecture for XML Binding (JAXB) maps Java
ƒ Generate WSDL out of Java interfaces objects to XML and vice versa

ƒ Generate Subs and Skeletons out of WSDL ƒ Remote computation


ƒ Java API for XML-based RPC (JAX-RPC) using SOAP
ƒ Used by application servers, e.g., Tomcat 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
5 6

1
API for XML processing JAXP API for XML Binding (JAXB)
We need to parse and transform XML: ƒ In Web Services, there is no standard binding
between data types in a language (e.g. Java) and
ƒ XML parsers with different interface levels:
XML Schema
SAX-event and DOM-tree levels
ƒ Best practices and guarantee for interoperability
ƒ Document Object Model (DOM) due to WS-Interoperability organization
implementation itself ƒ JAXB as used by default follows this recommendation
ƒ XSLT processing of XML translation ƒ Special closed world applications could benefit from
tailored mappings
ƒ JAXB additionally provides the framework to define
special mappings

7 8

API for XML-based RPC (JAX-RPC) SOAP with Attachments API (SAAJ)
ƒ Default serialization / deserialization of Java ƒ Used by JAX-RPC and using itself JAXP
data types ƒ Writing SOAP messages directly
ƒ Remote Procedure Call (RPC) to endpoint ƒ SOAP is a messaging and processing
addresses framework that goes beyond its use in Web
ƒ Support for WS-I 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. WS-Security

(More specifically: JAXR supports Version 2 BPEL

UDDI registries but not to Version 1 UDDI UDDI

WSDL
registries.) Using Axis
SOAP
Java XML
XML
Libraries
Apache - Tomcat ( HTTP, FTP )

11 12

2
Simple Web Service
public class TestWS {
public String testMethod(String in){
WS-Security
return in + "?";
BPEL
}
UDDI
}
WSDL
Using / Axis
Implementing SOAP
Java XML XML
Libraries Apache - Tomcat ( HTTP, FTP )

13 14

Simple Web Client Simple Web Service deployment


% ftp <localhost>/TestWS.java
<webapp>/TestWS_<login>.jws
import …
public class TestClient {
public static void main(String [] args) throws Exception {
JAX-RPC
Objects String endpoint =
"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 Client Server

% Got result : A test client ? ƒ Create a handle for the ƒ Gets SOAP request
server and a request object ƒ Possibly compiles/loads
ƒ Set target WS the requested WS class
ƒ Set parameter types and creates object of that
ƒ Set actual parameter class
ƒ Call ƒ Executes the method on
ƒ Serializes request to SOAP the actual parameters and
ƒ Deserializes the SOAP reply computes the result (if any)
to a Java object
ƒ Returns the SOAP reply

17 18

3
Java Web Services (JWS) SOAP Monitor
Pros: Cons: ƒ Allows you to check for SOAP messages
ƒ Simple to create ƒ No user defined exchanged between client and server
ƒ Simple to deploy binding of service ƒ Works like a proxy:
ƒ Simple to start with name and
implementation class ƒ Client calls localhost’s monitor with the SOAP
request
ƒ No WSDL
ƒ Hard to publish
ƒ Monitor displays the SOAP request and forwards
it to the actual server
ƒ Hard to administrate
ƒ No remote transparency ƒ 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:
% TCPmonitor.bat e.g.
http://localhost:1234/axis/TestWS.jws

Original call target


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

Add monitor

21

New monitor …
Change Simple Web Client

import … Monitor
public class TestClient { address
public static void main(String [] args) throws Exception {
… waits for messages 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 );
One could actually run several
String ret=(String) call.invoke(new Object[]{“test”});
monitors at the same time
System.out.println("Got result: " + ret);
}}

24

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

% Got result : A test client ?


SOAP request

SOAP reply

25

Custom Deployment – WSDD


ƒ Web Services Deployment Descriptor
SOAP request
ƒ XML format
HTTP ƒ Axis specific, Not W3C/Web Services standard !
Message
Header ƒ Specifies
ƒ Services to (un-)deploy, i.e. (de-)activate
SOAP ƒ Mapping of logic Web Service name to
SOAP Body encoding actual call Envelop • Implementation classes
• Runtime objects thereof in a session
SOAP reply ƒ Further administration information
ƒ…
28

A Deployment Descriptor An Undeployment Descriptor


WS to
<deployment implementation <undeployment
mapping
xmlns="http://xml.apache.org/axis/wsdd/" xmlns="http://xml.apache.org/axis/wsdd/">
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <service name="TestWS2"/>
<service name=“TestWS2" provider="java:RPC"> </undeployment>
<parameter name="className“ value=“test.TestWS2"/>
<parameter name="allowedMethods" value="*"/>
<parameter name="scope" value="Request"/>
</service>
</deployment>
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<host> public class TestWS2 {
-p<port>
private int count = 0;
-u<user>
-w<password public String testMethod(String in){
<deployment file>.wsdd return in + "(calls: " + count++ + ")";
}
% java -classpath "…" org.apache.axis.client.AdminClient }
-h

<undeployment file>.wsdd

31 32

Another Web Client Compile and deploy


Default WS
location
import … % javac test/*.java
public class TestClient2 {
% java -classpath "…" org.apache.axis.client.AdminClient
public static void main(String[] args) throws Exception {
–hlocalhost
String endpoint =
"http://localhost:8180/axis/services/TestWS2"; –p8180
String serviceClass = "TestWS2"; –uUser
String method = "testMethod"; –wPassword test/deploy.wsdd
/* basically as before */
% ftp <local>/test/TestWS2_<login>.class
… Still use
SOAP monitor <webapp>/WEB-INF/classes/test/TestWS2.class
call.setOperationName(new QName(serviceClass, testMethod));

String ret = (String) call.invoke( newObject[]{“test”} ); % ./deploy.bat
System.out.println("Got result: " + ret); % ftp <local>/test/TestWS2.class
}} <webapp>/WEB-INF/classes/test/TestWS2.class
33 34

Start the Client


% java -classpath "…" test.TestClient2 Server

% Got result 2: tested (calls: 0) Client ƒ Gets SOAP request


ƒ According to WSDD
ƒ Basically as before
ƒ Maps logic WS name to
ƒ Create a handle for the WS class
server and a request object ƒ Creates object
ƒ Set target WS
ƒ Set parameter types ƒ Executes the method on
ƒ Set actual parameter the actual parameters and
ƒ Call computes the result (if any)
ƒ Serializes request to SOAP ƒ Returns the SOAP reply
ƒ Deserializes the SOAP reply
to a Java object
35 36

6
Web Services Classes –
deployment using WSDD Remote transparency: WSDL

Pros: Cons: Remote Local Server


Remote Local Server
ƒ Still pretty simple to ƒ No WSDL subs & Client
Client Client
Client
create, deploy skeletons: No remote WSDL WSDL WSDL
WSDL WSDL WSDL
ƒ User defined binding of transparency Generated
Generated Generated
Generated Generated
Generated
service name and stub
stub stub
stub skeleton
skeleton
implementation class
SOAP (HTTP) Local
SOAP (HTTP) Remote

37 38

Generate WSDL: Java2WSDL Java2WSDL Example


ƒ Web Services Description Language (WSDL) WSDL name
corresponds to an interface of a Web Service % java -classpath "…" org.apache.axis.wsdl.Java2WSDL
-o GoogleWS.wsdl Target WS
ƒ Information can be extracted -l "http://localhost:8180/axis/services/GoogleWS"
WS namespace
ƒ WSDL encoding can be generated -n "urn:WSCPtutorial"
-p "tutorial" "urn:WSCPtutorial"
tutorial.GoogleWS
Mapping
WS namespace
% Java2WSDL.bat Java package
Fully qualified
Java class name

39 40

Generate Stubs: WSDL2Java WSDL2Java Example


ƒ Stub classes from a Java interface/class *: % java -classpath "…" org.apache.axis.wsdl.WSDL2Java
-Nurn:WSCPtutorial tutorial
ƒ *.java: New interface file with appropriate remote usages. GoogleWS.wsdl
ƒ *SoapBindingImpl.java: default server implementation WS, Mapping
modify manually to actual implementation. WS namespace
% WSDL2Java.bat Java package
ƒ *Service.java: client side service interface.
ƒ *ServiceLocator.java: client side service implementation factory.
ƒ *SoapBindingSkeleton.java: Server side skeleton. Just created
ƒ *SoapBindingStub.java: Client side stub. WSDL file name
ƒ (data types): Java files produced for non-standard types.
ƒ deploy.wsdd / undeploy.wsdd: (Un-)deployment descriptors

41 42

7
Web Service deployment Compile and Start the Client
% javac tutorial/ *.java % javac -classpath "…" GoogleClient.java
% java -classpath "…" % java -classpath "…" GoogleClient search WSCC
org.apache.axis.client.AdminClient
-hlocalhoset –p8180 –uUser –wPassword % Answer: …
tutorilal/deploy.wsdd [
% ftp <local>/tutorial/*.class URL = "http://
http://wscc
http://wscc.info/
wscc.info/"
.info/
Title = "This site was created using SiteDirect from Wipmind <b>...</b>"
<webapp>/WEB-INF/classes/tutorial/*.class
Snippet = "This site was created using SiteDirect from Wipmind
webbpublicering webdesign web<br> content management publiceringsverktyg wcm
e-handel e-business e-shop webshop <b>...</b> "
% deployGoogle.bat Directory Category = {SE="", FVN=""}
% ftp <local>/tutorial/*.class Directory Title = ""
<webapp>/WEB-INF/classes/tutorial/*.class Summary = ""
Cached Size = "2k"
Related information present = true
Host Name = ""
], …

43 44

Client Server WS WS
Interface Interface
ƒ Create a locator object ƒ Skeleton gets SOAP Implements Implements

ƒ Get a stub request Service/


call Binding
ƒ Calls WS impl as if it as Client Actual WS
ƒ Call stub as if it was a Impl implementation
local service a local client Get Stub call

ƒ Stub manages the ƒ WS returns to skeleton


Service Binding SOAP Binding
SOAP request to / reply ƒ Skeleton manages the Locator new Stub request Skeleton
from Skeleton SOAP reply to Stub
45 46

Web Services –
Resources
generated using WSDL

ƒ Java Web Services Tutorial


Pros: Cons: http://java.sun.com/webservices/docs/1.1/tutorial/doc
ƒ Great for the XML APIs
ƒ Easy to create, deploy ƒ Static invocation is less
ƒ Refers to a complete installation
ƒ User defined binding flexible ƒ Leaves out Axis
ƒ Can be published ƒ More complex ƒ Axis User's Guide:
ƒ Remote/Language http://ws.apache.org/axis/java/user-guide.html
ƒ Great for getting hands on Axis
transparency
ƒ Assumes some knowledge on XML APIs
ƒ Static invocation is
ƒ Standards: http://www.w3c.org
faster
47 48