Chapter 39. Provider-Based Route

download PDF

39.1. Provider-Based JAX-WS Endpoint


Use the provider-based approach, if you need to process very large Web services messages. The provider-based approach is a variant of the PAYLOAD data format that enables you to encode the message body as an XML streaming type, such as SAXSource. Since the XMLstreaming types are more efficient than DOM objects, the provider-based approach is ideal for large XML messages.

Demonstration location

The code presented in this chapter is taken from the following demonstration:
For details of how to download and install the demonstration code, see Chapter 33, Demonstration Code for Camel/CXF

Camel CXF component

The Camel CXF component is an Apache CXF component that integrates Web services with routes. You can use it either to instantiate consumer endpoints (at the start of a route), which behave like Web service instances, or to instantiate producer endpoints (at any other points in the route), which behave like WS clients.
Came CXF endpoints—which are instantiated using the cxf:cxfEndpoint XML element and are implemented by the Apache Camel project—are not to be confused with the Apache CXF JAX-WS endpoints—which are instantiated using the jaxws:endpoint XML element and are implemented by the Apache CXF project.

Provider-based approach and the PAYLOAD data format

The provider-based approach is a variant of the PAYLOAD data format, which is enabled as follows:
  • Define a custom<StreamType> class, where the StreamType type is an XML streaming type, such as SAXSource.
  • The PAYLOAD data format is selected by an annotation on the custom Provider<?> class (see the section called “The SAXSourceService provider class”).
  • The custom Provider<?> class is referenced by setting the serviceClass attribute of the cxf:cxfEndpoint element in XML configuration.
The provider-based approach has the following characteristics:
  • Enables you to access the message body as a streamed XML type—for example, javax.xml.transform.sax.SAXSource.
  • No JAX-WS or JAXB stub code required.
  • The SOAP body is marshalled into a stream-based SAXSource type.
  • The SOAP headers are converted into headers in the exchange's In message, of org.apache.cxf.binding.soap.SoapHeader type.

Implementing and building a provider-based route

To implement and build the demonstration provider-based route, starting from scratch, you would perform the following steps:
  1. Define a custom<StreamType> class (the current demonstration uses SAXSource as the StreamType type).
  2. Instantiate the Camel CXF endpoint in Spring, using the cxf:cxfEndpoint element and reference the custom provider class (using the serviceClass attribute).
  3. Implement the route in XML, where you can use the content-based router to sort requests by operation name.
  4. For each operation, define a processor bean to process the request.
  5. Define velocity templates for generating the reponse messages.
  6. Define a custom type converter, to support converting a String message body to a SAXSource message body.

Sample provider-based route

Figure 39.1, “Sample Provider-Based Route” shows an outline of the route that is used to process the operations of the CustomerService Web service using the provider-based approach. After sorting the request messages by operation name, an operation-specific processor bean reads the incoming request parameters. Finally, the response messages are generated using Velocity templates.

Figure 39.1. Sample Provider-Based Route

Sample Provider-Based Route
Red Hat logoGithubRedditYoutubeTwitter


Try, buy, & sell


About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.