Title: Deploying Web Services with AXIS
1Deploying Web Services with AXIS
- Representation and Management of Data on the Web
2Web Services
- Web services are methods that a remote
application can call - The methods are invoked through usual Web
protocols (e.g., HTTP) - Calling a method
- Discovery (UDDI)
- Description (WSDL)
- Invocation (SOAP)
3What is AXIS
- Axis is essentially a SOAP engine a framework
for constructing SOAP processors such as clients,
servers, gateways - AXIS implements the interfaces of JAX-RPC
(remote procedure calls in Java, using XML) - AXIS Apache EXtensible Interaction System
4Remote Method Invocation is not a New Idea
- java.rmi has been in Java since Javas early
versions - In Java RMI, objects can invoke methods of
objects that reside on a remote computer (RMI
Remote Method Invokation) - So, what has been changed
- Using HTTP and port 80 we can bypass the firewall
- Using agreed protocols, Java can invoke methods
that were not written in Java (e.g., .NET
methods) and vice versa - A complex registry procedure has been required in
RMI
5AXIS Includes
- Axis isn't just a SOAP engine it also includes
- a simple stand-alone server
- a server which plugs into servlet engines such as
Tomcat - extensive support for the Web Service Description
Language (WSDL) - emitter tooling that generates Java classes from
WSDL - a tool for monitoring TCP/IP packets
6AXIS Installation
- AXIS works inside a Servlet container (e.g.,
Tomcat) - You should add to your Tomcat libs some jar
files axis.jar, saaj.jar, wsdl4j.jar, - You need to include several jar files in your
CLASSPATH - This has already been done for you
- The needed CLASSPATH definitions where added to
dbi.cshrc - The needed jar files were added to
CATALINA_BASE/shared/lib/
7Working With AXIS
- AXIS uses Servlets that Tomcat apply
- You should copy the axis directory from dbi to
your webapps directory - cp r dbi/tomcat/axis CATALINA_BASE/webapps/
CATALINA_BASE
webapps
shared
friendsnet
axis
lib
classes
8(No Transcript)
9What We Would Like to Create
- Client applications applications that can call
a remote service - Services methods that can be called by remote
applications - Service descriptions WSDL files that describe
our methods
10Will We Do a Lot of XML Parsing?
- You will not directly read or write SOAP messages
- Instead, use Java methods that create request and
analyze result - Use the AxisServlet that actually includes a SOAP
processor - Code the Client Application and the Service
Application
11A Client in a Web Service
Web Server
12A Client in a Web Service
Web Server
13Creating a Client
- Create a Service object
- Create a Call object
- Set the endpoint URL, i.e., the destination for
the SOAP message - Define the operation (method) name of the Web
Service - Invoke the desired service, passing in an array
of parameters
14A Simple Client Example
- import org.apache.axis.client.Call
- import org.apache.axis.client.Service
- import javax.xml.namespace.QName
- public class TestClient
- public static void main(String args)
- try
- String endpoint "http//nagoya.apac
he.org5049/axis/services/echo" -
- Service service new Service()
- Call call (Call)
service.createCall()
15A Simple Client Example
-
- call.setTargetEndpointAddress( new
java.net.URL(endpoint) ) - call.setOperationName(new
QName("http//soapinterop.org/",
"echoString")) - String ret (String) call.invoke( new
Object "Hello!" ) -
- System.out.println("Sent 'Hello!',
got '" ret "'") - catch (Exception e)
- System.err.println(e.toString())
-
-
16- POST http//nagoya.apache.org5049/axis/services/e
cho HTTP/1.0 - Content-Type text/xml charsetutf-8
- Accept application/soapxml, application/dime,
multipart/related, text/ - User-Agent Axis/1.1
- Host nagoya.apache.org5049
- Cache-Control no-cache
- Pragma no-cache
- SOAPAction ""
- Content-Length 461
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltsoapenvEnvelope xmlnssoapenv"http//schemas.xm
lsoap.org/soap/envelope/" xmlnsxsd"http//www.w3
.org/2001/XMLSchema" xmlnsxsi"http//www.w3.org/
2001/XMLSchema-instance"gt - ltsoapenvBodygt
- ltns1echoString soapenvencodingStyle"http//sc
hemas.xmlsoap.org/soap/encoding/"
xmlnsns1"http//soapinterop.org/"gt - ltns1arg0 xsitype"xsdstring"gtHello!lt/ns1arg
0gt - lt/ns1echoStringgt
- lt/soapenvBodygt
The HTTP Request
17Example A Client that Uses WSDL
- We create an application that calls a remote Web
service - In our example the remote Web service produces
prime numbers in a given range - The service is in URL http//www.jusufdarmawan.com
/wsprimegenerator.exe/wsdl/IPrimeGenerator
18The WSDL of the Service
lt?xml version"1.0" ?gt ltdefinitions
xmlns"http//schemas.xmlsoap.org/wsdl/"
xmlnsxs"http//www.w3.org/2001/XMLSchema"
name"IPrimeGeneratorservice"
targetNamespace"http//www.borland.com/soapServic
es/" xmlnstns"http//www.borland.com/soapServ
ices/" xmlnssoap"http//schemas.xmlsoap.org/
wsdl/soap/" xmlnssoapenc"http//schemas.xmlso
ap.org/soap/encoding/"gt ltmessage
name"primegeneratorRequest"gt ltpart
name"valstart" type"xsstring" /gt Â
ltpart name"valend" type"xsstring" /gt Â
lt/messagegt ltmessage name"primegeneratorResponse
"gt ltpart name"return" type"xsstring"
/gt  lt/messagegt
19ltportType name"IPrimeGenerator"gt
ltoperation name"primegenerator"gtÂ
ltinput message"tnsprimegeneratorRequest" /gt Â
ltoutput message"tnsprimegeneratorRespon
se" /gt  lt/operationgt lt/portTypegt
String primegenerator(String valstart, String
valend)
Defining the function
20ltbinding name"IPrimeGeneratorbinding"
type"tnsIPrimeGenerator"gt ltsoapbinding
style"rpc"
transport"http//schemas.xmlsoap.org/soap/http"
/gt ltoperation name"primegenerator"gtÂ
ltsoapoperation soapAction"urnUnitIPrimeGe
nerator-IPrimeGeneratorprimegenerator" /gt
ltinputgt ltsoapbody use"encoded"
encodingStyle"http//schemas.xm
lsoap.org/soap/encoding/"
namespace"urnUnitIPrimeGenerator-IPrimeGenerator
" /gt  lt/inputgt ltoutputgtÂ
ltsoapbody use"encoded"
encodingStyle"http//schemas.xmlsoap.org/soap/en
coding/" namespace"urnUnitIPr
imeGenerator-IPrimeGenerator" /gt Â
lt/outputgt lt/operationgt lt/bindinggt
Binding the method as an RPC
21 ltservice name"IPrimeGeneratorservice"gt
ltport name"IPrimeGeneratorPort"
binding"tnsIPrimeGeneratorbinding"gtÂ
ltsoapaddress location"http//www.jusufdarmawan
.com/wsprimegenerator.
exe/soap/IPrimeGenerator" /gt  lt/portgtÂ
lt/servicegt lt/definitionsgt
The Service URL
22The Client Source Code
- import org.apache.axis.client.Call
- import org.apache.axis.client.Service
- import javax.xml.namespace.QName
- import java.net.URL
- public class PrimeGenerator
- public static void main(String argv)
- try
-
- / Set the porxy parameters /
- System.setProperty("http.proxyHost",
"wwwproxy.huji.ac.il") - System.setProperty("http.proxyPort",
"8080")
23-
- / Set the service parameters /
- String defaultNS null
- String endpoint null
- URL wsdl new URL("http//www.jusufda
rmawan.com/ - wsprimegenerator.exe/wsdl/IPri
meGenerator") - QName serviceName new
- QName("http//www.borland.com/soapServices/",
- "IPrimeGeneratorservice")
- String method "primegenerator"
- String port "IPrimeGeneratorPort"
-
- / Set the service arguments /
- String start "200"
- String end "300"
24-
- / Invoke the service /
- Service service new Service(wsdl,
serviceName) - Call call (Call) service.createCall(
new - QName(port),
- new QName(method))
- String value (String)call.invoke(new
Object start, end ) -
- System.out.println("Primes between "
start " and " - end
" " value) -
- catch (Exception exp)
- exp.printStackTrace(System.err)
-
-
25(No Transcript)
26The HTTP Request
POST /wsprimegenerator.exe/soap/IPrimeGenerator
HTTP/1.0 content-typetext/xml
charsetutf-8 acceptapplication/soapxml,
application/dime, multipart/related,
text/ user-agentAxis/1.1 hostwww.jusufdarmawan.
com cache-controlno-cache pragmano-cache soapact
ion"urnUnitIPrimeGenerator-IPrimeGeneratorprime
generator" content-length540 -- empty line --
27 lt?xml version"1.0" encoding"UTF-8"?gt ltsoapenvE
nvelope xmlnssoapenv"http//schemas.xmlsoap.org/
soap/envelope/" xmlnsxsd"http//www.w3.org/2001/
XMLSchema" xmlnsxsi"http//www.w3.org/2001/XMLSc
hema-instance"gt ltsoapenvBodygt
ltns1primegenerator soapenvencodingStyle"http/
/schemas.xmlsoap.org/soap/encoding/"
xmlnsns1"urnUnitIPrimeGenerator-IPrimeGenerat
or"gt ltvalstart xsitype"xsdstring"gt200lt/valst
artgt ltvalend xsitype"xsdstring"gt300lt/valendgt
lt/ns1primegeneratorgt lt/soapenvBodygt lt/soapen
vEnvelopegt
28The HTTP Response
HTTP/1.0 200 OK Date Tue, 08 Jun 2004 201016
GMT Content-Length 603 Content-Type
text/xml Server Microsoft-IIS/5.0 X-Powered-By
ASP.NET Content Via 1.1 proxy7 (NetCache
NetApp/5.5R4)
29lt?xml version"1.0" encoding'UTF-8'?gt ltSOAP-ENVE
nvelope xmlnsSOAP-ENV"http//schemas.xmlsoap.o
rg/soap/envelope/" xmlnsxsd"http//www.w3.org/2
001/XMLSchema" xmlnsxsi"http//www.w3.org/2001/
XMLSchema-instance" xmlnsSOAP-ENC"http//schema
s.xmlsoap.org/soap/encoding/"gt ltSOAP-ENVBodygt
ltNS1primegeneratorResponse
xmlnsNS1"urnUnitIPrimeGenerator-IPrimeGenerator
" SOAP-ENVencodingStyle"http//schemas.
xmlsoap.org/soap/encoding/"gt ltreturn
xsitype"xsdstring"gt 211, 223, 227,
229, 233, 239, 241, 251, 257, 263, 269, 271, 277,
281, 283, 293lt/returngt
lt/NS1primegeneratorResponsegt
lt/SOAP-ENVBodygt lt/SOAP-ENVEnvelopegt
30Service
- Service()
- the constructor assumes that the caller will set
the appropriate fields by hand rather than
getting them from the WSDL - Service(java.io.InputStream wsdlInputStream,
- QName serviceName)
- Constructs a new Service object for the service
in the WSDL document in the wsdlInputStream and
serviceName parameters
31Creating a Call
- Â Call createCall()
- Creates a new Call object with no prefilled data
-  Call createCall(QName portName,
QName operationName)      - Creates a new Call object - will prefill as much
info from the WSDL as it can
32Call
- Used to actually invoke the Web service
- You can invoke the operation associated with the
call using invoke() - invoke(Object params)
- Invokes the operation associated with the call
using the passed in parameters as the arguments
to the method
33Setting Types
- You can set parameters using the method
addParamether() - You can set the returned type using
setReturnedType()
call.addParameter("testParam", org.apache.axis.Co
nstants.XSD_STRING, javax.xml.rpc.ParameterMode
.IN) call.setReturnType(org.apache.axis.Constant
s.XSD_STRING)
34Creating a Service
- There is a fast and easy way of crating a
service - Create a Java class myClass.java
- Rename your class to end with jws myClass.jws
- Put the jws file under the directory
CATALINA_BASE/webapps/axis/ - That is all. Now you can call the service!
35Example a Calculator Service
- public class SimpleCalculator
- public int add(int i1, int i2)
-
- return i1 i2
-
- public int subtract(int i1, int i2)
-
- return i1 - i2
-
-
We rename the file SimpleCalculator.jws We put
the file under webapps/axis
36http//computer-that-runs-tomcatport/axis/SimpleC
alculator.jws
37The Client For the Calculator
- import org.apache.axis.client.Call
- import org.apache.axis.client.Service
- import org.apache.axis.encoding.XMLType
- import org.apache.axis.utils.Options
- import javax.xml.rpc.ParameterMode
- public class SimpleCalcClient
- public static void main(String args) throws
Exception - String endpoint "http//mangal.cs.huji.ac
.il8999/axis/SimpleCalculator.jws" -
- if (args null args.length ! 3)
- System.err.println("Usage
SimpleCalcClient ltaddsubtractgt arg1 arg2") - return
-
- String method args0
- if (!(method.equals("add")
method.equals("subtract"))) - System.err.println("Usage CalcClient
ltaddsubtractgt arg1 arg2") - return
-
38-
- Integer i1 new Integer(args1)
- Integer i2 new Integer(args2)
- Service service new Service()
- Call call (Call)
service.createCall() - call.setTargetEndpointAddress( new
java.net.URL(endpoint) ) - call.setOperationName( method )
- call.addParameter( "op1", XMLType.XSD_INT,
ParameterMode.IN ) - call.addParameter( "op2", XMLType.XSD_INT,
ParameterMode.IN ) - call.setReturnType( XMLType.XSD_INT )
- Integer ret (Integer) call.invoke( new
Object i1, i2 ) -
- System.out.println("Got result " ret)
-
39Tomcat
CATALINA_BASE
webapps
shared
friendsnet
axis
lib
classes
WEB-INF
jwsClasses
classes
AxisServlet.class
40Tomcat
CATALINA_BASE
webapps
shared
friendsnet
axis
lib
classes
WEB-INF
jwsClasses
classes
AxisServlet.class
41Tomcat
CATALINA_BASE
webapps
shared
friendsnet
axis
lib
classes
WEB-INF
jwsClasses
classes
AxisServlet.class
- The class SimpleCalculator is compiled and
dynamically loaded - The SOAP request is parsed and analyzed
- A response is created by the SimpleCalculator
- The result is wrapped as a SOAP response an
returned to the caller
5
HTTP Response
42When not to Use jws Files
- When you do not have the Java source code
- When you dont want to expose your code
- When you want to use custom type mappings
- When you want to use other configuration options
43 AxisServlet
- Dealing with service calls is done by AxisServlet
- The following files are mapped to AxisServlet (in
web.xml of the axis application directory) - servlet/AxisServlet
- .jws
- services/
44Deploying Services
- When a service is called, the AxisServlet must
know where to look for the application - Telling where the application can be found is
called "deploying" - Deploying is a two-step process
- Create a deployment descriptor file
- Call the java command that deploys the web
application
java org.apache.axis.client.AdminClient -p port
deploy-file.wsdd
45Creating a Service
- Create a Java class
- Compile the class
- Put the class under
axis/WEB-INF/classes/the-package-name/ - Create a deployment descriptor file mydeploy.wsdd
- Call the AdminClient Service with the deployment
file as a parameter (in the computer where Tomcat
runs AXIS) - You are done and can call the service!
46Example A Power Function
- We create a service that computes the power of
two numbers - We show how to deploy the service
- We demonstrate the service with a client that
calls the service
47The Service Code
- package dbi
- public class PowerService
- public int power(int a, int n)
- return (int)Math.pow(a,n)
-
-
48Deployment File
- ltdeployment xmlns"http//xml.apache.org/axis/wsdd
/" xmlnsjava"http//xml.apache.org/ax
is/wsdd/providers/java"gt - ltservice name"dbiPowerService"
provider"javaRPC"gt - ltparameter name"className"
value"dbi.PowerService"/gt - ltparameter name"scope"
value"application"/gt - ltparameter name"allowedMethods"
value""/gt - lt/servicegt
- lt/deploymentgt
We call the file dbideploy.wsdd
java org.apache.axis.client.AdminClient -p8090
dbideploy.wsdd
After deployment you can call the service
49A Client that Calls the Power Service
- import org.apache.axis.client.Call
- import org.apache.axis.client.Service
- import javax.xml.namespace.QName
- public class PowerClient
- private static final String host
"mangal.cs.huji.ac.il" - private static final int port 8090
- public static void main(String argv)
- try
- int x2, n5
-
- String endpoint "http//" host
"" port -
"/axis/services/dbiPowerService"
50- call call (Call) new Service().createCal
l() - call.setTargetEndpointAddress(new
java.net.URL(endpoint)) - call.setOperationName("power")
- Integer value (Integer)call.invoke(n
ew Object - new Integer(x), new Integer(n)
- )
-
- System.out.println(x""n ""
value) - catch (Exception exp)
- exp.printStackTrace(System.err)
-
-
Is it important from which directory I call the
client? Is it important from which computer I
call the client?
51The HTTP Request
- POST /axis/services/dbiPowerService HTTP/1.0
- content-typetext/xml charsetutf-8
- acceptapplication/soapxml, application/dime,
multipart/related, text/ - user-agentAxis/1.1
- hostmangal.cs.huji.ac.il8090
- cache-controlno-cache
- pragmano-cache
- soapaction""
- content-length499
52- lt?xml version"1.0" encoding"UTF-8"?gt
- ltsoapenvEnvelope
- xmlnssoapenv"http//schemas.xmlsoap.org/soap/en
velope/" xmlnsxsd"http//www.w3.org/2001/XMLSche
ma" - xmlnsxsi"http//www.w3.org/2001/XMLSchema-insta
nce"gt - ltsoapenvBodygt
- ltns1power
- soapenvencodingStyle"http//schemas.xm
lsoap.org/soap/encoding/" - xmlnsns1"http//dbi/"gt
- ltns1arg0 xsitype"xsdint"gt2lt
/ns1arg0gt - ltns1arg1 xsitype"xsdint"gt5lt
/ns1arg1gt - lt/ns1powergt
- lt/soapenvBodygt
- lt/soapenvEnvelopegt
53The HTTP Response
- HTTP/1.1 200 OK
- Content-Type text/xmlcharsetutf-8
- Date Sat, 05 Jun 2004 180002 GMT
- Server Apache-Coyote/1.1
- Connection close
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltsoapenvEnvelope
- xmlnssoapenv"http//schemas.xmlsoap.org/soap/en
velope/" - xmlnsxsd"http//www.w3.org/2001/XMLSchema"
xmlnsxsi"http//www.w3.org/2001/XMLSchema-instan
ce"gt - ltsoapenvBodygt
- ltns1powerResponse soapenvencodingStyle"http/
/schemas.xmlsoap.org/soap/encoding/" - xmlnsns1"http//dbi/"gt
- ltns1powerReturn xsitype"xsdint"gt32lt/ns1pow
erReturngt - lt/ns1powerResponsegt
- lt/soapenvBodygt
- lt/soapenvEnvelopegt
54The WSDL (1)
- ltwsdldefinitions targetNamespace"http//mangal.c
s.huji.ac.il8090/axis/services/dbiPowerService"gt - ltwsdlmessage name"powerResponse"gt
- ltwsdlpart name"powerReturn" type"xsdint"/gt
- lt/wsdlmessagegt
- ltwsdlmessage name"powerRequest"gt
- ltwsdlpart name"in0" type"xsdint"/gt
- ltwsdlpart name"in1" type"xsdint"/gt
- lt/wsdlmessagegt
- ltwsdlportType name"PowerService"gt
- ltwsdloperation name"power" parameterOrder"in0
in1"gt - ltwsdlinput message"implpowerRequest"
name"powerRequest"/gt - ltwsdloutput message"implpowerResponse"
name"powerResponse"/gt - lt/wsdloperationgt
- lt/wsdlportTypegt
55The WSDL (2)
- ltwsdlbinding name"dbiPowerServiceSoapBinding"
type"implPowerService"gt - ltwsdlsoapbinding style"rpc"
transport"http//schemas.xmlsoap.org/soap/http"/gt
- ltwsdloperation name"power"gt
- ltwsdlsoapoperation soapAction""/gt
- ltwsdlinput name"powerRequest"gt
- ltwsdlsoapbody encodingStyle"http
//schemas.xmlsoap.org/soap/encoding/"
namespace"http//dbi" use"encoded"/gt - lt/wsdlinputgt
- ltwsdloutput name"powerResponse"gt
- ltwsdlsoapbody encodingStyle"http
//schemas.xmlsoap.org/soap/encoding/"
- namespace"http//mangal.cs.huji.ac.il8090/axis
/services/dbiPowerService" use"encoded"/gt - lt/wsdloutputgt
- lt/wsdloperationgt
- lt/wsdlbindinggt
56The WSDL (3)
-
- ltwsdlservice name"PowerServiceService"gt
- ltwsdlport binding"impldbiPowerServiceSoapB
inding" name"dbiPowerService"gt - ltwsdlsoapaddress location"http//mangal.cs.hu
ji.ac.il8999/axis/services/dbiPowerService"/gt - lt/wsdlportgt
- lt/wsdlservicegt
- lt/wsdldefinitionsgt
57Deployment File
- ltdeployment xmlns"http//xml.apache.org/axis/wsdd
/" xmlnsjava"http//xml.apache.org/ax
is/wsdd/providers/java"gt - ltservice name"dbiPowerService"
provider"javaRPC"gt - ltparameter name"className"
value"dbi.PowerService"/gt - ltparameter name"scope"
value"application"/gt - ltparameter name"allowedMethods"
value""/gt - lt/servicegt
- lt/deploymentgt
Required namespaces Saying that this is a
deployment file of axis
58Deployment File
- ltdeployment xmlns"http//xml.apache.org/axis/wsdd
/" xmlnsjava"http//xml.apache.org/ax
is/wsdd/providers/java"gt - ltservice name"dbiPowerService"
provider"javaRPC"gt - ltparameter name"className"
value"dbi.PowerService"/gt - ltparameter name"scope"
value"application"/gt - ltparameter name"allowedMethods"
value""/gt - lt/servicegt
- lt/deploymentgt
The name of the service
The service is an RPC (not document)
59Deployment File
- ltdeployment xmlns"http//xml.apache.org/axis/wsdd
/" xmlnsjava"http//xml.apache.org/ax
is/wsdd/providers/java"gt - ltservice name"dbiPowerService"
provider"javaRPC"gt - ltparameter name"className"
value"dbi.PowerService"/gt - ltparameter name"scope"
value"application"/gt - ltparameter name"allowedMethods"
value""/gt - lt/servicegt
- lt/deploymentgt
60The Scope of the Object
- Request (the default) a new object is created
for each request, the service instance is
available for the duration of the request,
regardless of forwarding - Session a new object is created for each new
session and the service instance is available for
the entire session - Application a singleton shared service instance
is used to serve all invocations
61Undeployment of Services
- ltundeployment xmlns"http//xml.apache.org/axis/ws
dd/"gt - ltservice namedbiPowerService"/gt
- lt/undeploymentgt
We call this file dbiundeploy.wsdd
java org.apache.axis.client.AdminClient -p8090
dbiundeploy.wsdd
After undeployment you cannot call the service
anymore
62Service Styles
- RPC a call according to SOAP RPC conventions
- Document do not use encoding but maps XML to
Java types - Wrapped similar to document, except that they
unwrap the body to individual parameters - Message the services and returns raw XML in the
SOAP envelop, I.e., no type mappings or data
bindings
63Standard mappings from WSDL to Java
- xsdbase64Binary byte
- xsdboolean boolean
- xsdbyte byte
- xsddateTime
java.util.Calendar - xsddecimal
java.math.BigDecimal - xsddouble double
- xsdfloat float
- xsdhexBinary byte
- xsdint int
- xsdinteger
java.math.BigInteger - xsdlong long
- xsdQname javax.xml.namespace
.QName - xsdshort short
- xsdstring java.lang.String
64Note on Parameters
- It must be possible to "serialize" the parameters
that the method invoked receives and returns.
Why? - The following have default serialization/deseriali
zation - primitive types int, long, double, etc.
- primitive Objects Integer, Long, Double, String,
etc. - complex Objects Vector, Enumeration, Hashtable,
arrays - easy to use JavaBeans (not discussed here)
65Remote Exceptions
- When you call a Java method an exception can be
thrown - Consider a case where a client supplies a bad
argument and an exception occurs in the server
(while handling the service call) - What should happen?
66AXIS Support of WSDL
- When you deploy a service in Axis, users may then
access your service's URL with a standard web
browser and by appending "?WSDL" to the end of
the URL - AXIS provides a "WSDL2Java" tool which builds
Java proxies and skeletons for services with WSDL
descriptions - AXIS provides a "Java2WSDL" tool which builds
WSDL from Java classes
67WSDL2Java Mappings
- WSDL clause Java class(es)
generated - For each entry in the A java class
- type section
- A holder
if this type is - used as an inout/out parameter
- For each portType A java interface
- For each binding A stub class
- For each service A service interface
- A service
implementation - (the
locator)
68Using Reflection for Implementing Web Services
69How Could a SOAP Processor be Implemented?
- No, we won't be implementing a SOAP Processor in
this course ? - However, it could be implemented using reflection
- Reflection is a Java mechanism for discovering
the class/methods/fields of an object - Reflection allows you to load classes and invoke
methods
70Simple SOAP Implementation
- In SOAP, the details about the RPC are in an XML
message - In our Simple SOAP Implementation example,
details will be in parameters of HTTP request - We will allow user to invoke any method of any
class, provided that the method only has String
arguments - All this is to give us an idea of how a SOAP
processor works
71Getting Invocation Details from Client (HTML Form)
- ltform name"info" method"get" action"servlet/SOA
PImitation"gt - Class Name ltinput type"text" name"class"gtltbrgt
- Method Name ltinput type"text"
name"method"gtltbrgt - ltinput type"button" value"Set Number of
Arguments" onClick"setArguments()"gt - ltinput type"hidden" name"paramNum" value"0"gt
- ltp id "argumentP"gtlt/pgt
- ltinput type"submit"gt
- lt/formgt
72Getting Invocation Details from Client (HTML Form)
- function setArguments()
- num prompt("Enter the number of arguments to
the method", 0) - p document.getElementById("argumentP")
- str ""
- for (i 0 i lt num i)
- str "Argument " i " "
- "ltinput type'text' name'param"
i "'gtltbrgt" -
- p.innerHTMLstr
- info.paramNum.valuenum
73Our Simple SOAP Processor
- import java.io. import javax.servlet. import
javax.servlet.http. - import java.lang.reflect.
- public class SoapImitation extends HttpServlet
- public void doGet(HttpServletRequest req,
- HttpServletResponse res)
- throws ServletException, IOException
- res.setContentType("text/html")
- PrintWriter out res.getWriter()
-
- try
- Class objClass Class.forName(req.getParamet
er("class")) - int numParams Integer.parseInt(req.getParame
ter("paramNum")) -
74- Class paramClasses new ClassnumParams
- Object paramObjs new ObjectnumParams
- for (int i 0 i lt numParams i)
- paramClassesi Class.forName("java.lang.Strin
g") - paramObjsi req.getParameter("param" i)
-
-
- Method method
- objClass.getMethod(req.getParameter("method"),
- paramClasses)
- Object result method.invoke(objClass.newIns
tance(), paramObjs) - out.println("ltHTMLgtltBODYgtlth1gtMethod
Resultlt/h1gt" - result "lt/BODYgtlt/HTMLgt")
- catch (Exception e)
- out.println("ltHTMLgtltBODYgtError!lt/BODYgtlt/HTMLgt
") -
75A Class and a Method
package hello public class HelloServer
public String sayHelloTo(String name)
Return(new String(Hello name , How are
you doing?)
76(No Transcript)
77(No Transcript)
78Scoping
- What did the scoping of the Web Service
correspond to (request?, session?, application?) - How would the implementation differ if the
scoping was different?
79When Web Application Need to Share Information
- In your implementation of the friendsnet Web
application you will create instances of the
class FriendsDatabase - Where is the login for accessing the database is
taken from? - If you will have a service under axis, will the
service be able to create a FriendsDatabase
instance that includes the login parameter?
80A Possible Solution
CATALINA_BASE
webapps
shared
friendsnet
axis
lib
classes
- Put the FriendsDatabase class under shared
- Use a static field of FriendsDatabase to hold the
login argument - The first time a Servlet in friendsnet creates an
instance of FriendsDatabase, this servlet sets
the login - Now, what about servlets of axis?
FriendsDatabase