Language and Page Formatting Options
Chapter 37. Provider-Based Route
37.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.
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 31, 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:cxfEndpointXML 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:endpointXML 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
javax.xml.ws.Provider<StreamType>class, where the StreamType type is an XML streaming type, such as
- 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
serviceClassattribute of the
cxf:cxfEndpointelement 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,
- No JAX-WS or JAX-B stub code required.
- The SOAP body is marshalled into a stream-based
- The SOAP headers are converted into headers in the exchange's In message, of
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:
- Define a custom
javax.xml.ws.Provider<StreamType>class (the current demonstration uses
SAXSourceas the StreamType type).
- Instantiate the Camel CXF endpoint in Spring, using the
cxf:cxfEndpointelement and reference the custom provider class (using the
- Implement the route in XML, where you can use the content-based router to sort requests by operation name.
- For each operation, define a processor bean to process the request.
- Define velocity templates for generating the reponse messages.
- Define a custom type converter, to support converting a
Stringmessage body to a
Sample provider-based route
Figure 37.1, “Sample Provider-Based Route” shows an outline of the route that is used to process the operations of the
CustomerServiceWeb 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 37.1. Sample Provider-Based Route