• No results found

Joke Server example. with Java and Axis. Web services with Axis SOAP, WSDL, UDDI. Joke Metaservice Joke Server Joke Client.

N/A
N/A
Protected

Academic year: 2021

Share "Joke Server example. with Java and Axis. Web services with Axis SOAP, WSDL, UDDI. Joke Metaservice Joke Server Joke Client."

Copied!
5
0
0

Loading.... (view fulltext now)

Full text

(1)

Joke Server example

Joke

Metaservice

Joke

Server

Joke

Client

meta

service

client

server

1 2 3 4 5 6

Everything is XML over HTTP (REST).

Henning Niss SOAP and WSDLwith Java and Axis – p.2

SOAP, WSDL, UDDI

UDDI

registry

client

SOAP&WSDL

joke service

register service lookup WSDL SOAP req SOAP resp

SOAP and WSDL

with Java and Axis

Interactive web services, Course, Fall 2003

Henning Niss

IT University of Copenhagen

Web services with Axis

Today: How to invoke and deploy web services with

Apache

Axis

.

Axis is a

SOAP engine

with extensive support for

WSDL

.

a framework for constructing SOAP processors (clients,

servers, gateways, etc);

support for WSDL;

tools to generate Java classes from WSDL (and WSDL

from Java);

server that plugs into Tomcat.

(2)

A Simple Joke Client (1)

Example only: a client that uploads one joke to a joke server

and immediate requests the jokes in the specified category.

Need to know the

WSDL

-description of the server.

Henning Niss SOAP and WSDLwith Java and Axis – p.6

Joke Server WSDL (1)

<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions targetNamespace="urn:HenningsJokeServer" .../> <wsdl:types> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:HenningsJokeServer"> <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/> <complexType name="ArrayOf_xsd_string"> <complexContent> <restriction base="soapenc:Array"> <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/> </restriction> </complexContent> </complexType> </schema> </wsdl:types>

Henning Niss SOAP and WSDLwith Java and Axis – p.7

A Simple Joke Server (1)

interface JokeServer {

void submit(String joke, String category);

String[] lookup(String category);

String[] categories();

}

Henning Niss SOAP and WSDLwith Java and Axis – p.4

A Simple Joke Server (2)

public class JokeServerImpl implements JokeServer {

Map jokes = new TreeMap(); // maps categories to lists of jokes public void submit(String joke, String category) {

LinkedList catjokes = (LinkedList)jokes.get(category); if(catjokes==null) catjokes = new LinkedList();

catjokes.addLast(joke);

jokes.put(category, catjokes); }

public String[] lookup(String category) { List catjokes = (List)jokes.get(category); String[] res = new String[catjokes.size()]; return catjokes.toArray(res);

}

public String[] categories() {

String[] res = new String[jokes.size()]; return jokes.keySet().toArray(res);

} }

(3)

Joke Server WSDL (4)

<wsdl:binding name="JokeServerSoapBinding" type="impl:JokeServer"> <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="lookup"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="lookupRequest"> <wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:HenningsJokeServer"/> </wsdl:input> <wsdl:output name="lookupResponse"> <wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:HenningsJokeServer"/> </wsdl:output> </wsdl:operation> ... </wsdl:binding>

Henning Niss SOAP and WSDLwith Java and Axis – p.10

Joke Server WSDL (5)

<wsdl:service name="JokeServerService"> <wsdl:port name="JokeServer" binding="impl:JokeServerSoapBinding"> <wsdlsoap:address location="http://localhost:8180/axis/services/JokeServer"/> </wsdl:port> </wsdl:service>

Joke Server WSDL (2)

<wsdl:message name="lookupRequest">

<wsdl:part name="category" type="xsd:string"/> </wsdl:message> <wsdl:message name="lookupResponse"> <wsdl:part name="lookupReturn" type="impl:ArrayOf_xsd_string"/> </wsdl:message> <wsdl:message name="submitRequest">

<wsdl:part name="joke" type="xsd:string"/> <wsdl:part name="category" type="xsd:string"/> </wsdl:message> <wsdl:message name="submitResponse" /> <wsdl:message name="categoriesRequest" /> <wsdl:message name="categoriesResponse"> <wsdl:part name="categoriesReturn" type="impl:ArrayOf_xsd_string"/> </wsdl:message>

Henning Niss SOAP and WSDLwith Java and Axis – p.8

Joke Server WSDL (3)

<wsdl:portType name="JokeServer">

<wsdl:operation name="lookup" parameterOrder="category"> <wsdl:input name="lookupRequest" message="impl:lookupRequest"/> <wsdl:output name="lookupResponse" message="impl:lookupResponse"/> </wsdl:operation> ... </wsdl:portType>

(4)

A Simple Joke Server (3)

Tool support

to generate a WSDL description based on the

server interface.

The

Java2WSDL

tool generates the WSDL description

automatically.

java org.apache.axis.wsdl.Java2WSDL -o jokeserver.wsdl

-l "http://localhost:8180/axis/services/JokeServer"

-i jokeserver.JokeServerImpl -n "urn:HenningsJokeServer"

-p"jokeserver" "urn:HenningsJokeServer"

jokeserver.JokeServer

Henning Niss SOAP and WSDLwith Java and Axis – p.14

A Simple Joke Server (4)

Generating (SOAP) skeletons using the

WSDL2Java

tool.

java org.apache.axis.wsdl.WSDL2Java -o . -s -S true

-Nurn:HenningsJokeServer -d Application

jokeserver

Generated classes:

JokeServer.java

(interface)

JokeServerService.java

(service interface)

JokeServerServiceLocator.java

(service locator)

JokeServerSoapBindingImpl.java

(template)

JokeServerSoapBindingSkeleton.java

(SOAP skeleton)

JokeServerSoapBindingStub.java

(SOAP stub)

Henning Niss SOAP and WSDLwith Java and Axis – p.15

A Simple Joke Client (2)

How to get from the WSDL description to code?

Tool support!

The

WSDL2Java

tool generates stubs for invoking the service.

java org.apache.axis.wsdl.WSDL2Java jokeserver.wsdl

Generated classes:

JokeServer.java

(interface)

JokeServerService.java

(service interface)

JokeServerServiceLocator.java

(locate service)

JokeServerSoapBindingStub.java

(stub for talking to service)

Henning Niss SOAP and WSDLwith Java and Axis – p.12

A Simple Joke Client (3)

import HenningsJokeServer.*;

public class JokeClient {

static final String CATEGORY = "languages"; static final String JOKE =

"If it wasn’t for C, we’d be using BASI, PASAL and OBOL.";

public static void main(String[] args) { try {

JokeServerService service = new JokeServerServiceLocator(); JokeServer jokes = service.getJokeServer();

jokes.submit(JOKE,CATEGORY);

String[] res = jokes.lookup(CATEGORY); for(int i=0; i<res.length; i++)

System.out.println(res[i]);

} catch (Exception e) { e.printStackTrace(); }

} }

(5)

A Simple Joke Server (5)

Deploying

a web service is a matter of telling the Axis

implementation about it.

Invoking

WSDL2Java

in server-side mode also generates a

deployment descriptor

deploy.wsdd.

java org.apache.axis.client.AdminClient -p8180

deploy.wsdd

We can see the services deployed:

java org.apache.axis.client.AdminClient -p8180 list

References

Related documents

83,3 85,3 96 54,7 75,3 Jumlah 78,92 Bahwa hasil penelitian dan pengisian daftar pertanyaan (koesioner) ke 30 responden terhadap faktor internal yang terdiri dari 5 (lima)

ferric reducing antioxidant power (FRAP), DPPH free radical scavenging activity and ABTS radical cation decolourisation, together with the determination of total

We will become a vigorous rural area whose inhabitants have a sense of community and co-operate across all sec- toral and municipal borders, while our commitment and knowledge

Hence, for more study the progression &amp; development of RBV theory used as a strategic tool to recognize the available resources, capabilities &amp; core competencies they

Late maternal death is defined as a maternal death due to pregnancy (direct or indirect obstetric causes) which occurred more than 42 days but less than one year after the end

Our conclusion is that the classical formulation of the &#34;dutch book argument&#34; may be slightly improved, by stating that the said normalized implied probabilities always

The Lebanon Fire Department provides coordination for all activities related to the City of Lebanon Emergency Management Program and the Emergency Operations Center (EOC).. The

The study of Nonnenberg and Mendonca (2004) finds that the factors such as the market size measured by GNP, growth rate of the product, the availability of skilled labor,