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.
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:
A few things to note:
MediatorInInterceptoris for SOAP binding, you can write a similar interceptor for XML binding etc.
- We call
chain.abortat the end of this interceptor to stop any further processing in the dummy service.
- In this example,
implementor2are published using local transport. This is achieved by using an address like "local://SoapContext/version1/SoapPort". The
ServerRegistryto find endpoints hosted in the server then does the re-dispatch.
MediatorInInterceptoris set to
POST_STREAMphase and before
StaxInInterceptor, this makes sure it is the very first interceptor to be invoked.