You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

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

Building Services

JAX-WS Annotated Services from Java

The JAX-WS APIs include a set of annotations which allow you to build services using annotated classes. These services are based on a single class which contains a set of operations.

Here's a simple example:

@WebService
public class Hello {
  public String sayHi(String name) {
    return "Hello " + name;
  }
}

JAX-WS includes many more annotations as well such as:

  • @WebMethod - allows you to customize the operation name, exclude the operation from inclusion in the service, etc
  • @WebParam - allows you to customize a parameter's name, namespace, direction (IN or OUT), etc
  • @WebResult - allows you to customize a parameter's name, namespace, direction (IN or OUT), etc

Data is marshalled from XML to Java and vis a versa via the JAXB data-binding.

Services are publish via one of two means:

  • The JAX-WS standard Endpoint APIs
  • CXF's XML configuration format - i.e. <jaxws:endpoint ... />

More Information: A simple JAX-WS service, Developing a JAX-WS Service (goes into much more depth)

JAX-WS Annotated Services from WSDL

If you have existing WSDLs for your service or wish to write your WSDL first and then generate classes, CXF has many tools to help you do this.

  • maven plugin
  • wsdl2soap, etc
  • ant
  • API?

JAX-WS Providers

JAX-WS Providers allow you to create services which work at the message level - as opposed to the operation level as with annotated classes. The have a single operation "invoke" which receives either the message payload (i.e. the SOAP Body) or the whole message itself (i.e. the SOAP Envelope).

Here's a simple example:

@WebServiceProvider
public class HelloProvider {
  public Source invoke(Source request) {
    return ....;
  }
}

Services are publish via one of two means:

  • The JAX-WS standard Endpoint APIs
  • CXF's XML configuration format - i.e. <jaxws:endpoint ... />

More Information: Developing a JAX-WS Service

Simple Frontend

Sometimes you don't want to annotate classes or use the JAX-WS APIs. CXF includes a Simple Frontend which allows you to take nearly any class and make a service out of it with absolutely no extra work. This is great for those services which are simple or are quick prototypes.

CXF uses the JAXB databinding as the default, but you can use the Aegis data-binding for even more simplicity. Whereas JAXB forces you to annotate your classes, Aegis works with no annotations at all and also supports a wide variety of data-types out of the box, including things like Maps and Sets.

Services are publish via one of two means:

  • ServerFactoryBeans - these allow programmatic publishing of an endpoint
  • CXF's XML configuration format - i.e. <simple:server ... />

Transports and Bindings

  • No labels