Section 10.13. Automating Web Services Deployment


10.13. Automating Web Services Deployment

As we've seen so far, deploying a Web Service requires writing very little code (just the Service Endpoint Interface), but it adds a complex set of deployment issues:

  • Create three new descriptors (webservices.xml, the JAX-RPC Mapping file, and the WSDL file)

  • Modify both EJB deployment descriptors (ejb-jar.xml and jboss.xml).

Although it's possible to develop everything by hand, it's not very practical because the new deployment descriptors are interrelated, and the XML elements are tedious and error-prone. In previous chapters, we've automated everything with Ant and XDoclet, but the current XDoclet version, XDoclet 1.2.3, falls short when it comes to Web Services. XDoclet has Ant tasks that are supposed to generate the JAX-RPC Mapping and WSDL files, but these XDoclet tasks don't work properly. Bug reports have been submitted to the XDoclet project, and we hope to see a resolution to these issues in the next production version of XDoclet. As you'll see in the "Web Services Ant Script" section, we'll add another technology to our toolkitthe Java Web Services Developer's Pack (JWSDP)to complete our deployment by generating the JAX-RPC Mapping and WSDL files. Even though XDoclet doesn't do everything, we still use it to generate the Service Endpoint Interface, modify ejb-jar.xml, and generate webservices.xml.

Before you can use the JWSDP from our Ant build script, you need to download JWSDP 1.5 from http://java.sun.com/webservices/downloads/webservicespack.html and add the JAR files to your CLASSPATH by doing one of the following:

  • In the Ant build script below, set the jwsdp.lib.dir property to your JWSDP 1.5 installation.

  • Copy the libsub-directory from your Axis 1.1 installation to /Library/jwsdp-1.5/ (the jwsdp.lib.dir property in the Ant build script currently points to /Library/jwsdp-1.5).

10.13.1. Web Services Ant Script

We now modify the EJB deployment process to include Web Service deployment. Example 10-12 shows the upgraded build.xml script from the ejb sub-project.

Example 10-12. ejb/build.xml
     ...     <property name="jwsdp.lib.dir" value="/Library/jwsdp-1.5"/>     ...     <target name="run-ejbdoclet" ...>       <ejbdoclet ...>         ...         <service-endpoint/>         ...       </ejbdoclet>       <!-- Fix problems with XDoclet-generated Service Endpoint Interface  -->       <replace              file="${gen.source.dir}/com/jbossatwork/ws/InventoryEndpoint.java">       <replacetoken><![CDATA[throws javax.ejb.EJBException, java.rmi.RemoteException]]></replacetoken>         <replacevalue><![CDATA[throws java.rmi.RemoteException]]></replacevalue>         </replace>         <!-- Fix WS URL in jboss.xml -->         <replace file="${gen.source.dir}/jboss.xml">           <replacetoken><![CDATA[<ejb-name>InventoryFacade</ejb-name>]]> </replacetoken>             <replacevalue><![CDATA[                         <ejb-name>InventoryFacade</ejb-name>                         <port-component>                           <port-component-name>Inventory</port-component-name>                           <port-component-uri>jbossatwork-ws/InventoryService </port-component-uri>                         </port-component>                       ]]></replacevalue>         </replace>     </target>     <target name="run-wseedoclet" depends="run-ejbdoclet">         <taskdef name="wseedoclet"                  classname="xdoclet.modules.wsee.WseeDocletTask"                  classpathref="xdoclet.lib.path"/>         <wseedoclet wsdlFile="META-INF/wsdl/InventoryService.wsdl"                     jaxrpcMappingFile="META-INF/inventory-mapping.xml"                     wseeSpec="1.1"                     destdir="${gen.source.dir}"                     excludedtags="@version,@author"                     addedtags="@xdoclet-generated at ${TODAY}"                     verbose="true">             <fileset dir="${source.dir}">                 <include name="**/*Bean.java"/>             </fileset>             <deploymentdescriptor name="InventoryService"/>         </wseedoclet>         <!-- Fix problems with XDoclet-generated webservices.xml -->         <replace file="${gen.source.dir}/webservices.xml">             <replacetoken><![CDATA[<wsdl-file>WEB-INF/]]></replacetoken>             <replacevalue><![CDATA[<wsdl-file>]]></replacevalue>         </replace>         <replace file="${gen.source.dir}/webservices.xml">             <replacetoken><![CDATA[<jaxrpc-mapping-file>WEB-INF/]]></replacetoken>             <replacevalue><![CDATA[<jaxrpc-mapping-file>]]></replacevalue>         </replace>            <replace file="${gen.source.dir}/webservices.xml">             <replacetoken><![CDATA[<icon>]]></replacetoken>             <replacevalue><![CDATA[  ]]></replacevalue>         </replace>            <replace file="${gen.source.dir}/webservices.xml">             <replacetoken><![CDATA[</icon>]]></replacetoken>             <replacevalue><![CDATA[  ]]></replacevalue>         </replace>         <replace file="${gen.source.dir}/webservices.xml">             <replacetoken><![CDATA[Port</wsdl-port>]]></replacetoken>             <replacevalue><![CDATA[EndpointPort</wsdl-port>]]></replacevalue>         </replace>     </target>     <target name="run-wscompile" depends="compile">         <echo message="Generating JAX-RPC Mapping and WSDL files."/>         <path >             <fileset dir="${jwsdp.lib.dir}">                 <include name="**/*.jar"/>             </fileset>             <fileset dir="${java.home}/../lib" includes="tools.jar"/>         </path>         <taskdef name="wscompile"                  classname="com.sun.xml.rpc.tools.ant.Wscompile"                  classpathref="wscompile.task.classpath"/>         <wscompile base="${build.dir}"                    fork="true"                    server="true"                    features="rpcliteral"                    mapping="${gen.source.dir}/inventory-mapping.xml"                    config="wscompile-config.xml"                    nonClassDir="${gen.source.dir}">             <classpath>                 <path ref/>                 <path ref/>                 <pathelement location="${classes.dir}"/>             </classpath>         </wscompile>     </target>     ...     <!-- Build EJB JAR. -->     <target name="build-ejb-jar" depends="run-ejbdoclet, compile, run-wseedoclet, run-wscompile"             description="Packages the EJB files into a EJB JAR file">         <mkdir dir="${distribution.dir}" />         <jar destfile="${distribution.dir}/${ejb.jar.name}"              basedir="${classes.dir}">             <metainf dir="${gen.source.dir}" includes="*.xml"/>             <zipfileset dir="${gen.source.dir}" includes="*.wsdl"                         prefix="META-INF/wsdl"/>         </jar>     </target>     ... 

Even though we're adding Web Services to our EJB deployment, the overall process stays the same. We still execute run-ejbdoclet to generate all the EJB-based deployment descriptors and the EJB Remote and Local Component Interface files. The compile task compiles the EJBs, and the run-wseedoclet task generates the webservices.xml file. The run-wscompile target uses the wscompile task to create the JAX-RPC Mapping and WSDL files. Finally, build-ejb-jar takes all the descriptors and .class files, and creates an EJB JAR file.

In the run-ejbdoclet target, we've added a new <ejbdoclet>subtask called < service-endpoint> that generates the Service Endpoint Interface file and adds the <service-endpoint> element to ejb-jar.xml based on the XDoclet tags we added to our EJB. After executing <ejbdoclet>, the run-ejbdoclet target then uses the Ant <replace> task to set the Web Services URL in jboss.xml.

The run-wseedoclet target generates the webservices.xml file from the @wsee.port-component XDoclet tag we added to the EJB. But XDoclet doesn't generate the webservices.xml incorrectly (it doesn't conform to the W3C specification), so we used Ant's built-in <replace> task to fix each syntactical problem.

Since the XDoclet Ant tasks that generate the JAX-RPC Mapping and WSDL files don't work properly, the run-wscompile target uses the wscompile Ant task from JWSDP 1.5 to generate the JAX-RPC Mapping and WSDL files. Add the JWSDP JAR files to your CLASSPATH by doing one of the following:

  • In the Ant build script above, set the jwsdp.lib.dir property to your JWSDP 1.5 installation.

  • Copy the jwsdp-shared, jaxrpc, and saaj sub-directories from your JWSDP 1.5 installation to /Library/jwsdp-1.5 (the jwsdp.lib.dir property in the Ant build script currently points to /Library/jwsdp-1.5).

The wscompile task takes the wscompile-config.xml file in Example 10-13 (which resides in the ejb sub-directory) as input.

Example 10-13. wscompile-config.xml
 <?xml version="1.0" encoding="UTF-8"?> <configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">   <service name="InventoryService"            targetNamespace="http://localhost:8080/jbossatwork-ws"            typeNamespace="http://localhost:8080/jbossatwork-ws/types"            packageName="com.jbossatwork.ws">     <interface name="com.jbossatwork.ws.InventoryEndpoint"/>   </service> </configuration> 

The wscompile-config.xml file provides the XML Schema namespace, Java package name, and the name of the Service Endpoint Interface Java file for each Web Service. The wscompile task uses the contents of the wscompile-config.xml file to generate the JAX-RPC Mapping and WSDL files.

More XDoclet Issues

You may have noticed that we're modifying the artifacts generated by the <service-endpoint> and <wsee-doclet> XDoclet Ant tasks. We have to do this because XDoclet 1.2.3 doesn't generate the Service Endpoint Interface and webservices.xml files correctly. These files weren't badly broken, so we've fixed them inline in the Ant script. Bug reports have been submitted to the XDoclet project, and we hope to see a resolution to these issues in the next production version of XDoclet.




JBoss at Work. A Practical Guide
JBoss at Work: A Practical Guide
ISBN: 0596007345
EAN: 2147483647
Year: 2004
Pages: 197

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net