eef511caee12199caf44287778552d16.ppt
- Количество слайдов: 74
Handling Web Services with Apache AXIS
Web-Service Review By Examples. . .
POST /wsprimegenerator. exe/soap/IPrime. Generator HTTP/1. 0 Content-Type: text/xml; charset=utf-8 Host: www. jusufdarmawan. com SOAPAction: "urn: Unit. IPrime. Generator-IPrime. Generator#primegenerator" Content-Length: 527 A request to <? xml version="1. 0" encoding="UTF-8"? > <soapenv: Envelope www. jusufdarmawan. com xmlns: soapenv="http: //schemas. xmlsoap. org/soap/envelope/" xmlns: xsd="http: //www. w 3. org/2001/XMLSchema" xmlns: xsi="http: //www. w 3. org/2001/XMLSchema-instance"> <soapenv: Body> <ns 1: primegenerator soapenv: encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/" xmlns: ns 1="urn: Unit. IPrime. Generator-IPrime. Generator"> <valstart xsi: type="xsd: string">12</valstart> <valend xsi: type="xsd: string">120</valend> </ns 1: primegenerator> </soapenv: Body> </soapenv: Envelope>
HTTP/1. 0 200 OK Date: Mon, 09 May 2005 20: 58: 35 GMT Content-Length: 619 Content-Type: text/xml Server: Microsoft-IIS/5. 0 X-Powered-By: ASP. NET <? xml version="1. 0" encoding='UTF-8'? > The Response <SOAP-ENV: Envelope xmlns: SOAP- ENV="http: //schemas. xmlsoap. org/soap/envelope/" xmlns: xsd="http: //www. w 3. org/2001/XMLSchema" xmlns: xsi="http: //www. w 3. org/2001/XMLSchema-instance" xmlns: SOAP-ENC="http: //schemas. xmlsoap. org/soap/encoding/"> <SOAP-ENV: Body> <NS 1: primegenerator. Response xmlns: NS 1="urn: Unit. IPrime. Generator-IPrime. Generator" SOAP-ENV: encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/"> <return xsi: type="xsd: string">13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113</return> </NS 1: primegenerator. Response> </SOAP-ENV: Body> </SOAP-ENV: Envelope>
POST /soap HTTP/1. 0 SOAPAction: "" Content-Length: 520 A request to services. xmethods. net <? xml version="1. 0" encoding="UTF-8"? > <soapenv: Envelope xmlns: soapenv="http: //schemas. xmlsoap. org/soap/envelope/" xmlns: xsd="http: //www. w 3. org/2001/XMLSchema" xmlns: xsi="http: //www. w 3. org/2001/XMLSchema-instance"> <soapenv: Body> <ns 1: get. Rate soapenv: encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/" xmlns: ns 1="urn: xmethods-Currency. Exchange"> <country 1 xsi: type="xsd: string">Euro</country 1> <country 2 xsi: type="xsd: string">Israel</country 2> </ns 1: get. Rate> </soapenv: Body> </soapenv: Envelope>
HTTP/1. 0 200 OK Date: Sat, 07 May 2005 23: 26: 21 GMT Content-Length: 492 The Response Content-Type: text/xml <? xml version='1. 0' encoding='UTF-8'? > <soap: Envelope xmlns: soap='http: //schemas. xmlsoap. org/soap/envelope/' xmlns: xsi='http: //www. w 3. org/2001/XMLSchema-instance' xmlns: xsd='http: //www. w 3. org/2001/XMLSchema' xmlns: soapenc='http: //schemas. xmlsoap. org/soap/encoding/' soap: encoding. Style='http: //schemas. xmlsoap. org/soap/encoding/'> <soap: Body> <n: get. Rate. Response xmlns: n='urn: xmethods-Currency. Exchange'> <Result xsi: type='xsd: float'>5. 5825</Result> </n: get. Rate. Response> </soap: Body> </soap: Envelope>
<? xml version="1. 0"? > <definitions name="Currency. Exchange. Service" A WSDL Example target. Namespace="http: //www. xmethods. net/sd/Currency. Exchange. Service. wsdl" xmlns: tns="http: //www. xmethods. net/sd/Currency. Exchange. Service. wsdl" xmlns: xsd="http: //www. w 3. org/2001/XMLSchema" xmlns: soap="http: //schemas. xmlsoap. org/wsdl/soap/" xmlns="http: //schemas. xmlsoap. org/wsdl/"> <message name="get. Rate. Request"> <part name="country 1" type="xsd: string"/> <part name="country 2" type="xsd: string"/> </message> <message name="get. Rate. Response"> <part name="Result" type="xsd: float"/> </message> <port. Type name="Currency. Exchange. Port. Type"> <operation name="get. Rate"> <input message="tns: get. Rate. Request" name="get. Rate"/> <output message="tns: get. Rate. Response" name="get. Rate. Response"/> </operation></port. Type>
<binding name="Currency. Exchange. Binding" type="tns: Currency. Exchange. Port. Type"> <soap: binding style="rpc" transport="http: //schemas. xmlsoap. org/soap/http"/> <operation name="get. Rate"> <soap: operation soap. Action=""/> <input name="get. Rate"> <soap: body use="encoded" namespace="urn: xmethods-Currency. Exchange" encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/"/> </input> <output name="get. Rate. Response"> <soap: body use="encoded" namespace="urn: xmethods-Currency. Exchange" encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/"/> </output> </operation> </binding> <service name="Currency. Exchange. Service"> <documentation>Returns the exchange rate between the two currencies</documentation> <port name="Currency. Exchange. Port" binding="tns: Currency. Exchange. Binding"> <soap: address location="http: //services. xmethods. net: 80/soap"/> </port> </service> </definitions>
WSDL Elements Service * Port Binding Input Output Operation * Port Type
Apache EXtensible Interaction System (Axis)
What is AXIS • Axis is essentially a SOAP engine – a framework for constructing SOAP processors - clients side - server side • Axis implements the interfaces of JAX-RPC (XML-based remote procedure calls in Java) • AXIS = Apache Extensible Interaction System
Remote Method Invocation is not a New Idea • java. rmi has been in Java since Java’s early versions • In Java RMI, objects can invoke methods of objects that reside on a remote computer - (RMI = Remote Method Invocation) • So, what has been changed? - Using HTTP for communication - 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
AXIS Includes • Axis package includes: - a simple stand-alone server - a server which plugs into servlet engines such as Tomcat - tools for Web service invocation - extensive support for the Web Service Description Language (WSDL) - emitter tooling that generates Java classes from WSDL - and more
What We Would Like to Create • Client applications: applications that can call a remote Web service • Services: methods that can be called by remote applications • Service descriptions: WSDL files that describe our methods
Client Applications
Calling Web Services • By now, we already know how to invoke a remote Web service in Java: - Open a socket to the remote server - Through the socket, send a SOAP request wrapped by a HTTP request - Parse the response (e. g. , using SAX/DOM) • However, this approach is cumbersome, and most of it can be automated
Invoking Services with Apache • Axis includes comfortable tools for managing calls to Web services • The programmer configures the request for the Web service using a friendly API - with, or without considering the WSDL • According to the configuration, a method invocation is transformed into a SOAP request that is sent to the remote server
Invoking Services with Axis • To invoke an operation of a Web service, do the following: - Construct a Service instance - Using the Service instance, generate a Call instance - Configure the Call instance - Invoke the call
Example: Currency Exchange import org. apache. axis. client. *; import javax. xml. namespace. QName; import javax. xml. rpc. Parameter. Mode; import javax. xml. rpc. encoding. XMLType; public class Currency. Exchange 1 { public static void main(String[] args) throws Exception { System. set. Property("http. proxy. Host", "wwwproxy. huji. ac. il"); System. set. Property("http. proxy. Port", "8080"); String endpoint. Url = "http: //services. xmethods. net: 80/soap"; String nsuri = "urn: xmethods-Currency. Exchange"; Service service = new Service(); Call call = (Call) service. create. Call();
Example: Currency Exchange (cont) call. set. Target. Endpoint. Address(endpoint. Url); call. set. Operation. Name(new QName(nsuri, "get. Rate")); call. add. Parameter("country 1", XMLType. SOAP_STRING, Parameter. Mode. IN); call. add. Parameter("country 2", XMLType. SOAP_STRING, Parameter. Mode. IN); call. set. Return. Type(XMLType. SOAP_FLOAT); Object ret = call. invoke(new Object[] {"Euro", "Israel"}); System. out. println(ret); } }
Using the WSDL • Axis can read a given WSDL and configure the service as much as possible from that WSDL • Instead of using the default constructor, construct the service using the following constructor: Service(String wsdl. Location, QName service. Name) • Also, supply the port to get a prefilled Call object • In this approach, you usually need to know the following about the service: - the WSDL URL, the service name, the namespace uri, the operation name and port and the expected arguments
public class Currency. Exchange 2 { public static void main(String[] args) throws Exception { System. set. Property("http. proxy. Host", "wwwproxy. huji. ac. il"); System. set. Property("http. proxy. Port", "8080"); String wsdl = "http: //www. xmethods. net/sd/2001/Currency. Exchange. Service. wsdl"; String nsuri = "http: //www. xmethods. net/sd/Currency. Exchange. Service. wsdl"; String s. Name = "Currency. Exchange. Service", String o. Name = "get. Rate"; Service service = new Service(wsdl, new QName(nsuri, s. Name)); String port = service. get. Ports(). next(). to. String(); Call call = (Call)service. create. Call (new QName(nsuri, port), new QName(nsuri, o. Name)); System. out. println(call. invoke(new Object[] {"UK", "Israel"})); }
The WSDL 2 Java Application • Axis provides a mechanism for communicating with a Web service using stubs • That is, generation of regular Java classes that have an interface similar to that of the Web service and implementation that wraps Web service management • Invoke class WSDL 2 Java in order to create the required Java classes
An Example
Using The Generated Classes import net. xmethods. www. sd. Currency. Exchange. Service_wsdl. *; public class Currency. Exchange 3 { public static void main(String[] args) throws Exception { Currency. Exchange. Service ce = new Currency. Exchange. Service. Locator(); Currency. Exchange. Port. Type cep = ce. get. Currency. Exchange. Port(); float rate = cep. get. Rate("USA", "Israel"); System. out. println("Rate: " + rate); } }
Generated Classes • WSDL 2 Java generates the following: - A service interface and a service implementation (locator) for each service - A stub class for each binding - An interface for each port type • This interface contains methods that correspond to the operations of the port type - A class for each complex type
Server Applications
AXIS Installation • Axis works inside a Servlet container (e. g. , Tomcat) • You should add to your Tomcat libs some jar files: axis. jar, saaj. jar, wsdl 4 j. 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 are in $CATALINA_BASE/shared/lib/
AXIS Installation (cont) • You need to copy the Axis application to your Tomcat's application directory: cp -r ~dbi/tomcat/axis/ $CATALINA_BASE/webapps $CATALINA_BASE webapps myapplication shared axis lib The directory that Classes were you need to copy added for you classes
Creating a Web Service • Next, we will see how we can create and publish a Web service using the Axis plugin in Tomcat
1. Generate the Implementing Class package myws; public class Power { public int power(int a, int n) { return (int)Math. pow(a, n); } } $CATALINA_BASE/webapps/axis/classes/myws/Power. class
2. Deploy the Service using Web Service Deployment Descriptor <deployment xmlns="http: //xml. apache. org/axis/wsdd/" xmlns: java="http: //xml. apache. org/axis/wsdd/providers/java"> <service name="mypower" provider="java: RPC"> <parameter name="class. Name" value="myws. Power"/> <parameter name="scope" value="application"/> <parameter name="allowed. Methods" value="*"/> </service> </deployment> services. wsdd java org. apache. axis. client. Admin. Client -hlocalhost -p 8090 services. wsdd
That's it. Call the Service. import org. apache. axis. client. *; public class Power. Client { public static void main(String[] argv)throws Exception { String endpoint = "http: //mangal: 8090/axis/services/mypower"; Call call = (Call) new Service(). create. Call(); call. set. Target. Endpoint. Address(endpoint); call. set. Operation. Name("power"); Object value = call. invoke(new Object[] {new Integer(2), new Integer(5)}); System. out. println(2+"^"+5 +"=" + value); } }
How Does it Work? • The AXIS plugin is simply a Web application that resides in Tomcat (under webapps/) • The Servlet Axis. Servlet of this application is responsible for invoking services • All URLs of the form /services/* are mapped to the Axis. Servlet - Where is that written?
How Does it Work? (cont) • The wsdd file defines mappings between a Web service elements to a Java class elements - I. e. , names, methods, etc. • The class Admin. Client sends a request to the application to register the service based on the wsdd content • When a SOAP request arrives, the Axis. Servlet object parses the request and invokes the corresponding method of the class associated with the service URL
The Deployment Descriptor <deployment xmlns="http: //xml. apache. org/axis/wsdd/" xmlns: java="http: //xml. apache. org/axis/wsdd/providers/java"> <service name="mypower" provider="java: RPC"> <parameter name="class. Name" value="myws. Power"/> <parameter name="scope" value="application"/> <parameter name="allowed. Methods" value="*"/> </service> </deployment> services. wsdd
The 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
Undeploying a Service <undeployment xmlns="http: //xml. apache. org/axis/wsdd/"> <service name="mypower"/> undeploy. wsdd </undeployment> java org. apache. axis. client. Admin. Client -hlocalhost -p 8090 undeploy. wsdd
Implementing Classes • The class that implements the Web service must be accessible to the Axis Servlet • Hence, this class should reside in a package in one of the directories - $CATALINA_BASE/webapps/axis/WEB-INF/classes - $CATALINA_BASE/shared/classes (classes that are required for other applications besides Axis) • Of course, all helper classes should be accessible to the Axis application too
The Service WSDL • Axis automatically provides a WSDL for each deployed service • To get the WSDL, use the service URL with the empty argument wsdl http: //localhost: 8090/axis/services/mypower? wsdl
Power-Service WSDL <? xml version="1. 0" encoding="UTF-8"? > <wsdl: definitions target. Namespace="http: //localhost/axis/services/mypower" xmlns="http: //schemas. xmlsoap. org/wsdl/" xmlns: apachesoap="http: //xml. apache. org/xml-soap" xmlns: impl="http: //localhost/axis/services/mypower" xmlns: intf="http: //localhost/axis/services/mypower" xmlns: soapenc="http: //schemas. xmlsoap. org/soap/encoding/" xmlns: wsdl="http: //schemas. xmlsoap. org/wsdl/" xmlns: wsdlsoap="http: //schemas. xmlsoap. org/wsdl/soap/" xmlns: xsd="http: //www. w 3. org/2001/XMLSchema"> <wsdl: message name="power. Response"> <wsdl: part name="power. Return" type="xsd: int"/> </wsdl: message> <wsdl: message name="power. Request"> <wsdl: part name="a" type="xsd: int"/> <wsdl: part name="n" type="xsd: int"/> </wsdl: message>
<wsdl: port. Type name="Power"> <wsdl: operation name="power" parameter. Order="a n"> <wsdl: input message="impl: power. Request" name="power. Request"/> <wsdl: output message="impl: power. Response" name="power. Response"/> </wsdl: operation> </wsdl: port. Type>
<wsdl: binding name="mypower. Soap. Binding" type="impl: Power"> <wsdlsoap: binding style="rpc" transport="http: //schemas. xmlsoap. org/soap/http"/> <wsdl: operation name="power"> <wsdlsoap: operation soap. Action=""/> <wsdl: input name="power. Request"> <wsdlsoap: body encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/" namespace="http: //myws" use="encoded"/> </wsdl: input> <wsdl: output name="power. Response"> <wsdlsoap: body encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/" namespace="http: //localhost/axis/services/mypower" use="encoded"/> </wsdl: output> </wsdl: operation> </wsdl: binding>
<wsdl: service name="Power. Service"> <wsdl: port binding="impl: mypower. Soap. Binding" name="mypower"> <wsdlsoap: address location="http: //localhost/axis/services/mypower"/> </wsdl: port> </wsdl: service> </wsdl: definitions>
jws Files • There is a fast and easy way of crating a service: 1. Create a Java class my. Class. java 2. Rename your class to end with jws: my. Class. jws 3. Put the jws file directly under the directory $CATALINA_BASE/webapps/axis/ 4. That is all. Now you can call the service!
Example: a Calculator Service public class Simple. Calculator { public int add(int i 1, int i 2) { return i 1 + i 2; } public int subtract(int i 1, int i 2) { return i 1 - i 2; } } $CATALINA_BASE/webapps/axis/Simple. Calculator. jws Service URL: http: //server: port/axis/Simple. Calculator. jws
Example: a Calculator Service public class Calculator. Client { public static void main(String[] argv)throws Exception { String endpoint = "http: //localhost: 80/axis/Simple. Calculator. jws"; Call call = (Call) new Service(). create. Call(); call. set. Target. Endpoint. Address(endpoint); call. set. Operation. Name("add"); Object value = call. invoke(new Object[] {new Integer(4), new Integer(6)}); System. out. println(value); } }
How does it Work? • On the first time the jws file is being called, it is compiled into a class - WEB-INF/jws. Classes/Simple. Calculator. class • Axis then considers the URL of the jws as one of a regular web service - Default configurations are assumed • Sounds like any other technology we know?
When not to Use jws Files • • When you do not have the Java source code When you don’t want to expose your code When you want to use custom type mappings When you want to use other configuration options
Axis Type Mappings
Axis Type Mappings • Axis uses mappings between SOAP types and Java classes and primitive types - In client side: SOAP → Java - In server side: Java → SOAP • Serialization and deserialization are executed by objects of the interfaces Serializer and Deserializer (provided by Axis), respectively - For example, Simple. Serializer, Simple. Deserializer, Date. Deserializer, Array. Serializer Axis Type Mapping
Complex Type Example - Service Side package myws; import java. util. *; public class Vector. Service { public Vector get. As. Vector(int[] array) { Vector result = new Vector(); for(int i=0; i<array. length; ++i) result. add("Number " + array[i]); return result; } } Vector. Service. java <service name="tovector" provider="java: RPC"> <parameter name="class. Name" value="myws. Vector. Service"/> <parameter name="scope" value="application"/> <parameter name="allowed. Methods" value="get. As. Vector"/> </service> services. wsdd
Input in The WSDL <complex. Type name="Array. Of_xsd_int"> <complex. Content> <restriction base="soapenc: Array"> <attribute ref="soapenc: array. Type" wsdl: array. Type="xsd: int[]"/> </restriction> </complex. Content> </complex. Type> <wsdl: message name="get. As. Vector. Request"> <wsdl: part name="array" type="impl: Array. Of_xsd_int"/> </wsdl: message>
Output in The WSDL <complex. Type name="Vector"> <sequence> <element max. Occurs="unbounded" min. Occurs="0" name="item" type="xsd: any. Type"/> </sequence> </complex. Type> <wsdl: message name="get. As. Vector. Response" <wsdl: part name="get. As. Vector. Return" type="apachesoap: Vector"/> </wsdl: message>
Complex Type Example - Client Side import java. util. *; import org. apache. axis. client. *; public class Vector. Client { public static void main(String[] argv)throws Exception { String endpoint = "http: //localhost/axis/services/tovector"; Call call = (Call) new Service(). create. Call(); call. set. Target. Endpoint. Address(endpoint); call. set. Operation. Name("get. As. Vector"); int[] array = {3, 7}; Vector value = (Vector)call. invoke(new Object[] {array}); print. Vector(value); } Vector. Client. java
A Snapshot from the Request <get. As. Vector soapenv: encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/"> <arg 0 xsi: type="soapenc: Array" soapenc: array. Type="xsd: int[2]" xmlns: soapenc="http: //schemas. xmlsoap. org/soap/encoding/"> <item>3</item> <item>7</item> </arg 0> </get. As. Vector>
A Snapshot from the Response <get. As. Vector. Response soapenv: encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/"> <get. As. Vector. Return href="#id 0"/> </get. As. Vector. Response> <multi. Ref id="id 0" soapenc: root="0" soapenv: encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/" xsi: type="ns 1: Vector" xmlns: soapenc="http: //schemas. xmlsoap. org/soap/encoding/" xmlns: ns 1="http: //xml. apache. org/xml-soap"> <item xsi: type="soapenc: string">Number 3</item> <item xsi: type="soapenc: string">Number 7</item> </multi. Ref>
Java Beans • Java Beans are simply objects of classes that follow some (natural) coding conventions: - An empty constructor - A readable property has a matching getter - A writable property has a matching setter • A property has name and a type • The getter of property prop: type get. Prop() • The setter of property prop: void set. Prop()
An Example package myws; public class Person { private String first. Name, last. Name; private int person. ID; property first. Name public String get. First. Name() {return first. Name; } public void set. First. Name(String first. Name) { this. first. Name = first. Name; } public String get. Last. Name() {return last. Name; } public void set. Last. Name(String last. Name) { this. last. Name = last. Name; Property last. Name } public void set. Id(int id) {person. ID = id; } public int get. Id(int id) {return person. ID; } } Property id
Using Beans in Web Services • A Web service can use beans in its definition - either in its input or output • For that, you need to tell the Axis engine that the corresponding object needs to be serialized as a bean • In this serialization, every readable property (i. e. , one that has a getter) is specified • Where, in the file system, should the bean class reside?
A Service Example package myws; public class Person. Service { public Person create. Person() { Person person = new Person(); person. set. First. Name("f"); person. set. Last. Name("l"); person. set. Id(2); return person; } }
The WSDL <deployment xmlns="http: //xml. apache. org/axis/wsdd/" xmlns: java="http: //xml. apache. org/axis/wsdd/providers/java"> <service name="person" provider="java: RPC"> <parameter name="class. Name" value="myws. Person. Service"/> <parameter name="scope" value="application"/> <parameter name="allowed. Methods" value="*"/> <bean. Mapping qname="ns: person" xmlns: ns="http: //www. cs. huji. ac. il/~dbi/xsd" language. Specific. Type="java: myws. Person"/> </service> </deployment>
Using Beans in Clients • To use a bean on the client side, you need to configure service to deserialize the SOAP type into a Java bean • For that, we use the class Bean. Serializer provided by Axis • Note that client and server beans need not be the class - What should they have in common?
public class Person. Client { public static void main(String[] argv) throws Exception { String endpoint = "http: //localhost/axis/services/person"; Call call = (Call) new Service(). create. Call(); call. set. Target. Endpoint. Address(endpoint); call. set. Operation. Name("create. Person"); QName qn = Identical to new QName("http: //www. cs. huji. ac. il/~dbi/xsd", "person"); Person Bean. Deserializer. Factory bdf = new Bean. Deserializer. Factory(My. Person. class, qn); call. register. Type. Mapping(My. Person. class, qn, null, bdf); My. Person value = (My. Person)call. invoke(new Object[] {}); System. out. println(value); } }
Exception Handling
Exception in Service Calls • Several problems can cause exception to be thrown when a service is being invoked • For example - the server cannot be connected - the server does not find the requested URL - the request is inappropriate (no such operation, invalid arguments, etc. ) - the implementing service method has thrown an exception
Service Exception • When the implementing service throws an exception, a SOAP fault response is returned by the server • The client invocation method translates this response to a java. rmi. Remote. Exception after parsing the response
An Example package myws; public class Exception. Service { public void throw. Exception() throws Illegal. State. Exception { throw new Illegal. State. Exception ("I only throw an exception!"); }} <service name="exception" provider="java: RPC"> <parameter name="class. Name" value="myws. Exception. Service"/> <parameter name="allowed. Methods" value="*"/> </service> services. wsdd
public class Exception. Client { public static void main(String[] argv){ String endpoint = "http: //localhost: 80/axis/services/exception"; try { Call call = (Call) new Service(). create. Call(); call. set. Target. Endpoint. Address(endpoint); call. set. Operation. Name("throw. Exception"); Object value = call. invoke(new Object[] {}); System. out. println(value); } catch(Remote. Exception exp) { System. err. println("WS invocation error: " + exp. get. Message()); } catch(Exception exp) { System. err. println("Error: " + exp. get. Message()); }}}
A Snapshot from the Response <soapenv: Body> <soapenv: Fault> <faultcode>soapenv: Server. user. Exception</faultcode> <faultstring>java. lang. Illegal. State. Exception: I only throw an exception!</faultstring> <detail>. . . </detail> </soapenv: Fault> </soapenv: Body>
Sharing Information with Web Applications
The Scenario • In your project, you will have two Web applications under Tomcat 5. 0: - Your Web site - Axis application for publishing Web services • The above two applications need to share information - e. g. , the database connection parameters • How will your Web application pass that information to the service method?
A Possible Solution • Tomcat uses one class loader for all classes under $CATALINA_BASE/share/ • Hence, a static variable in one of those classes will be accessible to every class running under Tomcat
A Possible Solution $CATALINA_BASE webapps myapplication shared axis lib 1. Put the shared class under shared 2. Use a static field of the shared class to hold the shared object 3. The first time a you discover the parameter, store it the shared classes Shared. Class
eef511caee12199caf44287778552d16.ppt