Child pages
  • Service Routing
Skip to end of metadata
Go to start of metadata

Service Routing

One thing you'll often need to do when developing services, is to develop a new version while keeping the old version running. This guide shows how to develop a simple service router that will scan the incoming message then direct the message to the appropriate service version.

For more complex requirements you might also wish to check out Apache Camel for full support for the Enterprise Integration Patterns with CXF

One common practice to version web services is using XML namespaces to clearly delineate the versions of a document that are compatible. For example:

Among many different possible implementations of service routing, one simple way ("simple" in terms of amount of code you have to write, but it does require a certain extent of familiarity with CXF internal architecture) to do this is by writing a CXF interceptor that acts as a routing mediator.

Firstly we need to have a dummy service with an intermediary interceptor registered. This intermediary interceptor sits at the very beginning of the interceptor chain, this is to make sure the intermediary interceptor is the first interceptor being invoked in the message pipeline. The intermediary interceptor scans the incoming message for example, the schema namespace, then directs the message to the desired endpoint according to user programmed strategy.

Lets see the code:

Example 1: The server - this server has three endpoints: one endpoint for the dummy service, another two endpoints are different versions of Greeter service
Example 2: The intermediary interceptor

A few things to note:

  1. The MediatorInInterceptor is for SOAP binding, you can write a similar interceptor for XML binding etc.
  2. We call chain.abort at the end of this interceptor to stop any further processing in the dummy service.
  3. In this example, implementor1 and implementor2 are published using local transport. This is achieved by using an address like "local://SoapContext/version1/SoapPort". The MediatorInInterceptor looks up ServerRegistry to find endpoints hosted in the server then does the re-dispatch.
  4. The MediatorInInterceptor is set to POST_STREAM phase and before StaxInInterceptor, this makes sure it is the very first interceptor to be invoked.
  • No labels