Professional Documents
Culture Documents
3 4
06/15/2005
Response
Client System Server System
Background on ? RPC, COM, CORBA, RMI:
Remote Synchronous communication: calling process
Communication
blocks until there is a response
More tightly coupled (than non-RPC model):
client must find recipients and know method and
its arguments
7
Non persistent
8
06/15/2005
?
WSDL is the IDL
Any communication protocol can be
Why
used as a transport XML-based RPC?
e.g.) HTTP, SMTP, FTP etc.
13 14
What is JAX-RPC?
? Java API for XML-based RPC
Web Services operations are performed by
exchanging SOAP 1.1 messages
Implementation classes
Servlet-based endpoint model
Optional handler and serializer classes
23 24
06/15/2005
31 32
06/15/2005
4. Package the files into war file 5. Deploy the WAR file
? asant create-war ? asant deploy-war
hello-jaxrpc.war is created hello-jaxrpc.war is deployed
? The tie classes (which are used to
communicate with clients) are generated
by the Application Server during
deployment.
39 40
06/15/2005
Type Mapping
41 42
setter methods
45 46
// Java
public class Book implements java.io.Serializable {
// ...
public String getAuthor() { ... }
public void setAuthor(String author) { ... }
Type Mapping
public String getPreface() { ... }
public void setPreface(String preface) { ... } Mapping of Java Data
public float getPrice() { ... }
}
public void setPrice(float price) { ... } types to XML Data types
47 48
06/15/2005
49 50
51 52
06/15/2005
53 54
57 58
63 64
06/15/2005
71 72
06/15/2005
javax.xml.rpc.Call
package javax.xml.rpc;
public interface Call {
static public final int PARAM_MODE_IN = 1;
static public final int PARAM_MODE_OUT = 2;
static public final int PARAM_MODE_INOUT = 3;
public void addParameter(String paramName, QName xmlType, int parameterMode);
public void setReturnType(QName xmlType);
public void removeAllParameters();
public String getOperationName();
public void setOperationName(String operationName);
public QName getPortTypeName();
public void setPortTypeName(QName portType);
public String getTargetEndpointAddress();
public void setTargetEndpointAddress(String address);
public void setProperty(String name, Object value) throws JAXRPCException;
public Object getProperty(String name);
WSDL to Java Mapping
public void removeProperty(String name);
// Remote Method Invocation methods
public Object invoke(Object[] params) throws java.rmi.RemoteException;
Mapping Tool
public void invokeOneWay(Object[] params) throws javax.xml.rpc.JAXRPCException;
}
75 76
06/15/2005
implementation
Service definition interface (Extension of
SOAP Binding
java.rmi.Remote) Support in JAX-RPC
Stub and tie classes
Additional classes
? serializers, deserializers
77 78
}
} Dynamic Proxy based
private static Stub createProxy() {
// Note: MyHelloService_Impl is implementation-specific.
return (Stub) (new MyHelloService_Impl().getHelloIFPort());
} 91 92
}
06/15/2005
Example: Dynamic Proxy Client (1) Example: Dynamic Proxy Client (2)
package dynamicproxy; ServiceFactory serviceFactory =
ServiceFactory.newInstance();
import java.net.URL;
import javax.xml.rpc.Service; Service helloService =
import javax.xml.rpc.JAXRPCException; serviceFactory.createService(helloWsdlUrl,
import javax.xml.namespace.QName; new QName(nameSpaceUri, serviceName));
import javax.xml.rpc.ServiceFactory;
import dynamicproxy.HelloIF; dynamicproxy.HelloIF myProxy =
(dynamicproxy.HelloIF)
public class HelloClient { helloService.getPort(
new QName(nameSpaceUri, portName),
public static void main(String[] args) { dynamicproxy.HelloIF.class);
try {
System.out.println(myProxy.sayHello("Buzz"));
String UrlString = args[0] + "?WSDL";
String nameSpaceUri = "urn:Foo"; } catch (Exception ex) {
String serviceName = "MyHelloService"; ex.printStackTrace();
String portName = "HelloIFPort"; }
}
System.out.println("UrlString = " + UrlString); }
URL helloWsdlUrl = new URL(UrlString)
97 98
101 102
Step2: From the Service object, Step3: Set the service endpoint
create a Call object address on the Call object
? A Call object supports the dynamic ? In the WSDL file, this address is specified by
invocation of the remote procedures of a the <soap:address> element
service call.setTargetEndpointAddress(endpoint);
QName port = new QName(qnamePort);
Call call = service.createCall(port);
? The parameter of createCall is a QName
object that represents the service endpoint
interface, which is specified in WSDL
<portType name="HelloIF">
105 106
Step4: Specify the method's return Step5: Specify the method's return
type, name, and parameter type, name, and parameter
? Properties to set ? Return type, method name, parameter
SOAPACTION_USE_PROPERTY QName QNAME_TYPE_STRING = new QName(NS_XSD, "string");
call.setReturnType(QNAME_TYPE_STRING);
SOAPACTION_URI_PROPERTY
ENCODING_STYLE_PROPERTY call.setOperationName(new QName(BODY_NAMESPACE_VALUE,
"sayHello"));
call.addParameter("String_1", QNAME_TYPE_STRING,
ParameterMode.IN);
107 108
06/15/2005
import javax.xml.rpc.Call;
? Assign the parameter value (Murphy) to a import javax.xml.rpc.Service;
import javax.xml.rpc.JAXRPCException;
String array (params) and then executes the import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceFactory;
invoke method with the String array as an import javax.xml.rpc.ParameterMode;
call.setProperty(Call.SOAPACTION_USE_PROPERTY,
new Boolean(true));
call.setProperty(Call.SOAPACTION_URI_PROPERTY
"");
call.setProperty(ENCODING_STYLE_PROPERTY,
URI_ENCODING);
QName QNAME_TYPE_STRING =
new QName(NS_XSD, "string"); 111 112
call.setReturnType(QNAME_TYPE_STRING);
06/15/2005
113 114
Service Deployer
? Handles
Protocol binding
Port assignment
? Multiple protocol binds for a single service
endpoint definition Protocol and
? Creates web.xml
? Creates complete WSDL document which
Transport Binding
contains concrete binding information
This WSDL document can be published
? Creates and deploy assembled *.war file
117 118
125 126
Package Relationship
javax.xml.rpc javax.xml.messaging
javax.xml.soap Resources
127 128
06/15/2005
Resources
? JAX-RPC Home
http://java.sun.com/xml/jax-rpc/index.html
? Java Web Services Developer Pack Download
http://java.sun.com/webservices/downloads/webservicespack.html
? Java Web Services Developer Pack Tutorial Passion!
http://java.sun.com/webservices/downloads/webservicetutorial.html
? J2EE 1.4 SDK
http://java.sun.com/j2ee/1.4/download-dr.html
129 130