Consuming Web Services with CXF
This page describes how to consume web services using the CXF client message processors.
There are 4 ways to consume web services. The first 3 correspond to the 3 ways of building web services:
1. Generate and use a client from a WSDL
2. Use a client based on the interface of a JAX-WS service
3. Use a client based on the interface of a "simple" frontend web service
4. Use the JAX-WS Java client API
The last two options are only usable if you have the Java interface for your service, meaning that their use is normally limited to use within an organization.
WSDL First JAX-WS Client
You can use a CXF-generated client as an outbound endpoint. First, you generate a CXF client using the WSDL to Java tool from CXF or the Maven plugin. (Note: the CXF transport doesn't support wrapper-style web service method calls. You may need to create a binding file or change the WSDL directly. See the WSDL to Java tool page for more details.)
Next, you configure the client as an outbound endpoint using the following properties:
clientClass: The client class generated by CXF, which extends javax.xml.ws.Service.
port: The WSDL port to use for communicating with the service
wsdlLocation: The location of the WSDL for the service. CXF uses this to configure the client.
operation: The operation name to invoke on the web service. The objects that you pass to the outbound router must match the signature of the method for this operation. If your method takes multiple parameters, they must be put in an Object array.
Here is a simple example:
JAX-WS Code First Client
You can also build a client for your JAX-WS services without the need to generate a client from WSDL. To do this, you need a copy of your service interface and all your data objects locally to use. This can simplify consuming web services if you already have access to the code used to build the service.
Using the JAX-WS Client API
This section describes how to use the JAX-WS client APIs to talk to web services. This allows you to talk to web services outside of mule configurations.
There are two ways to use CXF clients. First, you can generate a client from WSDL using the CXF WSDL to Java tool. Second, if you've built your service via "code-first" methodologies, you can use the service interface to build a client proxy object.
When using a CXF client, it automatically discovers the Mule instance (provided you're in the same JVM/Classloader) and uses it for your transport. Therefore, if you've generated a client from WSDL, invoking a service over Mule can be as simple as the following:
Building a Client Proxy
Following is an example of how to construct a client using the service that was developed in Building Web Services with CXF:
Simple Frontend Clients
You can build a client for your simple frontend based services with out the need to generate a client from WSDL. To do this, you need a copy of your service interface and all your data objects locally to use. This can simplify consuming web services if you already have access to the code used to build the service.