I've been creating a BusConfiguratorFeature to be able to consolidate the
setup of features, interceptors, etc. in a single bundle and then apply this
to the CXF Bus of a given name when it gets registered. Invariably
developers at organizations I go to spam configuration and set up of busses
across all their bundles.

 

Basically it is address this issue:

https://cwiki.apache.org/confluence/display/CXF/Grouping+bundles+to+applicat
ions+in+OSGi

 

I'm rarely at a client's site where the setup of services across bundles is
identical. Different department, software stacks, etc. all seem to have
different flavors. The issue with the way Features work is that when you
install it, it is applied to every CXF Bus instance that gets created.

 

Basically I'm piggybacking on that and creating an internal registry/Map of
bus id to bus configuration object. I also have some mixins that allow for
some pluggable behavior. This works well but I'm not entirely happy with it
as implementing the Feature gets a lot of notifications I don't really care
about (for example, client, provider, server, etc.) and just leave them
blank right now. 

 

This let's me as coarse or granular in the configuration as I want. I set
these up in Blueprint as most of the different setups for things like
JAASAuthenticationFeature or as simple as logging providers are in Blueprint
or at least most examples are. 

 

I was thinking about re-implementing the BusConfiguratorFeature as a DS
component that would listen for BusConfigurationBeans and add/remove/update
them from the registry and listen for Bus registration and apply
configurations, if any, are applicable, when it is received. I've used DS in
the past but usually it is simple @Reference injection and service export.

In this case I'd need a component that would listen for
BusConfigurationBeans and add/update the registry and also listen for Bus
registration and apply the configurations - but I don't need to keep the Bus
in a list. It wouldn't be stateful.

 

Are there any good examples, perhaps from PAX or Karaf projects themselves,
where I might get a good sample?

 

public class BusConfiguratorFeature extends WebServiceFeature implements
Feature {

 

                

                //Avoid nulls...

                private Map<String, BusConfiguratorBean>
configuratorRegistry = new HashMap<String,BusConfiguratorBean>();

 

 

                public void setConfigurators(Map<String,
BusConfiguratorBean>

configurators) {

                                this.configuratorRegistry = configurators;

                                                

                }

//Basically this is the only even I really want notification about. 

                @Override

                public void initialize(Bus bus) {

                                BusConfiguratorBean configurator =
configuratorRegistry.get(bus.getId());

                                if(configurator!=null)

                                                configurator.setBus(bus);

 

                }

//The configurator bean.

public class BusConfiguratorBean {

 

                /** The interceptorProviders. */

                private List<InterceptorProvider> interceptorProviders = new
ArrayList<InterceptorProvider>();

                private List<Feature> features = new ArrayList<Feature>();

 

                private Map<String, Object> properties = new
HashMap<String,Object>();

 

                public void setBus(Bus bus) {

 

                                                for (InterceptorProvider
provider : interceptorProviders) {

 
bus.getInFaultInterceptors().addAll(provider.getInFaultInterceptors());

                                                

bus.getOutFaultInterceptors().addAll(provider.getOutFaultInterceptors());

 
bus.getInInterceptors().addAll(provider.getInInterceptors());

 
bus.getOutInterceptors().addAll(provider.getOutInterceptors());

 

                                                }

 
bus.getFeatures().addAll(features);

 
bus.setProperties(this.properties);

                                

                                                //System.out.println("The
rolled up properties: "+ bus.getProperties());

                                

                }

 

public class BusConfigurationMixin implements InterceptorProvider {

 

                protected ModCountCopyOnWriteArrayList<Interceptor&lt;?
extends Message>> inInterceptors = new
ModCountCopyOnWriteArrayList<Interceptor&lt;? extends

Message>>();

                protected ModCountCopyOnWriteArrayList<Interceptor&lt;?
extends Message>> outInterceptors = new
ModCountCopyOnWriteArrayList<Interceptor&lt;? extends

Message>>();

                protected ModCountCopyOnWriteArrayList<Interceptor&lt;?
extends Message>> outFaultInterceptors = new
ModCountCopyOnWriteArrayList<Interceptor&lt;?

extends Message>>();

                protected ModCountCopyOnWriteArrayList<Interceptor&lt;?
extends Message>> inFaultInterceptors = new
ModCountCopyOnWriteArrayList<Interceptor&lt;?

extends Message>>();

                protected Map<String,Object> properties = new
HashMap<String,Object>();

 

 

Reply via email to