Recipe3.5.Deploying an Axis Web Service That Uses AspectJ


Recipe 3.5. Deploying an Axis Web Service That Uses AspectJ

Problem

You want to deploy an aspect-oriented Apache Axis web service that has been created using AspectJ.

Solution

Create and compile your web service Java class with your aspects using the ajc command line tool or in AspectJ project in Eclipse. Copy your application's .class files to the %AXIS_INSTALLATION_IN_TOMCAT%/WEB-INF/classes directory and the aspectjrt.jar to %AXIS_INSTALLATION_IN_TOMCAT%/WEB-INF/lib.

Create an Apache Axis deployment configuration file and use the org.apache.axis.client.AdminClient command-line tool to register your new web service with Apache Axis.

Discussion

Apache Axis is rapidly becoming one of the most popular web service implementations for Java developers. Not only is it open source but, thanks to its very active supporting developer base, it also has a high degree of success in interoperability with web services developed using other web service frameworks such as .NET.

Once you have Apache Axis running within Tomcat on your machine, you can use the following steps to compile a simple aspect-oriented web service and deploy it within Apache Axis:

  1. Create a directory within your project area called source, and within that new directory, create a file called MyWebService.java that contains:

    package com.oreilly.aspectjcookbook; public class MyWebService {    public String echo(String message)    {       return message;    } }

  2. Create another file in the source directory called AddMessageHeaderAspect.java that contains:

    package com.oreilly.aspectjcookbook; public aspect AddMessageHeaderAspect  {    public pointcut captureEcho(String message) :        execution(public void MyWebService.echo(String)) &&        args(message);        Object around(String message) : captureEcho(message)    {       return "Your original message was: " + message;    } }

  3. Create a classes directory within your project area.

  4. Compile the two files, MyWebService.java and AddMessageHeaderAspect.java, in your source directory using the ajc command-line tool from the project root directory:

    ajc -classpath %AXIS_INSTALL_DIRECTORY%/lib/axis.jar:%AXIS_ INSTALL_DIRECTORY%/lib/axis.jar -d classes/ source/*.java

  5. Once you have successfully run the ajc command, the compiled .class files and package structure will be generated under the classes directory.

  6. Create a file called deploy.wsdd within the classes directory that is going to be used to automatically deploy your web application to Axis. The deploy.wsdd should contain the following information:

    <deployment xmlns="http://xml.apache.org/axis/wsdd/"             xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">  <service name="MyWebService" provider="java:RPC">   <parameter name="className" value="com.oreilly.aspectjcookbook.MyWebService"/>   <parameter name="allowedMethods" value="*"/>  </service> </deployment>

  7. It is a good practice to create an undeploy.wsdd file in the same classes directory as the deploy.wsdd to be able to remove your web application from Axis. The undeploy.wsdd should contain the following information:

    <undeployment xmlns="http://xml.apache.org/axis/wsdd/">  <service name="MyWebService"/> </undeployment>

  8. Copy the %ASPECTJ_INSTALL_DIRECTORY%/lib/aspectjrt.jar to %AXIS_INSTALLATION_IN_TOMCAT%/WEB-INF/lib.

  9. Copy your .class files located in the classes directory, preserving the package directory structure, to %AXIS_INSTALLATION_IN_TOMCAT%/WEB-INF/classes.

  10. Ensuring that Tomcat is running if you are deploying to Apache Axis running within Tomcat, run the following java command from the classes directory to run the Apache Axis deployment program that registers your new web service with Axis:

     java -classpath %AXIS_INSTALL_DIRECTORY%/lib/axis.jar: %AXIS_INSTALL_ DIRECTORY%/lib/jaxrpc.jar:%AXIS_INSTALL_DIRECTORY%/lib/log4j-1.2.4.jar: %AXIS_INSTALL_DIRECTORY%/lib/commons-logging.jar:%AXIS_INSTALL_DIRECTORY% /lib/commons-discovery.jar:%AXIS_INSTALL_DIRECTORY%/lib/saaj.jar org. apache.axis.client.AdminClient -h%HOST% -p%PORT% deploy.wsdd

  11. Restart Tomcat to ensure it has refreshed all of the libraries and applications it manages, including Axis.

  12. To test that your web service has been deployed correctly, you can go to :/axis/services/MyWebService">http://<hostname>:<post>/axis/services/MyWebService in your browser, and you should see the output shown in Figure 3-12.

    Figure 3-12. The aspect-oriented MyWebService service, initialized and ready for use inside Apache Axis


  13. Web service clients can now use your new aspect-oriented web service. For example, the output of a simple AppleScript that uses the MyWebService is shown in Figure 3-13.

    Figure 3-13. An AppleScript web service client using the echo method on the aspect-oriented MyWebService service


See Also

Compiling using the ajc command-line tool is explained in Recipe Recipe 2.2; creating and compiling an AspectJ project in Eclipse is described in Recipe 2.7; execution(Signature) pointcut is explained in Recipe 4.4; the args([TypePatterns | Identifiers]) pointcut is explained in Recipe 11.3; Programming Apache Axis by Christopher Haddad, Kevin Bedell, and Paul Brown (O'Reilly); AppleScript in a Nutshell by Bruce W. Perry (O'Reilly).



AspectJ Cookbook
Aspectj Cookbook
ISBN: 0596006543
EAN: 2147483647
Year: 2006
Pages: 203
Authors: Russ Miles

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