Search in sources :

Example 1 with BindingFactory

use of org.apache.cxf.binding.BindingFactory in project cxf by apache.

the class BindingFactoryManagerImpl method loadAll.

private BindingFactory loadAll(final String namespace) {
    // Try old method of having activationNamespaces configured in.
    // It activates all the factories in the list until one matches, thus
    // it activates stuff that really aren't needed.
    ConfiguredBeanLocator.BeanLoaderListener<BindingFactory> listener = new ConfiguredBeanLocator.BeanLoaderListener<BindingFactory>() {

        public boolean beanLoaded(String name, BindingFactory bean) {
            loaded.add(name);
            if (!bindingFactories.containsKey(namespace)) {
                if (bean instanceof AbstractBindingFactory) {
                    for (String ns : ((AbstractBindingFactory) bean).getActivationNamespaces()) {
                        registerBindingFactory(ns, bean);
                    }
                } else {
                    try {
                        Method m = bean.getClass().getMethod("getActivationNamespace");
                        Collection<String> c = CastUtils.cast((Collection<?>) m.invoke(bean));
                        for (String s : c) {
                            registerBindingFactory(s, bean);
                        }
                    } catch (Exception ex) {
                    // ignore
                    }
                }
            }
            return bindingFactories.containsKey(namespace);
        }

        public boolean loadBean(String name, Class<? extends BindingFactory> type) {
            return !bindingFactories.containsKey(namespace) && !loaded.contains(name);
        }
    };
    bus.getExtension(ConfiguredBeanLocator.class).loadBeansOfType(BindingFactory.class, listener);
    return bindingFactories.get(namespace);
}
Also used : ConfiguredBeanLocator(org.apache.cxf.configuration.ConfiguredBeanLocator) AbstractBindingFactory(org.apache.cxf.binding.AbstractBindingFactory) Method(java.lang.reflect.Method) BusException(org.apache.cxf.BusException) BindingFactory(org.apache.cxf.binding.BindingFactory) AbstractBindingFactory(org.apache.cxf.binding.AbstractBindingFactory)

Example 2 with BindingFactory

use of org.apache.cxf.binding.BindingFactory in project cxf by apache.

the class BindingFactoryManagerImpl method loadActivationNamespace.

private BindingFactory loadActivationNamespace(final String namespace) {
    final ConfiguredBeanLocator locator = bus.getExtension(ConfiguredBeanLocator.class);
    // Second attempt will be to examine the factory class
    // for a DEFAULT_NAMESPACES field and if it doesn't exist, try
    // using the older activation ns things.  This will then load most
    // of the "older" things
    ConfiguredBeanLocator.BeanLoaderListener<BindingFactory> listener = new ConfiguredBeanLocator.BeanLoaderListener<BindingFactory>() {

        public boolean beanLoaded(String name, BindingFactory bean) {
            loaded.add(name);
            return bindingFactories.containsKey(namespace);
        }

        public boolean loadBean(String name, Class<? extends BindingFactory> type) {
            if (loaded.contains(name)) {
                return false;
            }
            try {
                type.getField("DEFAULT_NAMESPACES");
                return false;
            } catch (Exception ex) {
            // ignore
            }
            return locator.hasConfiguredPropertyValue(name, "activationNamespaces", namespace);
        }
    };
    locator.loadBeansOfType(BindingFactory.class, listener);
    return bindingFactories.get(namespace);
}
Also used : ConfiguredBeanLocator(org.apache.cxf.configuration.ConfiguredBeanLocator) BusException(org.apache.cxf.BusException) BindingFactory(org.apache.cxf.binding.BindingFactory) AbstractBindingFactory(org.apache.cxf.binding.AbstractBindingFactory)

Example 3 with BindingFactory

use of org.apache.cxf.binding.BindingFactory in project cxf by apache.

the class BindingFactoryManagerImpl method loadDefaultNamespace.

private BindingFactory loadDefaultNamespace(final String namespace) {
    // First attempt will be to examine the factory class
    // for a DEFAULT_NAMESPACES field and use it
    ConfiguredBeanLocator.BeanLoaderListener<BindingFactory> listener = new ConfiguredBeanLocator.BeanLoaderListener<BindingFactory>() {

        public boolean beanLoaded(String name, BindingFactory bean) {
            loaded.add(name);
            return bindingFactories.containsKey(namespace);
        }

        public boolean loadBean(String name, Class<? extends BindingFactory> type) {
            if (!loaded.contains(name)) {
                try {
                    Field f = type.getField("DEFAULT_NAMESPACES");
                    Object o = f.get(null);
                    if (o instanceof Collection) {
                        Collection<String> c = CastUtils.cast((Collection<?>) o);
                        return c.contains(namespace);
                    }
                } catch (Exception ex) {
                // ignore
                }
            }
            return false;
        }
    };
    bus.getExtension(ConfiguredBeanLocator.class).loadBeansOfType(BindingFactory.class, listener);
    return bindingFactories.get(namespace);
}
Also used : Field(java.lang.reflect.Field) ConfiguredBeanLocator(org.apache.cxf.configuration.ConfiguredBeanLocator) Collection(java.util.Collection) BusException(org.apache.cxf.BusException) BindingFactory(org.apache.cxf.binding.BindingFactory) AbstractBindingFactory(org.apache.cxf.binding.AbstractBindingFactory)

Example 4 with BindingFactory

use of org.apache.cxf.binding.BindingFactory in project cxf by apache.

the class BareInInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    bus = BusFactory.newInstance().createBus();
    BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
    IMocksControl control = createNiceControl();
    BindingFactory bf = control.createMock(BindingFactory.class);
    Binding binding = control.createMock(Binding.class);
    expect(bf.createBinding(null)).andStubReturn(binding);
    expect(binding.getInFaultInterceptors()).andStubReturn(new ArrayList<Interceptor<? extends Message>>());
    expect(binding.getOutFaultInterceptors()).andStubReturn(new ArrayList<Interceptor<? extends Message>>());
    bfm.registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/", bf);
}
Also used : IMocksControl(org.easymock.IMocksControl) Binding(org.apache.cxf.binding.Binding) Message(org.apache.cxf.message.Message) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) BareInInterceptor(org.apache.cxf.wsdl.interceptors.BareInInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) BindingFactory(org.apache.cxf.binding.BindingFactory) Before(org.junit.Before)

Example 5 with BindingFactory

use of org.apache.cxf.binding.BindingFactory in project cxf by apache.

the class EndpointImpl method createBinding.

final void createBinding(BindingInfo bi) throws EndpointException {
    if (null != bi) {
        String namespace = bi.getBindingId();
        try {
            final BindingFactory bf = bus.getExtension(BindingFactoryManager.class).getBindingFactory(namespace);
            if (null == bf) {
                Message msg = new Message("NO_BINDING_FACTORY", BUNDLE, namespace);
                throw new EndpointException(msg);
            }
            binding = bf.createBinding(bi);
        } catch (BusException ex) {
            throw new EndpointException(ex);
        }
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) BusException(org.apache.cxf.BusException) BindingFactory(org.apache.cxf.binding.BindingFactory)

Aggregations

BindingFactory (org.apache.cxf.binding.BindingFactory)13 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)9 BusException (org.apache.cxf.BusException)7 AbstractBindingFactory (org.apache.cxf.binding.AbstractBindingFactory)4 QName (javax.xml.namespace.QName)3 Binding (org.apache.cxf.binding.Binding)3 ConfiguredBeanLocator (org.apache.cxf.configuration.ConfiguredBeanLocator)3 Interceptor (org.apache.cxf.interceptor.Interceptor)3 Message (org.apache.cxf.message.Message)3 BindingInfo (org.apache.cxf.service.model.BindingInfo)3 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)3 IMocksControl (org.easymock.IMocksControl)3 Before (org.junit.Before)3 Field (java.lang.reflect.Field)2 Message (org.apache.cxf.common.i18n.Message)2 EndpointImpl (org.apache.cxf.endpoint.EndpointImpl)2 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 BindingFault (javax.wsdl.BindingFault)1 BindingOperation (javax.wsdl.BindingOperation)1