Search in sources :

Example 16 with BindingFactoryManager

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

the class Wsdl11AttachmentPolicyProviderTest method oneTimeSetUp.

@BeforeClass
public static void oneTimeSetUp() throws Exception {
    IMocksControl control = EasyMock.createNiceControl();
    Bus bus = control.createMock(Bus.class);
    WSDLManager manager = new WSDLManagerImpl();
    WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    EasyMock.expect(bus.getExtension(DestinationFactoryManager.class)).andReturn(dfm).anyTimes();
    EasyMock.expect(dfm.getDestinationFactory(EasyMock.isA(String.class))).andReturn(null).anyTimes();
    BindingFactoryManager bfm = control.createMock(BindingFactoryManager.class);
    EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bfm).anyTimes();
    EasyMock.expect(bfm.getBindingFactory(EasyMock.isA(String.class))).andReturn(null).anyTimes();
    control.replay();
    int n = 19;
    services = new ServiceInfo[n];
    endpoints = new EndpointInfo[n];
    for (int i = 0; i < n; i++) {
        String resourceName = "/attachment/wsdl11/test" + i + ".wsdl";
        URL url = Wsdl11AttachmentPolicyProviderTest.class.getResource(resourceName);
        try {
            services[i] = builder.buildServices(manager.getDefinition(url.toString())).get(0);
        } catch (WSDLException ex) {
            ex.printStackTrace();
            fail("Failed to build service from resource " + resourceName);
        }
        assertNotNull(services[i]);
        endpoints[i] = services[i].getEndpoints().iterator().next();
        assertNotNull(endpoints[i]);
    }
    control.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) Bus(org.apache.cxf.Bus) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) WSDLException(javax.wsdl.WSDLException) WSDLServiceBuilder(org.apache.cxf.wsdl11.WSDLServiceBuilder) WSDLManager(org.apache.cxf.wsdl.WSDLManager) WSDLManagerImpl(org.apache.cxf.wsdl11.WSDLManagerImpl) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Example 17 with BindingFactoryManager

use of org.apache.cxf.binding.BindingFactoryManager in project tomee by apache.

the class CxfUtil method initDefaultBus.

private static Bus initDefaultBus() {
    final ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(CxfUtil.class.getClassLoader());
    try {
        // create the bus reusing cxf logic but skipping factory lookup
        final Bus bus = BusFactory.newInstance(CXFBusFactory.class.getName()).createBus();
        bus.setId(SystemInstance.get().getProperty("openejb.cxf.bus.id", "openejb.cxf.bus"));
        final BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
        bindingFactoryMap = (Map<String, BindingFactory>) Reflections.get(bfm, "bindingFactories");
        bus.setExtension(new OpenEJBHttpDestinationFactory(), HttpDestinationFactory.class);
        // ensure client proxies can use app classes
        CXFBusFactory.setDefaultBus(Bus.class.cast(Proxy.newProxyInstance(CxfUtil.class.getClassLoader(), new Class<?>[] { Bus.class }, new ClientAwareBusHandler())));
        bus.setProperty(ClassUnwrapper.class.getName(), new ClassUnwrapper() {

            @Override
            public Class<?> getRealClass(final Object o) {
                final Class<?> aClass = o.getClass();
                Class<?> c = aClass;
                while (c.getName().contains("$$")) {
                    c = c.getSuperclass();
                }
                return c == Object.class ? aClass : c;
            }

            @Override
            public Class<?> getRealClassFromClass(Class<?> aClass) {
                return aClass;
            }

            @Override
            public Object getRealObject(Object o) {
                // straight on the proxy
                if (o instanceof OwbInterceptorProxy) {
                    return getProxiedInstance(o);
                }
                return o;
            }

            private Object getProxiedInstance(Object o) {
                try {
                    final Field field = o.getClass().getDeclaredField(FIELD_INTERCEPTOR_HANDLER);
                    field.setAccessible(true);
                    final Object fieldValue = field.get(o);
                    if (fieldValue instanceof DefaultInterceptorHandler) {
                        final DefaultInterceptorHandler handler = (DefaultInterceptorHandler) fieldValue;
                        return handler.getTarget();
                    } else {
                        throw new IllegalStateException("Expected OwbInterceptorProxy handler to be an instance of Default Interceptor Handler.");
                    }
                } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        SystemInstance.get().addObserver(new LifecycleManager());
        initAuthenticators();
        // we keep as internal the real bus and just expose to cxf the client aware bus to be able to cast it easily
        return bus;
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
}
Also used : Bus(org.apache.cxf.Bus) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) ClassUnwrapper(org.apache.cxf.common.util.ClassUnwrapper) Field(java.lang.reflect.Field) DefaultInterceptorHandler(org.apache.webbeans.intercept.DefaultInterceptorHandler) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) OpenEJBHttpDestinationFactory(org.apache.openejb.server.cxf.transport.OpenEJBHttpDestinationFactory) OwbInterceptorProxy(org.apache.webbeans.proxy.OwbInterceptorProxy) BindingFactory(org.apache.cxf.binding.BindingFactory)

Example 18 with BindingFactoryManager

use of org.apache.cxf.binding.BindingFactoryManager in project tomee by apache.

the class CxfRSService method init.

@Override
public void init(final Properties properties) throws Exception {
    super.init(properties);
    config = properties;
    factoryByListener = "true".equalsIgnoreCase(properties.getProperty("openejb.cxf-rs.factoryByListener", "false"));
    System.setProperty("org.apache.johnzon.max-string-length", SystemInstance.get().getProperty("org.apache.johnzon.max-string-length", properties.getProperty("org.apache.johnzon.max-string-length", "8192")));
    SystemInstance.get().setComponent(RESTResourceFinder.class, new CxfRESTResourceFinder());
    try {
        CUTask.addContainerListener(new CUTask.ContainerListener() {

            @Override
            public Object onCreation() {
                return Contexts.state();
            }

            @Override
            public Object onStart(final Object state) {
                return Contexts.restore(state);
            }

            @Override
            public void onEnd(final Object oldState) {
                Contexts.restore(oldState);
            }
        });
    } catch (final Throwable th) {
    // unlikely but means the container core has been customized so just ignore it
    }
    CxfUtil.configureBus();
    final Bus bus = CxfUtil.getBus();
    final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(CxfUtil.initBusLoader());
    try {
        // force init of bindings
        if (!CxfUtil.hasService(JAXRSBindingFactory.JAXRS_BINDING_ID)) {
            // cxf does it but with the pattern "if not here install it". It is slow so installing it without testing for presence here.
            final BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
            try {
                bfm.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, new JAXRSBindingFactory(bus));
            } catch (Throwable b) {
            // no-op
            }
        }
        initCxfProviders(bus);
    } finally {
        if (oldLoader != null) {
            CxfUtil.clearBusLoader(oldLoader);
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) JAXRSBindingFactory(org.apache.cxf.jaxrs.JAXRSBindingFactory) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) CUTask(org.apache.openejb.threads.task.CUTask)

Example 19 with BindingFactoryManager

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

the class CXFBusImplTest method testConstructionWithExtensions.

@Test
public void testConstructionWithExtensions() throws BusException {
    IMocksControl control;
    BindingFactoryManager bindingFactoryManager;
    InstrumentationManager instrumentationManager;
    PhaseManager phaseManager;
    control = EasyMock.createNiceControl();
    Map<Class<?>, Object> extensions = new HashMap<>();
    bindingFactoryManager = control.createMock(BindingFactoryManager.class);
    instrumentationManager = control.createMock(InstrumentationManager.class);
    phaseManager = control.createMock(PhaseManager.class);
    extensions.put(BindingFactoryManager.class, bindingFactoryManager);
    extensions.put(InstrumentationManager.class, instrumentationManager);
    extensions.put(PhaseManager.class, phaseManager);
    Bus bus = new ExtensionManagerBus(extensions);
    assertSame(bindingFactoryManager, bus.getExtension(BindingFactoryManager.class));
    assertSame(instrumentationManager, bus.getExtension(InstrumentationManager.class));
    assertSame(phaseManager, bus.getExtension(PhaseManager.class));
}
Also used : IMocksControl(org.easymock.IMocksControl) Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) PhaseManager(org.apache.cxf.phase.PhaseManager) HashMap(java.util.HashMap) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) InstrumentationManager(org.apache.cxf.management.InstrumentationManager) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Test(org.junit.Test)

Example 20 with BindingFactoryManager

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

the class DocLiteralInInterceptorTest 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) DocLiteralInInterceptor(org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) BindingFactory(org.apache.cxf.binding.BindingFactory) Before(org.junit.Before)

Aggregations

BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)33 Bus (org.apache.cxf.Bus)15 DestinationFactoryManager (org.apache.cxf.transport.DestinationFactoryManager)11 WSDLServiceBuilder (org.apache.cxf.wsdl11.WSDLServiceBuilder)8 Before (org.junit.Before)8 BindingInfo (org.apache.cxf.service.model.BindingInfo)7 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)7 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)7 IMocksControl (org.easymock.IMocksControl)7 Definition (javax.wsdl.Definition)6 BusException (org.apache.cxf.BusException)6 BindingFactory (org.apache.cxf.binding.BindingFactory)6 Test (org.junit.Test)6 Service (javax.wsdl.Service)5 WSDLReader (javax.wsdl.xml.WSDLReader)5 QName (javax.xml.namespace.QName)5 SoapBindingInfo (org.apache.cxf.binding.soap.model.SoapBindingInfo)5 JAXRSBindingFactory (org.apache.cxf.jaxrs.JAXRSBindingFactory)5 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)4 WSDLFactory (javax.wsdl.factory.WSDLFactory)3