Java(TM) API for XML-based RPC (JAX-RPC) Tools
Revised: 7 October, 2003
Contents
wscompile
The
wscompiletool generates stubs, ties, serializers, and WSDL files used in JAX-RPC clients and services. The tool reads a configuration file, which specifies either a WSDL file, a model file, or a compiled service endpoint interface.Syntax
By convention, the configuration file is named
config.xml, but this is not a requirement. The following table lists the wscompile options. Note that exactly one of the-import,-define, or-genoptions must be specified.
The following table lists the features (delimited by commas) that may follow the
-foption. The wscompile tool reads as input either a WSDL file, compiled service endpoint interface (SEI), or model file. The Type of File column indicates which of these files can be used with a particular feature.
Configuration File
The
wscompiletool reads the configuration file (config.xml), which contains information that describes the web service. The basic structure ofconfig.xmlfollows:<?xml version="1.0" encoding="UTF-8"?> <configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config"> <service> or <wsdl> or <modelfile> </configuration>The
<configuration>element may contain exactly one<service>,<wsdl>, or<modelfile>element.The <service> Element
If you specify this element, wscompile reads the service endpoint interface that describes the service and generates a WSDL file. In the
<interface>subelement, the name attribute specifies the service endpoint interface, and theservantNameattribute specifies the class that implements the interface. For example:<service name="CollectionIF_Service" targetNamespace="http://echoservice.org/wsdl" typeNamespace="http://echoservice.org/types" packageName="stub_tie_generator_test"> <interface name="stub_tie_generator_test.CollectionIF" servantName="stub_tie_generator_test.CollectionImpl"/> </service>The <wsdl> Element
If you specify this element,
wscompilereads the service's WSDL file and generates the service endpoint interface. The location attribute specifies the URL of the WSDL file, and thepackageNameattribute specifies the package of the classes generated bywscompile. For example:The <modelfile> Element
This element is for advanced users.
If
config.xmlcontains a<service>or<wsdl>element,wscompilegenerates a model file that contains the internal data structures that describe the service. If you've already generated a model file in this manner, then you can reuse it the next time you runwscompile. For example:wsdeploy
The
wsdeploytool reads a WAR file and thejaxrpc-ri.xmlfile and then generates another WAR file that is ready for deployment. Behind the scenes,wsdeployrunswscompilewith the-gen:serveroption. Thewscompilecommand generates classes and a WSDL file thatwsdeployincludes in the generated WAR file.On JWSDP, the
wsdeploytool must be run. However, on J2EE you don't have to runwsdeploybecause the functions it performs are done automatically when you deploy a WAR withdeploytoolorasadmin.Syntax
The syntax for wsdeploy follows:
The following table lists the tool's options. Note that the
-ooption is required.
The Input WAR File
Typically, you create the input WAR file with a GUI development tool or with the
antwartask. Here are the contents of a simple input WAR file:META-INF/MANIFEST.MF WEB-INF/classes/hello/HelloIF.class WEB-INF/classes/hello/HelloImpl.class WEB-INF/jaxrpc-ri.xml WEB-INF/web.xmlIn this example,
HelloIFis the service endpoint interface andHelloImplis the class that implements the interface. Theweb.xmlfile is the deployment descriptor of a web component. Thejaxrpc-ri.xmlfile is described in the next section.The jaxrpc-ri.xml File
The listing that follows shows a
jaxrpc-ri.xmlfile for a simpleHelloWorldservice.<?xml version="1.0" encoding="UTF-8"?> <webServices xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/dd" version="1.0" targetNamespaceBase="http://com.test/wsdl" typeNamespaceBase="http://com.test/types" urlPatternBase="/ws"> <endpoint name="MyHello" displayName="HelloWorld Service" description="A simple web service" wsdl="/WEB-INF/<wsdlame> interface="hello.HelloIF" implementation="hello.HelloImpl"/> <endpointMapping endpointName="MyHello" urlPattern="/hello"/> </webServices>The
<webServices>element must contain one or more<endpoint>elements. In this example, note that the interface and implementation attributes of<endpoint>specify the service's interface and implementation class. The<endpointMapping>element associates the service name with a URL.Advanced Topics
This section is for developers who are familiar with WSDL, SOAP, and the JAX-RPC specifications.
Namespace Mappings
For the below
namespaceMappingRegistryelement in theconfig.xmlfile,wscompilebehaves as follows. When going from WSDL types to Java types, for all types defined in thehttp://echoservice.org/typesnamespace,wscompilewill generate Java classes in theechoservice.org.typespackage. Likewise, for all schema types defined in thehttp://echoservice.org/types2namespace,wscompilegenerate Java classes in theechoservice.org.types2package.<namespaceMappingRegistry> <namespaceMapping namespace="http://echoservice.org/types" packageName="echoservice.org.types"/> <namespaceMapping namespace="http://echoservice.org/types2" packageName="echoservice.org.types2"/> </namespaceMappingRegistry>Handlers
A handler accesses a SOAP message that represents an RPC request or response. A handler class must implement the
javax.xml.rpc.handlerinterface. Because it accesses a SOAP message, a handler can manipulate the message with the APIs of thejavax.xml.soappackage.A handler chain is a list of handlers. You may specify one handler chain for the server and one for the client. On the server, you include the
<handlerChains>element in thejaxrpc-ri.xmlfile. On the client , you include this element in theconfig.xmlfile. Here is an example of the<handlerChains>element inconfig.xml:<handlerChains> <chain runAt="server" roles= "http://acme.org/auditing http://acme.org/morphing" xmlns:ns1="http://foo/foo-1"> <handler className="acme.MyHandler" headers ="ns1:foo ns1:bar"/> <property name="property" value="xyz"/> </handler> </chain> </handlerChains>For more information on handlers, see the SOAP Message Handlers chapter of the JAX-RPC specifications.
Copyright © 2003 Sun Microsystems, Inc. All rights reserved.