23
Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Embed Size (px)

Citation preview

Page 1: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Presentation:Advanced AXIS:

Deployment Descriptors and Advanced Types

Page 2: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Outline

• So far with AXIS• Installation of Apache Tomcat and AXIS• Easy deployment of .java with .jws • Using Dynamic Call Interface for the Client to .jws

• Rather tedious work – and pretty error-prone• WSDL2Java Client generation

• This time• Use of.wsdd deployment files in AXIS (server specific)• Types allowed in Java/WSDL mappings (client/server)• Use of Arrays and Objects (client/server)• Custom Objets (client/server)• Use of the WSDL2Java stubgeneration tool (client)• Scope (client/server)

Page 3: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Using Axis Web Service Deployment Descriptor I

• Easy to use .jws• But not nice deployment• Only source code (.java) no bytecode (.class)• How to undeploy?• Problems with accessing outside classes (no suppot for

packages)• Not possible to use custom objects

• Alternative: Using the deployment tool in Axis with Web Service Deployment Descriptor (.wsdd) files• % java org.apache.axis.client.AdminClient deploy.wsdd

Page 4: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Use of AdminClient

• AdminClient may be used as console application taking a deployment file as argument (as shown on the previous slide)

• Or may be adopted into a deployment program or software-tool if needed for better deployment control:

Page 5: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

List of Deployed Services with AdminClient

Results in a complete list of deployed servicesResults in a complete list of deployed services

Using the “list” argument with AdminClientUsing the “list” argument with AdminClient

Page 6: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Using Axis Web Service Deployment Descriptor II – Into the .wsdd

• Web Service Deployment Descriptor (.wsdd) is XML for defining characteristics of a Web service • The service name and the provider

<service name="HelloWorld" provider="java:RPC"> • The (packaged) class that provides the service

<parameter name="className" value=“hello. HelloWorld"/>

• Which of the class methods are to be exposed (all or limited)<parameter name="allowedMethods" value="*"/><parameter name="allowedMethods" value="getHelloWorldMessage someOtherMethod"/>

Page 7: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Using Axis Web Service Deployment Descriptor III – provider style

• Much higher degree of deployment control• Also needed when dealing with non RPC

java:RPC = ”object-oriented middleware style”- others include: - Document services - Wrapped services & - Message services- these are not an integral part of the curriculum

java:RPC = ”object-oriented middleware style”- others include: - Document services - Wrapped services & - Message services- these are not an integral part of the curriculum

Page 8: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Using Axis Web Service Deployment Descriptor IIII - Scope

• Web service scope specifies the lifetime/management of the service class. • Specify scope of the Web service (request, application or

session) in wsdd<parameter name="scope" value="request"/>

• request - is the default scope; each request causes a new service object to be created to handle the request

• session - conceptually, all requests by a single client are handled by a single object (implemented with cookies)

• application - a singleton web service. A single object serves all clients.

• More on scope later

Page 9: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Parameter Types for Web Services and Clients in AXIS

• The primitive types are mapped as shown below:

• These types can be used as either parameter or return types

Page 10: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Value Objects

• Allowed objects are:• Objects listed in the preceding slide • Objects that conforms to the Java Bean Standard

• Custom objects – rolling your own• Normally one would like to use ones own objects as parameters and

return values• This may be done using the BeanSerializer• Beans MUST conform to the Java Bean Standard

• This means empty constructor and accessor (getter/setter) methods

• More on this later

• Collections SHOULD NOT BE USED if interoperability is needed (e.g. with C# og C++) as this is under-specified• Instead use regular Arrays (Object[] and typecast)• At least until next version of the specification

Page 11: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Using Custom Objects

• Axis supports passing user-defined class objects that are Java Beans • get and set methods are defined for every class attribute • no-argument constructor• the class is Serializable

• Marshalling and Unmarshalling parameters and return-values • Suppose a Web Service returns a user-defined SomeClass object.

• On the server, deploy with a .wsdd element associating the user-defined class (SomeClass ) with the Axis provided BeanService as:

• <beanMapping qname="msgNS:SomeClass" xmlns:msgNS="urn:BeanService"languageSpecificType="java:onk1Package.SomeClass"/>

• On the client side, WSDL2Java creates a BeanService. SomeObject class • The wsdl for the corresponding Web Service includes xml for

SomeClass. • The proxy unmarshals a returned Message object to a BeanService.

SomeClass object. • This is integral for the support of the Data Transfer Object pattern (also

known as Replicating Objects pattern)

Page 12: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Example WSDD

<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

<service name="TVPSService" provider="java:RPC"> <parameter name="className" value="tvps.TVPSService"/> <parameter name="allowedMethods" value="*"/> <beanMapping qname="myNS:Programme" xmlns:myNS="urn:BeanService"

languageSpecificType="java:tvps.Programme"/> </service></deployment>

• TV-Program Web service (TVPSService.class):• Java Server• C# Client (Pocket PC .NET CF)• Java Client (UNIX, LINUX, Windows)

• Key elements:• Package of service = tvps• Class of service = tvps.TVPSService• Allowed methods = all (*)• Custom class (return parameter) = tvps.Programme

Page 13: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Client side – using WSDL2Java

• The deployment is purely server side• Lets now take a look at the client side• We have already seen dynamic clients

• If we would like to generate static Client proxy stubs for a WSDL service – we could use:• C:\dev-axis\java org.apache.axis.wsdl.WSDL2Java

http://localhost:8080/axis/Calculator.jws?wsdl -p calc

• Which would generate a package ”calc” containing all the Proxy code needed for building a Client

Page 14: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Result of WSDL2JavaWSDL clause Java class(es) generated

For each entry in the type section A java class (as in Java RMI & CORBA)

A holder if this type is used as an inout/out parameter (as in CORBA)

For each portType A java interface (as in Java RMI & CORBA)

For each binding A stub class (as in Java RMI & CORBA)

For each service A service interface

A service implementation (the locator)

Page 15: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Building a Client

package hello;

public class HelloWorldClient {

public static void main (String args[]) throws Exception {

// Make a service locator HelloWorldService service = new HelloWorldServiceLocator();

//Now use the service locator to get a stub which implements the SDI HelloWorld stub = (HelloWorld) service.getHelloWorld();

String text = stub.getHelloWorldMessage("Test af OO indpakning");System.out.println(”Recieved from server: "+text);

}}

• Lets start by generating the Clients stub given the WSDL (-p = destination package = hello):• java org.apache.axis.wsdl.WSDL2Java http://localhost:8080/axis/HelloWorld.jws?wsdl –p hello

Page 16: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

HelloWorld.java – the interface

• Generated by the WSDL2Java tool

Page 17: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

HelloWorldService.java – Service Interface

• Generated by the WSDL2Java tool

Page 18: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

HelloWorldServiceLocator.java - part 1

implementation of the interfaceimplementation of the interface

More code to followMore code to follow

Hot wired address – from where?Hot wired address – from where?

standard getHelloWorld impl takes hot wired addressstandard getHelloWorld impl takes hot wired address

Calls the getHelloWorld(endpoint)Calls the getHelloWorld(endpoint)

Page 19: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

HelloWorldServiceLocator.java - part 2

If you want to implement a naming service a different accessor is providedIf you want to implement a naming service a different accessor is provided

It returns a proxy stub – which is also generated – the HelloWorldSoapBindingStubIt returns a proxy stub – which is also generated – the HelloWorldSoapBindingStub

More code is generated – but not shown hereMore code is generated – but not shown here

The remaining code is not commented further – take a closer look for yourselfThe remaining code is not commented further – take a closer look for yourself

Page 20: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

HelloWorldSoapBindingStub.java – the stub - part 1

Extending stub and implementing the interfaceExtending stub and implementing the interface

Only excerpts of the code have been shown on these slidesOnly excerpts of the code have been shown on these slides

Page 21: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

HelloWorldSoapBindingStub.java – the stub - part 2

Implementing the marshalling – compare this to the dynamic client we made earlier on, or your UDP assignment!Implementing the marshalling – compare this to the dynamic client we made earlier on, or your UDP assignment!

We are using the call objectWe are using the call object

Only excerpts of the code have been shown on these slidesOnly excerpts of the code have been shown on these slides

To invoke the method on the serverTo invoke the method on the server

Page 22: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Axis Life-Cycle Management for Web Services

• Web service scope specifies the lifetime/management of the service class. • request - has the same effect as if a new service object is

created to handle each method call. • Request is the default scope - provides scalability in high-

capacity load-balanced applications. Connections and/or server objects can be pooled.

• session - conceptually, all requests from a single client are handled by a single object. Implemented with cookies, and requires client support.

• application - a singleton web service. A single object serves all clients.

• Using application scope for a Java Web Service and Client • The deploy.wsdd specifies application scope for the Web

Service<parameter name="scope" value="application"/>

Page 23: Presentation: Advanced AXIS: Deployment Descriptors and Advanced Types

Using Session Scope with Axis

• Using the session scope for a Java Web Service and Client • For example, count all calls made to a service by a single

client. • Each client has its own call count -- in effect, has its own

service object. • The deploy.wsdd specifies session scope for the Web

Service<parameter name="scope" value="session"/>

• For session scope to work, the web service client must also specify a session mechanism • In C# as: tcs.CookieContainer = new

System.Net.CookieContainer(); • Java Proxy as:

((MyWSServiceLocator)tcs).setMaintainSession(true);