cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrea Smyth <>
Subject Re: Programatically installing interceptors per (Bus|Service|Endpoint)
Date Wed, 21 Mar 2007 08:10:57 GMT
Fred Dushin wrote:

> I understand that CXF provides APIs for installed interceptors  
> through the InterceptorProvider interface, which the Bus, Endpoint,  
> and Service types all extend (among other types).
> Suppose I want to create, via configuration, some sort of CXF plugin  
> (I hesitate to call this an interceptor, for reasons which should  
> become obvious).  The purpose of this plugin is to install  
> interceptors programatically into the call chain.
> I can see how to do this using a reference to a Bus -- e.g., I can  
> spring-load the plugin I want to install, and wire it up to the Bus  
> -- common pattern.  And from there, I can get access to the Bus-level  
> InterceptorProvider, since the Bus extends that type.
> That would work in the case where I want my plugin to install these  
> interceptors globally, i.e, for all services and endpoints in a Bus;   
> however, suppose I want to install my interceptors at a finer level  
> of granularity, e.g., per endpoint.  Is there a way for my plugin,  
> which seems to be loaded at Bus initialization time, to get a handle  
> on the Service or Endpoint (which also implement InterceptorProvider)  
> for which it is (or counterfactually would be) configured?  Is this  
> an envisioned pattern?  Or is there some other sort of interceptor I  
> don't know of, e.g, which hooks into Service or Endpoint creation?
> Thanks!
> -Fred

Hi Fred,

On the client side you can manage interceptors at the client, endpoint, 
service and bus level. If you have created your proxy using JAXWS APIs, 
you need to first obtain a reference to the underlying CXF client object 
as follows:

BasicGreeterService gs = new BasicGreeterService();
Greeter greeter = gs.getGreeterPort();

org.apache.cxf.endpoint.Client client = 
org.apache.cxf.endpoint.Endpoint endpoint = client.getEndpoint();
org.apache.cxf.service.Service service = endpoint.getService();

On the server side, if you use the JAXWS API, cast the object you obtained from publish to get access to 
its underlying CXF endpoint. Note that Server - unlike Client - is not 
an interceptor provider, which is a bit asymmetric. jaxwsEndpoint ="http://localhost:9020/SoapContext/GreeterPort", 
new GreeterImpl(););
LoggingOutInterceptor out = new LoggingOutInterceptor();
org.apache.cxf.jaxws.EndpointImpl jaxwsEndpointImpl = 
org.apache.cxf.endpoint.Server server = jaxwsEndpointImpl.getServer();
org.apache.cxf.endpoint.Endpoint endpoint = server.getEndpoint();
org.apache.cxf.service.Service service = endpoint.getService();

You can also have an interceptor installed at bus level which, when 
executing, adds further interceptors to the chain, possibly on a per 
message basis. This is done for example in


View raw message