Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
xml
xml
    <wsdl:types>
        <schema
             targetNamespace="http://apache.org/2007/03/21/hello_world_xml_http/mixed/types"
             xmlns="http://www.w3.org/2001/XMLSchema">
             <element name="sayHi">
                 <complexType />
             </element>  

             ..........     

         </schema>
    </wsdl:types>

Among many different possible implementations of service routing, one simple way ("simple" in terms of amount of codes you have to write, but it does require a certain extent of familiarity with CXF internal architectures) to do this is 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 is positioned at the very beginning of the interceptor chain, which is to make sure the intermediary interceptor will be the first interceptor being invoked in the message pipeline. The intermediary interceptor will scan the incoming message for example, detect the schema namespace, then direct the message to the desired endpoint according to user defined programmed strategy.

Lets see the code:

...

  1. The MediatorInInterceptor is for SOAP binding, you can write a similar interceptor for xml binding etcXML binding etc.
  2. In this example, the MediatorInInterceptor redirects the request to endpoints that are hosted in the same server, this way we do not need to go through transport again. But if you are going to do a transport bridging (eg, jms-to-http) or your services cannot be hosted in a same server with the dummy service, you can initiate a client proxy in the interceptor to invoke the real endpoint.
  3. The MediatorInInterceptor is set to POST_STREAM phase and before StaxInInterceptor, this makes sure it is the very first interceptor to be invoked.
  4. We call chain.abort at the end of this interceptor to stop any further processing of in the dummy service.