LibraryLink ToToggle FramesPrintFeedback

WSDL-first JAX-WS Service Development

The WSDL-first JAX-WS sample is a simple Hello World application developed using the JAX-WS APIs. The sample demonstrates using a WSDL-first development approach to:

  • Run a simple client against a standalone server using SOAP 1.1 over HTTP

  • Configure FUSE Services Framework to enable schema validation on the client and/or server side

This sample includes a WSDL file that defines the operations and the data exchanged with the service. When you run this sample, the client and server applications send greetings back and forth. The client sends one of the messages with an invalid length string, which causes the server to throw an exception defined in the WSDL file.

When you enable schema validation, the server and client throw marshaling and unmarshaling exceptions defined in a configuration file that you add to your CLASSPATH (see Enabling schema validation).

The hello_world.wsdl file for this sample defines four operations for the service:


The client and server do the following when you run the sample:

  1. The client invokes sayHi and the server responds.

  2. The client invokes greetMe and the server responds.

  3. The client invokes greetMe with an invalid length string and expects an error. The server executes pingMe and throws a PingMeFault exception.

  4. The client invokes greetMeOneWay and expects no response from the server.

These instructions use Maven to build and run the sample, using the pom.xml file located the base directory of this sample. If you prefer to use wsdl2java, javac, and java to build and run the sample, see the ReadMe file located in your install_dir\samples\wsdl_first directory.

See About Maven and Installing and setting up Maven for more information about using Maven with the FUSE Services Framework samples.

Initially, you will run the sample without using a configuration file. Later you will add the file, cxf.xml, to the CLASSPATH to run the sample with schema validation.

To build and run the sample:

The messages appear rapidly in the consoles as the sample runs. When the messages have all been sent, you can scroll up in the console windows to observe the following events:

  1. The client invokes sayHi, and receives a response from the server:

    Messages in the server console indicate that the server executes the sayHi operation:

  2. The client (in this example, Bob) then invokes greetMe and receives a response from the server:

    Messages in the server console indicate that the server executes the greetMe operation:

  3. The client invokes greetMe with an invalid length string and expects an exception:

    The server executes pingMe and throws a PingMeFault exception:

  4. The client invokes greetMeOneWay and gets no response because this is a one-way operation:

  5. The client invokes pingMe and expects an exception:

    The server throws an exception, executes greetMeOneWay, and exits:

To remove the code generated from the WSDL file and the *.class files, run mvn clean.

By default, message parameters are not validated, but you can use a configuration file to enable message parameter validation. This sample includes a configuration file, cxf.xml, that changes the default behavior to enable schema validation on the client proxy and server endpoint:

When you run this sample with the cxf.xml configuration file added to the CLASSPATH, the client's second greetMe invocation causes an exception (a marshaling error) on the client side. This exception occurs before the request with the invalid parameter is sent.

You can comment out the definition of the jaxws:client element in the cxf.xml configuration file, then run the sample again to observe that the client's second greetMe invocation still throws an exception. This time the exception is caused by an unmarshaling error on the server side.

You can comment out both elements, or remove the cxf.xml file from your CLASSPATH, to restore the default behavior.

To run the sample with schema validation.

  1. Add cxf.xml to your CLASSPATH environment variable.

  2. Start the server and client again. After the sample runs, scroll through the server and client consoles to observe the messages exchanged.

    This time, when the client invokes greetMe with an invalid length string, the client catches an WebServiceException before the message is sent, and generates a marshaling error:

  3. Edit the configuration file to comment out the definition of the <jaxws:client>. When you run the sample this time, the second greetMe invocation throws an exception that is caused by an unmarshaling error on the server side:

    Messages in the client console show the that the WebServiceException is caught and an unmarshalling error is generated:

  4. Edit the configuration file to comment out both the <jaxws:client> and <jaxws:endpoint> elements to restore the default behavior. Alternatively, remove cxf.xml from your CLASSPATH.

When you run the Maven mvn install command, Maven compiles the Java files and creates Java class files. Maven creates the install_dir\samples\wsdl_first\target directory, which includes the client and server class files.

When you run the Maven mvn -Pserver and mvn -Pclient commands, Maven starts the server and client and executes the operations in the WSDL and Java class files.

The sample files in the wsdl_first directory include the following:

OSGi is a mature, lightweight, component system that solves many challenges associated with medium and large scale development projects. Through the use of bundles complexity is reduced by separating concerns and ensuring dependencies are minimally coupled via well defined interface communication. This also promotes the reuse of components in much the same way that SOA promotes the reuse of services. And, since each bundle effectively is given an isolated environment, and since dependencies are explicitly defined, versioning and dynamic updates are possible. These are just a few of the many benefits of OSGi. Users wishing to learn more should check out http://www.osgi.org/Main/HomePage.

Before you can install an application into an OSGi container, you must package it into one or more OSGi bundles. An OSGi bundle is a JAR that contains extra information that is used by the OSGi container. This extra information specifies the packages this bundle exposes to the other bundles in the container and any packages on which this bundle depends.

See the chapter "Deploying to an OSGi Container" in Configuring and Deploying FUSE™ Services Framework Endpoints , for more information about deploying to an OSGi container, and for instructions that use this WSDL-first sample to demonstrate the steps of installing an application into an OSGi container.