Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Excerpt
hiddentrue

A meta guide to your options with CXF


CXF provides you with many options to build clients for your services. This guide is meant to give you a quick overview of those options and help you orient yourself quickly with CXF.

...

The WSDL2Java tool will generate a JAX-WS clients from your WSDL. You can run it WSDL2java one of three ways:

For more in depth information read Developing a JAX-WS consumer or see the Hello World demos inside the distribution.

JAX-WS Proxy

Instead of using a wsdl2java-generated stub client directly, you can use Service.create to create Service instances, the following code illustrates this process:

Code Block
java
java

import java.net.URL;
import javax.xml.ws.Service;
...

URL wsdlURL = new URL("http://localhost/hello?wsdl");
QName SERVICE_NAME = new QName("http://apache.org/hello_world_soap_http", "SOAPService");
Service service = Service.create(wsdlURL, SERVICE_NAME);
Greeter client = service.getPort(Greeter.class);
String result = client.greetMe("test");

JAX-WS Dispatch APIs

JAX-WS provides the "dispatch" mechanism which makes it easy to dynamically invoke services which you have not generated a client for. Using the Dispatch mechanism you can create messages (which can be JAXB objects, Source objects, or a SAAJMessage) and dispatch them to the server. A simple example might look like this:

Code Block
java
java

import java.net.URL;
import javax.xml.transform.Source;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
...

URL wsdlURL = new URL("http://localhost/hello?wsdl");
Service service = Service.create(wsdlURL, new QName("HelloService"), wsdlURL);
Dispatch<Source> disp = service.createDispatch(new QName("HelloPort"), Source.class, Service.Mode.PAYLOAD);

Source request = new StreamSource("<hello/>")
Source response = disp.invoke(request);

...

For more in depth information see the Hello World demos inside the distribution.

JAX-WS Proxy

Instead of using the generated stub client directly, you can use Service.create to create Service instances, the following code illustrates this process:

...

.

...

Simple Frontend Client Proxy

...

There are two ways to create Clients at runtime. The first would be through choice is to use the ClientFactoryBean and or JaxWsClientFactoryBean classes. These will create proxy objects for the SEI for the service. These proxies cannot handle complex objects.

The second is through to use the DynamicClientFactory or one of its subclasses. The DynamicClientFactory goes the additional step of generating and compiling JAXB POJOs for complex objects described in the background WSDL, for use at runtime via reflection.

This is most useful when you're using a dynamic language such as Groovy with CXF, but it is possible to use reflection directly from Java.

More Information: Dynamic Clients