JAX-RPC Model
Introduction to JAXRPC
Service
JAXRPC Client
Tie Ye Wu http://www.ise.gmu.edu/~wuye SWE 645 Component-based Software Development sources: Java Web Service Architecture, James McGoven and etc., Morgan Kaufmann, Ch 4, 10, 11 (8 and 9 are supporting chapters)
Axis
SOAP
SOAP
HTTP
HTTP
TCP/IP
TCP/IP
© Dr. Ye Wu
2
New Features in Axis2
• • • •
SOAP Engine (SOAP 1.1 and SOAP 1.2 compliant) 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. • some sample programs, and
© Dr. Ye Wu
Endpoint
INTERNET 2006-11-1
2006-11-1
Dynamic Stub Proxy DII
• • • • • •
3
Better Performance AXIOM (Axis Object Model) Asynchronous Web Services Improved deployment model Improved support for Message-style interaction Improved handlers
2006-11-1
© Dr. Ye Wu
4
1
Data Type and Serialization
Java-to-XML Marshalling • All Java primitives, with exception of a char. • An object that is an instance of
• RMI – Java Serialization • CORBA – IIOP • DCOM – ORPC
– – – – –
• Web service – How to perform marshalling and unmarshalling?
2006-11-1
© Dr. Ye Wu
• An object that is an instance of a class that conforms to JavaBean specification. (Not remote objects • An array • A java.lang.Exception class 5
2006-11-1
XML <-> Java Data Mapping in AXIS xsd:base64Bin byte[] ary xsd:boolean
Boolean
xsd:byte
Byte
xsd:dateTime xsd:decimal
java.util.Cale ndar java.math.Bi gDecimal
xsd:hexBina ry
byte[]
xsd:int
Int
xsd:integer
java.math.BigInteg er
xsd:long
long
xsd:QName
javax.xml.namespa ce.QName
xsd:double
Double
xsd:short
short
xsd:float
Float
xsd:string
java.lang.String
2006-11-1
© Dr. Ye Wu
Java.lang.String Java.util.Date Java.util.Calendar Java.math.BigInteger Java.math.BigDecimal
© Dr. Ye Wu
6
SOAP Binding and Encoding • Encoded message
7
– Axis - RPC style service
• Literal message – – – –
2006-11-1
Axis - RPC style service Axis - Document style service Axis - Wrapped style service Axis - Message service
© Dr. Ye Wu
8
2
Develop SOAP Service with Axis
Developing the Axis service import java.util.*;
• Developing the Axis service • Prepare a services.xml file to explain the Web Services • Deploy web service • Develop Client program
2006-11-1
© Dr. Ye Wu
public class HelloWorldService { public HelloWorldService() {} public String HelloWorld() { return "Hello World!"; } } 9
2006-11-1
Services.xml
© Dr. Ye Wu
Deploy Web Service
<service> <description> This is my first service, which says hello <parameter name="ServiceClass"> swe645.HelloWorldService <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
• Create a .aar file which includes all class files and the services.xml • Copy the .aar file into $AXIS_HOME/WEBINF/services directory
2006-11-1
2006-11-1
© Dr. Ye Wu
10
11
• Verify the deployment at http://localhost:8080/axis2
© Dr. Ye Wu
12
3
Develop Web Service Client
Develop Web Service Client
private static EndpointReference targetEPR = new EndpointReference( "http://localhost:8888/axis2/services/HelloWorld");
try { Options options = new Options(); options.setTo(targetEPR);
public static void main(String[] args) { OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace("http:///XSD", "Helloworld"); OMElement method = fac.createOMElement("HelloWorld", omNs);
// Blocking invocation. ServiceClient sender = new ServiceClient(); sender.setOptions(options); OMElement result = sender.sendReceive(method);
OMElement token = fac.createOMElement("HelloWorldParameter", omNs); token.addChild(fac.createOMText(token, "Test Input")); method.addChild(token);
2006-11-1
© Dr. Ye Wu
13
System.out.println(result); } catch (AxisFault axisFault) { axisFault.printStackTrace(); } } }2006-11-1
© Dr. Ye Wu
14
4