Section 2.2. Customizing Plug-in Behavior


2.2. Customizing Plug-in Behavior

In this lab, you'll be working with a web service maintained by the U.S. government's National Oceanic and Atmospheric Administration (NOAA). The U.S. government recently decided that weather feeds should be made available to the general public at no charge, so now it provides a forecast server at http://weather.gov/xml/. You are going to use the Maven Axis plug-in to generate classes which will retrieve a forecast from this web service. To do this, you will need to customize the behavior of the Axis plug-in.

2.2.1. How do I do that?

If you've successfully installed the Axis plug-in, maven -P axis should list the goals available in the plug-in; one of them should be axis:wsdl2java. You are going to use this goal to generate a client library from the Web Service Description Language (WSDL) for the weather web service.

You can find the WSDL for the NOAA forecast service at http://weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl. A WSDL document is an XML document which completely describes the methods available in a SOAP service. The Axis plug-in is going to use this XML document to create a client library. For the purposes of this lab, this WSDL document is stored in weather/src/wsdl/weather.wsdl. The Axis plug-in will generate Java source files for all WSDL documents found in this directory.

To use the output of the Axis plug-in, your project will need to include the following dependencies:

<dependency>    <groupId>commons-discovery</groupId>   <artifactId>commons-discovery</artifactId>   <version>20030211.213356</version> </dependency> <dependency>    <groupId>commons-logging</groupId>   <artifactId>commons-logging</artifactId>   <version>1.0.4</version> </dependency> <dependency>    <groupId>axis</groupId>   <artifactId>axis</artifactId>   <version>1.2-RC3</version> </dependency> <dependency>    <groupId>axis</groupId>   <artifactId>axis-jaxrpc</artifactId>   <version>1.2-RC3</version> </dependency> <dependency>    <groupId>axis</groupId>   <artifactId>axis-saaj</artifactId>   <version>1.2-RC3</version> </dependency> <dependency>    <groupId>axis</groupId>   <artifactId>axis-wsdl4j</artifactId>   <version>1.2-RC3</version> </dependency>

To generate this client library, you will need to configure the Axis plug-in to generate client-side bindings from the WSDL document. And to do this, you will need to set the values of plug-in properties in your project.properties file. There are two places where you can discover the properties a plug-in exposes: the plug-in project web site and your local plug-in cache. To find a plug-in's properties from your local cache, take a look at the ~/.maven/cache/maven-axis-plugin-0.7/plugin.properties file. It should contain the following:

maven.axis.dir=${maven.build.dir}/axis maven.axis.generated.dir=${maven.axis.dir}/src maven.axis.test.dir=${maven.axis.dir}/test maven.axis.url=${maven.src.dir}/wsdl maven.axis.all=true maven.axis.deployscope=session maven.axis.factory=org.apache.axis.wsdl.toJava.JavaGeneratorFactory maven.axis.helpergen=false maven.axis.serverside=true maven.axis.skeletondeploy=true maven.axis.noimports=no maven.axis.verbose=yes maven.axis.debug=false maven.axis.typemappingversion=1.1 maven.axis.timeout=45000

This file lists the default values for the plug-in's properties, and in this case you can see that the maven.axis.serverside variable is set to true by default. Since you are going to be generating client-side bindings, this variable needs to be set to false for this project. You will also notice that the value of maven.axis.timeout is set to 45000 milliseconds; in this project, you will set the timeout to 20 seconds. For a friendlier list of the Axis plug-in properties, see the plug-in web site at http://maven-plugins.sourceforge.net/maven-axis-plugin/properties.html. To customize the behavior of this plug-in, place the following in your weather/project.properties file:

#Maven XDoc Plug-in Customization maven.xdoc.date = left maven.xdoc.date.format = MM/dd/yyyy    # Maven Axis Plug-in Customization maven.axis.serverside = false maven.axis.timeout = 20000 # Maven Test Plug-in Customization maven.test.skip = false maven.test.fork = yes

Now, when you run the axis:wsdl2java goal, it creates a client library with a 20-second timeout. You will also notice that the project.properties file customizes the behavior of two other plug-ins: Test and XDoc. Later in this chapter you will see how to customize the XDoc plug-in.

Running maven axis:wsdl2java will create the client library for this SOAP service, and will store the generated source in maven.axis.generate.dir. You should also be able to run unit tests in the sample project to see that the project has a unit test to verify the operation of the NOAA forecast web service.



Maven. A Developer's Notebook
Maven: A Developers Notebook (Developers Notebooks)
ISBN: 0596007507
EAN: 2147483647
Year: 2003
Pages: 125

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