Jared Zebedee - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Jared Zebedee

Description:

Building Web Services with Apache AXIS. Anatomy of a Web Services Implementation ... package localhost.axis.Calculator_jws; public class Client ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 24
Provided by: jar53
Category:

less

Transcript and Presenter's Notes

Title: Jared Zebedee


1
Jared Zebedee Queens Database Systems Laboratory
2
  • Anatomy of a Web Services Implementation
  • Building a Service
  • Deploying the Service
  • Building a Client

3
(No Transcript)
4
  • Anatomy of a Web Services Implementation
  • Building a Service
  • Deploying the Service
  • Building a Client

5
  • Web Services can built in any language that a
    SOAP engine supports
  • Apache Axis is currently available in Java and
    C implementations
  • Services written for Axis should be easily
    portable to other SOAP engines

Process Step 1 Write the Code Step 2 Deploy
the Service Step 3 Test
6
Step 1 Writing the Code
Source code for a simple Calculator Web Service
public class Calculator public int
add(int i1, int i2) return i1 i2
public int subtract(int i1, int i2)
return i1 - i2
7
Step 2 Deploying the Service
In AXIS there are two ways to deploy a Web Service
  • Method 1 (Instant Deployment)
  • Change the source file extension from .java
    to .jws
  • Copy the source file into the AXIS
    installation folder
  • Done!

8
Step 2 Deploying the Service (continued)
  • Method 2 (Custom Deployment)
  • Create a WSDD file (Web Service Deployment
    Descriptor)
  • Add deployment parameters to WSDD file (in XML
    format)
  • Use AXIS AdminClient to process the WSDD file
    and deploy the service

java org.apache.axis.client.AdminClient
filename.wsdd
9
Step 2 Deploying the Service (continued)
Example WSDD file for the Calculator Web
Service
ltdeployment xmlns"http//xml.apache.org/axis/wsd
d/" xmlnsjava"http//xml.apache.org/axis/wsdd
/providers/java"gt ltservice nameCalculator"
provider"javaRPC"gt ltparameter
name"className" value"samples.userguide.exa
mple3.MyService"/gt ltparameter
name"allowedMethods" value""/gt lt/servicegt lt/d
eploymentgt
10
Step 2 Deploying the Service (continued)
Advanced WSDD Parameters
  • These are additional options that can be
    specified in the WSDD file
  • They are optional!

Scoped Services
  • AXIS instantiates Web Service objects using one
    of the following three Scope levels
  • Request Scope A new object is created each
    time a SOAP request comes in.
  • Session Scope A separate object is created
    for each connected client.
  • Application Scope A single object is
    created for all connections.
  • The default Scope level is Request.

11
Step 2 Deploying the Service (continued)
Advanced WSDD Parameters (continued)
Handlers and Chains
AXIS can invoke a Handler each time a Web Service
receives a SOAP requestor sends a SOAP response.
A Handler is just another program that
performsan action such as monitoring or logging.
This feature is completely optional.
Remote Administration
By default, AXIS only allows administration on
the local machine. The remote administration
option applies only to the AdminService Web
Service, and can be enabled by modifying the
server-config.wsdd file.
12
Step 2 Deploying the Service (continued)
Advanced WSDD Parameters (continued)
Service Styles
  • AXIS supports four different styles of service.
    These styles reflect the type of encodingthat
    AXIS performs on the XML documents being
    transferred.
  • RPC (remote procedure call) services
    This is the default in AXIS, and the standard
    encoding style used for Web Services. RPC
    services follow the SOAP encoding rules to
    translate between XML and data objects.
  • Document and Wrapped services Document
    and Wrapped Services translate between XML and
    data objects, but they do not use SOAP
    encoding rules. Instead, the translation is done
    directly between XML and the data objects.
  • Message Services
  • Message Services are used when a developer
    wants to access the XML data directly.
    They do not perform any translation between data
    objects and XML.

13
Step 3 Testing
Once the Web Service is properly deployed, it can
be accessed directly using any Web Browser. This
is a good way to test the Service.Example
Testing the Calculator Service For our
Calculator service we Deployed using Instant
Deployment The URL is http//largo.cs.queensu.c
a8080/axis/Calculator.jws For the Calculator
Service we Deployed using Custom Deployment The
URL is http//largo.cs.queensu.ca8080/axis/servi
ces/Calculator
14
Step 3 Testing (continued)
In a similar manner, we can test the methods that
the Web Service Provides. We see the raw XML,
SOAP packaged response in the browser
This URL tests the add method in the Instantly
Deployed version
http//largo.cs.queensu.ca8080/axis/Calculator.jw
s?methodaddp12p23
This URL tests the subtract method in the
Custom Deployed version
http//largo.cs.queensu.ca8080/axis/services/Calc
ulator?methodsubtractp12p23
15
  • Anatomy of a Web Services Implementation
  • Building a Service
  • Deploying the Service
  • Building a Client

16
  • Weve seen how to Build and Test a Web Service
    with Apache AXIS.
  • How do we Build a Client that can Connect to
    it and Access its methods?

Process Step 1 Locate the Service (UDDI) Step
2 Obtain WSDL Document Step 3 Generate
Stubs Step 4 Write the Client Code Step 5 Test
17
Step 1 Locating the Service
  • Use a UDDI repository to locate the Service you
    want to build a Client for.
  • Covering this step in further detail would be
    beyond the Scope of this
  • Presentation. Lets assume weve already
    located the Service.

Step 2 Obtaining the Services WSDL document
  • AXIS automatically generates WSDL documents for
    its deployed Web Services

http//largo.cs.queensu.ca8080/axis/services/Calc
ulator?wsdl
  • Other SOAP engines may not generate WSDL
    documents the same way AXIS does. However,
    Web Service Providers will generally make their
    WSDL files
  • available to developers who wish to create
    Clients.

18
Step 3 Generating Stubs
  • The WSDL file contains the information needed
    to build a Client for the Web Service. The
    developer can examine the WSDL directly and code
    a Client from scratch, or use a utility which
    creates Client Stubs. The Stubs provide a
    neatly packaged interface to the Web Service, and
    save the Client developer a lot of work.
  • We will look at the Stub method of Building a
    Client it is much simpler than building a
    Client from scratch.
  • AXIS comes with a utility called WSDL2Java,
    which generates Stubs from any valid WSDL
    document.

Invoking WSDL2JAVA on the Calculator Web
Services WSDL Document
java org.apache.axis.wsdl.WSDL2Java
Calculator.wsdl
19
Step 3 Generating Stubs (continued)
  • The WSDL2Java utility creates four Stub
    classes their filenames are prefixed with
    the Web Service name.
  • Calculator.java This is the "remote"
    interface. Extends Remote and includes methods
    from the original
    Calculator.java.
  • CalculatorService.java Service interface of
    the Web Services. The ServiceLocator
    implements this interface.
  • CalculatorServiceLocator.java Helper factory
    for retrieving a handle to the service.
  • CalculatorSoapBindingStub.java Client-side
    stub code that encapsulates client
  • access.

20
Step 4 Writing the Client Code
Using the Stubs it is very easy to build a simple
Client.
package localhost.axis.Calculator_jws public
class Client public static void main(String
args) throws Exception CalculatorService
calc new CalculatorServiceLocator() Calculato
r port calc.getCalculator() System.out.print
ln("5 8 " port.add(5,8)) System.out.
println("7 - 4 " port.subtract(7,4))

21
Step 5 Testing the Client
Testing the Client is simply a matter of
compiling and executing it.
javac localhost\axis\Calculator_jws\.java java
localhost.axis.Calculator_jws.Client 5 8
13 7 - 4 3
22
Demo
23
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com