JBoss.orgCommunity Documentation

Chapter 4. JAX-WS Tools

4.1. Server side
4.1.1. Bottom-Up (Using wsprovide)
4.1.2. Down (Using wsconsume)
4.2. Client Side
4.2.1.
4.3. WS binding customization
4.4. wsconsume
4.4.1. Command Line Tool
4.4.2. Maven Plugin
4.4.3. Ant Task
4.5. wsprovide
4.5.1. Command Line Tool
4.5.2. Maven Plugin
4.5.3. Ant Task

The JAX-WS tools provided by JBossWS can be used in a variety of ways. First we will look at server-side development strategies, and then proceed to the client.

When developing a Web Service Endpoint (the server-side) you have the option of starting from Java ( bottom-up development ), or from the abstact contract (WSDL) that defines your service ( top-down development ). If this is a new service (no existing contract), the bottom-up approach is the fastest route; you only need to add a few annotations to your classes to get a service up and running. However, if you are developing a service with an already defined contract, it is far simpler to use the top-down approach, since the provided tool will generate the annotated code for you.

Bottom-up use cases:

Top-down use cases:

The following JAX-WS command line tools are included in JBossWS:

Command

Description

wsprovide

Generates JAX-WS portable artifacts, and provides the abstract contract. Used for bottom-up development.

wsconsume

Consumes the abstract contract (WSDL and Schema files), and produces artifacts for both a server and client. Used for top-down and client development

The bottom-up strategy involves developing the Java code for your service, and then annotating it using JAX-WS annotations. These annotations can be used to customize the contract that is generated for your service. For example, you can change the operation name to map to anything you like. However, all of the annotations have sensible defaults, so only the @WebService annotation is required.

This can be as simple as creating a single class:

A JSE or EJB3 deployment can be built using this class, and it is the only Java code needed to deploy on JBossWS. The WSDL, and all other Java artifacts called "wrapper classes" will be generated for you at deploy time. This actually goes beyond the JAX-WS specification, which requires that wrapper classes be generated using an offline tool. The reason for this requirement is purely a vender implementation problem, and since we do not believe in burdening a developer with a bunch of additional steps, we generate these as well. However, if you want your deployment to be portable to other application servers, you will unfortunately need to use a tool and add the generated classes to your deployment.

This is the primary purpose of the wsprovide tool, to generate portable JAX-WS artifacts. Additionally, it can be used to "provide" the abstract contract (WSDL file) for your service. This can be obtained by invoking wsprovide using the "-w" option:

Inspecting the WSDL reveals a service called EchoService :

As expected, this service defines one operation, " echo ":

Let's create a POJO endpoint for deployment on JBoss AS. A simple web.xml needs to be created:

The web.xml and the single class can now be used to create a war:

The war can then be deployed to the JBoss Application Server.The war can then be deployed to the JBoss Application Server; this will internally invoke wsprovide, which will generate the WSDL. If deployment was successful, and you are using the default settings, it should be available in the server management console.

For a portable JAX-WS deployment, the wrapper classes generated earlier could be added to the deployment.

The top-down development strategy begins with the abstract contract for the service, which includes the WSDL file and zero or more schema files. The wsconsume tool is then used to consume this contract, and produce annotated Java classes (and optionally sources) that define it.

Using the WSDL file from the bottom-up example, a new Java implementation that adheres to this service can be generated. The "-k" option is passed to wsconsume to preserve the Java source files that are generated, instead of providing just classes:

The following table shows the purpose of each generated file:

File

Purpose

Echo.java

Service Endpoint Interface

Echo_Type.java

Wrapper bean for request message

EchoResponse.java

Wrapper bean for response message

ObjectFactory.java

JAXB XML Registry

package-info.java

Holder for JAXB package annotations

EchoService.java

Used only by JAX-WS clients

Examining the Service Endpoint Interface reveals annotations that are more explicit than in the class written by hand in the bottom-up example, however, these evaluate to the same contract:

The only missing piece (besides for packaging) is the implementation class, which can now be written, using the above interface.

Before going to detail on the client-side it is important to understand the decoupling concept that is central to Web Services. Web Services are not the best fit for internal RPC, even though they can be used in this way. There are much better technologies for this (CORBA, and RMI for example). Web Services were designed specifically for interoperable coarse-grained correspondence. There is no expectation or guarantee that any party participating in a Web Service interaction will be at any particular location, running on any particular OS, or written in any particular programming language. So because of this, it is important to clearly separate client and server implementations. The only thing they should have in common is the abstract contract definition. If, for whatever reason, your software does not adhere to this principal, then you should not be using Web Services. For the above reasons, the recommended methodology for developing a client is to follow the top-down approach , even if the client is running on the same server.

Let's repeat the process of the top-down section, although using the deployed WSDL, instead of the one generated offline by wsprovide . The reason why we do this is just to get the right value for soap:address. This value must be computed at deploy time, since it is based on container configuration specifics. You could of course edit the WSDL file yourself, although you need to ensure that the path is correct.

Offline version:

Online version:

Using the online deployed version with wsconsume :

The one class that was not examined in the top-down section, was EchoService.java . Notice how it stores the location the WSDL was obtained from.

As you can see, this generated class extends the main client entry point in JAX-WS, javax.xml.ws.Service . While you can use Service directly, this is far simpler since it provides the configuration info for you. The only method we really care about is the getEchoPort() method, which returns an instance of our Service Endpoint Interface. Any WS operation can then be called by just invoking a method on the returned interface.

All that is left to do, is write and compile the client:

It is easy to change the endpoint address of your operation at runtime, setting the ENDPOINT_ADDRESS_PROPERTY as shown below:

An introduction to binding customizations:

The schema for the binding customization files can be found here:

wsconsume is a command line tool and ant task that "consumes" the abstract contract (WSDL file) and produces portable JAX-WS service and client artifacts.

The command line tool has the following usage:

The wsconsume tools is included in the org.jboss.ws.plugins:jaxws-tools- maven- plugin plugin. The plugin has two goals for running the tool, wsconsume and wsconsume-test , which basically do the same during different maven build phases (the former triggers the sources generation during generate-sources phase, the latter during the generate-test-sources one).

The wsconsume plugin has the following parameters:

Attribute

Description

Default

bindingFiles

JAXWS or JAXB binding file

true

classpathElements

Each classpathElement provides a library file to be added to classpath

${project.compileClasspathElements} or ${project.testClasspathElements}

catalog

Oasis XML Catalog file for entity resolution

none

targetPackage

The target Java package for generated code.

generated

bindingFiles

One or more JAX-WS or JAXB binding file

none

wsdlLocation

Value to use for @WebServiceClient.wsdlLocation

generated

outputDirectory

The output directory for generated artifacts.

${project.build.outputDirectory} or ${project.build.testOutputDirectory}

sourceDirectory

The output directory for Java source.

${project.build.directory}/generated-sources/wsconsume

verbose

Enables more informational output about command progress.

false

wsdls

The WSDL files or URLs to consume

n/a

extension

Enable SOAP 1.2 binding extension.

false

encoding

The charset encoding to use for generated sources.

${project.build.sourceEncoding}

argLine

An optional additional argline to be used when running in fork mode; can be used to set endorse dir, enable debugging, etc. Example <argLine>-Djava.endorsed.dirs=...</argLine>

none

fork

Whether or not to run the generation task in a separate VM.

false

target

A preference for the JAX-WS specification target

Depends on the underlying stack and endorsed dirs if any

You can use wsconsume in your own project build simply referencing the jaxws-tools- maven- plugin in the configured plugins in your pom.xml file.

The following example makes the plugin consume the test.wsdl file and generate SEI and wrappers' java sources. The generated sources are then compiled together with the other project classes.

You can also specify multiple wsdl files, as well as force the target package, enable SOAP 1.2 binding and turn the tool's verbose mode on:

Finally, if the wsconsume invocation is required for consuming a wsdl to be used in your testsuite only, you might want to use the wsconsume-test goal as follows:

Plugin stack dependencyThe plugin itself does not have an explicit dependency to a JBossWS stack, as it's meant for being used with implementations of any supported version of the JBossWS SPI . So the user is expected to set a dependency in his own pom.xml to the desired JBossWS stack version. The plugin will rely on the that for using the proper tooling.

The wsconsume Ant task ( org.jboss.ws.tools.ant.WSConsumeTask ) has the following attributes:

Attribute

Description

Default

fork

Whether or not to run the generation task in a separate VM.

true

keep

Keep/Enable Java source code generation.

false

catalog

Oasis XML Catalog file for entity resolution

none

package

The target Java package for generated code.

generated

binding

A JAX-WS or JAXB binding file

none

wsdlLocation

Value to use for @WebServiceClient.wsdlLocation

generated

encoding

The charset encoding to use for generated sources

n/a

destdir

The output directory for generated artifacts.

"output"

sourcedestdir

The output directory for Java source.

value of destdir

target

The JAX-WS specification target. Allowed values are 2.0, 2.1 and 2.2

 

verbose

Enables more informational output about command progress.

false

wsdl

The WSDL file or URL

n/a

extension

Enable SOAP 1.2 binding extension.

false

additionalHeaders

Enables processing of implicit SOAP headers

false

Also, the following nested elements are supported:

Element

Description

Default

binding

A JAXWS or JAXB binding file

none

jvmarg

Allows setting of custom jvm arguments

 

wsprovide is a command line tool, Maven plugin and Ant task that generates portable JAX-WS artifacts for a service endpoint implementation. It also has the option to "provide" the abstract contract for offline usage.

The wsprovide tools is included in the org.jboss.ws.plugins:jaxws-tools- maven- plugin plugin. The plugin has two goals for running the tool, wsprovide and wsprovide-test , which basically do the same during different Maven build phases (the former triggers the sources generation during process-classes phase, the latter during the process-test-classes one).

The wsprovide plugin has the following parameters:

Attribute

Description

Default

testClasspathElements

Each classpathElement provides a library file to be added to classpath

${project.compileClasspathElements} or ${project.testClasspathElements}

outputDirectory

The output directory for generated artifacts.

${project.build.outputDirectory} or ${project.build.testOutputDirectory}

resourceDirectory

The output directory for resource artifacts (WSDL/XSD).

${project.build.directory}/wsprovide/resources

sourceDirectory

The output directory for Java source.

${project.build.directory}/wsprovide/java

extension

Enable SOAP 1.2 binding extension.

false

generateWsdl

Whether or not to generate WSDL.

false

verbose

Enables more informational output about command progress.

false

portSoapAddress

The generated port soap:address in the WSDL

 

endpointClass

Service Endpoint Implementation.

 

You can use wsprovide in your own project build simply referencing the jaxws-tools- maven- plugin in the configured plugins in your pom.xml file.

The following example makes the plugin provide the wsdl file and artifact sources for the specified endpoint class:

The following example does the same, but is meant for use in your own testsuite:

Plugin stack dependencyThe plugin itself does not have an explicit dependency to a JBossWS stack, as it's meant for being used with implementations of any supported version of the JBossWS SPI . So the user is expected to set a dependency in his own pom.xml to the desired JBossWS stack version. The plugin will rely on the that for using the proper tooling.

The wsprovide ant task ( org.jboss.ws.tools.ant.WSProvideTask ) has the following attributes:

Attribute

Description

Default

fork

Whether or not to run the generation task in a separate VM.

true

keep

Keep/Enable Java source code generation.

false

destdir

The output directory for generated artifacts.

"output"

resourcedestdir

The output directory for resource artifacts (WSDL/XSD).

value of destdir

sourcedestdir

The output directory for Java source.

value of destdir

extension

Enable SOAP 1.2 binding extension.

false

genwsdl

Whether or not to generate WSDL.

false

address

The generated port soap:address in wsdl.

 

verbose

Enables more informational output about command progress.

false

sei

Service Endpoint Implementation.

 

classpath

The classpath that contains the service endpoint implementation.

"."