Building a Web Services Client Project

Web Services are a part of many J2EE applications, and Maven’s ability to integrate toolkits can make them easier to add to the build process. For example, the Maven plugin called Axis Tools plugin takes WSDL files and generates the Java files needed to interact with the Web services it defines. As the name suggests, the plugin uses the Axis framework, and this will be used from DayTrader’s wsappclient module. We start our building process off by visiting the Web services portion of the build since it is a dependency of later build stage.

Axis generates the following:

Table 4-1: Axis generated classes

WSDL clause Java class(es) generated
For each entry in the type section A Java class A holder if this type is used as an in-out/out parameter
For each port type A Java interface
For each binding A stub class
For each service A service interface A service implementation (the locator)

For more details on the generation process, see this site.

FIgure 4-5 shows the directory structure of the wsappclient module. As you may notice, the WSDL files are in src/main/wsdl, which is the default used by the Axis Tools plugin:


Figure 4-5: Directory structure of the wsappclient module

The location of WSDL source can be customized using the sourceDirectory property. For example:

[...]
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>axistools-maven-plugin</artifactId>
    <configuration>
        <sourceDirectory> src/main/resources/META-INF/wsdl </sourceDirectory>
    </configuration>
</plugin>
[...]

In order to generate the Java source files from the TradeServices.wsdl file, the wsappclient/pom.xml file must declare and configure the Axis Tools plugin:

<project>
    [...]
    <build>
        <plugins>
            [...]
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>axistools-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Note that there’s no need to define a phase in the execution element as the wsdl2java goal is bound to the generate-sources phase by default.

At this point if you were to execute the build, it would fail. This is because after the sources are generated, you will require a dependency on Axis and Axis JAXRPC in your pom.xml. While you might expect the Axis Tools plugin to define this for you, it is required for two reasons: it allows you to control what version of the dependency to use regardless of what the Axis Tools plugin was built against, and more importantly, it allows users of your project to automatically get the dependency transitively. Similarly, any tools that report on the POM will be able to recognize the dependency.

As before, you need to add the J2EE specifications JAR to compile the project’s Java sources. Thus the following three dependencies have been added to your POM:

<dependencies>
    <dependency>
        <groupId>axis</groupId>
        <artifactId>axis</artifactId>
        <version>1.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>axis</groupId>
        <artifactId>axis-jaxrpc</artifactId>
        <version>1.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-j2ee_1.4_spec</artifactId>
        <version>1.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>
Note: The Axis JAR depends on the Mail and Activation Sun JARs which cannot be redistributed by Maven. Thus, they are not present on ibiblio1 and you’ll need to install them manually. Run mvn install and Maven will fail and print the installation instructions.

After manually installing Mail and Activation, running the build with mvn install leads to:

C:devm2bookcodej2eedaytraderwsappclient>mvn install
[...]
[INFO] [axistools:wsdl2java {execution: default}]
[INFO] about to add compile source root
[INFO] processing wsdl:
C:devm2bookcodej2eedaytraderwsappclient
srcmainwsdlTradeServices.wsdl
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile] Compiling 13 source files to
C:devm2bookcodej2eedaytraderwsappclienttargetclasses
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] No sources to compile
[INFO] [surefire:test]
[INFO] No tests to run.
[INFO] [jar:jar]
[INFO] Building jar: C:devm2bookcodej2eedaytraderwsappclient
targetdaytrader-wsappclient-1.0.jar
[INFO] [install:install]
[INFO] Installing C:devm2bookcodej2eedaytraderwsappclient
targetdaytrader-wsappclient-1.0.jar to
C:[...].m2repositoryorgapachegeronimosamplesdaytrader
daytrader-wsappclient1.0daytrader-wsappclient-1.0.jar
[...]

Note that the daytrader-wsappclient JAR now includes the class files compiled from the generated source files, in addition to the sources from the standard source directory.

The Axis Tools plugin boasts several other goals including java2wsdl that is useful for generating the server-side WSDL file from handcrafted Java classes. The generated WSDL file could then be injected into the Web Services client module to generate client-side Java files. But that’s another story. The Axis Tools reference documentation can be found here.

Now that we have discussed and built the Web services portion, let’s visit EJBs next.

Thank you for requesting a Maestro evaluation! This is our passion, and we want you to be successful. Please let us know how we may help!

Please enter your name, company email address and phone, and we will send you a link to your pre-built hosted evaluation within minutes.






I have read and agree to the Terms and Conditions.