WebReference.com - Part 4 of chapter 3 from Professional Java Web Services, Wrox Press Ltd. (5/6)

To page 1To page 2To page 3To page 4current pageTo page 6
[previous] [next]

Professional Java Web Services

User-Defined Types

If Apache SOAP clients need to exchange user-defined types with Apache SOAP services, we need to register the new type mapping with the Apache SOAP runtime. In this section we will discuss two ways to register user-defined type mappings:

Register via the Deployment Descriptor

The first method consists of registering the type using the deployment descriptor, which we discussed in the Deploying and Running a "Hello World" Service section. This method is the easiest method, but the major drawback is that the type would have to be registered each time it was used with a different service. In other words, services that want to utilize the type would have to add the type mapping information to its deployment descriptor. This is appropriate for data types that are application-specific and rarely reused.

Type mappings are specified through the use of the mappings element, which is an optional child element of the <service> element. To illustrate this, let's look at the deployment descriptor for the Job Resumé Repository Service (JobResumeRepositoryDD.xml):

<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
             id="urn:JobResuméRepositoryService">
  <isd:provider type="java"
                scope="Application"
                methods="retrieve submit">
    <isd:java class="com.wrox.jobresumé.service.JobResuméRepositoryService"
    static="false"/>
  </isd:provider>
  <isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListener>
  <isd:mappings>
    <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
            xmlns:x="urn:jobresume" qname="x:resume"
            javaType="com.wrox.jobresume.common.Resume"
            java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"
            xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
  </isd:mappings>
</isd:service>

The deployment descriptor for the Job Resumé Repository Service is similar to the one for the Hello World service except that a mapping element now has to be used since the Resume type has to be exchanged between Apache SOAP clients and Apache SOAP servers. The mapping element contains one or more <map> elements, which define an actual type mapping. The encodingStyle attribute is used to specify the encoding schema that the mapping should use. We are using the preferred encoding method, which is http://schemas.xmlsoap.org/soap/encoding/. The xmlns and qname attributes are used to specify the namespace and element name of the type that's being defined. So, the fully qualified name for the Resume type will be urn:jobresume:resume. The javaType attribute is used to specify the fully qualified class name of the class that implements the type. So, the fully qualified class for the Resume type is com.wrox.jobresume.common.Resume. The java2XMLClassName and the xml2JavaClassName attributes are used to specify the serializier and deserializer for the type. Since the Resume class conforms to the JavaBean specification we are able to use the BeanSerializer class that comes with Apache SOAP, which is capable of handling both the serialization and deserialization.

Override the SOAPMappingRegistry Class

An alternative to registering a user-defined type using a deployment descriptor is to override the SOAPMappingRegistry class with another class that has the new type defined. This method would allow the type mapping to be centralized in one place. This would alleviate the need to register the type for each service that needs it. This is appropriate for types that are used for multiple services, rather than a type that's only used by one service.

To page 1To page 2To page 3To page 4current pageTo page 6
[previous] [next]

Created: June 5, 2002
Revised: June 5, 2002

URL: http://webreference.com/programming/java/webservices/chap3/4/5.html