Search in sources :

Example 11 with ExtensionManagerBus

use of org.apache.cxf.bus.extension.ExtensionManagerBus in project cxf by apache.

the class CXFBusImplTest method testExtensions.

@Test
public void testExtensions() {
    Bus bus = new ExtensionManagerBus();
    String extension = "CXF";
    bus.setExtension(extension, String.class);
    assertSame(extension, bus.getExtension(String.class));
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Test(org.junit.Test)

Example 12 with ExtensionManagerBus

use of org.apache.cxf.bus.extension.ExtensionManagerBus in project cxf by apache.

the class JettyHTTPDestinationTest method setUpDestination.

private JettyHTTPDestination setUpDestination(boolean contextMatchOnStem, boolean mockedBus) throws Exception {
    policy = new HTTPServerPolicy();
    address = getEPR("bar/foo");
    transportFactory = new HTTPTransportFactory();
    final ConduitInitiator ci = new ConduitInitiator() {

        public Conduit getConduit(EndpointInfo targetInfo, Bus b) throws IOException {
            return decoupledBackChannel;
        }

        public Conduit getConduit(EndpointInfo localInfo, EndpointReferenceType target, Bus b) throws IOException {
            return decoupledBackChannel;
        }

        public List<String> getTransportIds() {
            return null;
        }

        public Set<String> getUriPrefixes() {
            return new HashSet<>(Collections.singletonList("http"));
        }
    };
    ConduitInitiatorManager mgr = new ConduitInitiatorManager() {

        public void deregisterConduitInitiator(String name) {
        }

        public ConduitInitiator getConduitInitiator(String name) throws BusException {
            return null;
        }

        public ConduitInitiator getConduitInitiatorForUri(String uri) {
            return ci;
        }

        public void registerConduitInitiator(String name, ConduitInitiator factory) {
        }
    };
    if (!mockedBus) {
        bus = new ExtensionManagerBus();
        bus.setExtension(mgr, ConduitInitiatorManager.class);
    } else {
        bus = EasyMock.createMock(Bus.class);
        bus.getExtension(EndpointResolverRegistry.class);
        EasyMock.expectLastCall().andReturn(null);
        bus.getExtension(ContinuationProviderFactory.class);
        EasyMock.expectLastCall().andReturn(null).anyTimes();
        bus.getExtension(PolicyDataEngine.class);
        EasyMock.expectLastCall().andReturn(null).anyTimes();
        bus.hasExtensionByName("org.apache.cxf.ws.policy.PolicyEngine");
        EasyMock.expectLastCall().andReturn(false);
        bus.getExtension(ClassLoader.class);
        EasyMock.expectLastCall().andReturn(this.getClass().getClassLoader());
        EasyMock.replay(bus);
    }
    engine = EasyMock.createNiceMock(JettyHTTPServerEngine.class);
    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setName(new QName("bla", "Service"));
    endpointInfo = new EndpointInfo(serviceInfo, "");
    endpointInfo.setName(new QName("bla", "Port"));
    endpointInfo.setAddress(NOWHERE + "bar/foo");
    endpointInfo.addExtensor(policy);
    engine.addServant(EasyMock.eq(new URL(NOWHERE + "bar/foo")), EasyMock.isA(JettyHTTPHandler.class));
    EasyMock.expectLastCall();
    engine.getContinuationsEnabled();
    EasyMock.expectLastCall().andReturn(true);
    EasyMock.replay(engine);
    JettyHTTPDestination dest = new EasyMockJettyHTTPDestination(bus, transportFactory.getRegistry(), endpointInfo, null, engine);
    dest.retrieveEngine();
    policy = dest.getServer();
    observer = new MessageObserver() {

        public void onMessage(Message m) {
            inMessage = m;
            threadDefaultBus = BusFactory.getThreadDefaultBus();
        }
    };
    dest.setMessageObserver(observer);
    return dest;
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) URL(java.net.URL) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) HashSet(java.util.HashSet)

Example 13 with ExtensionManagerBus

use of org.apache.cxf.bus.extension.ExtensionManagerBus in project cxf by apache.

the class ClientProviderFactoryTest method testParameterHandlerProviderWithConstraints.

@Test
public void testParameterHandlerProviderWithConstraints() throws Exception {
    final Bus bus = new ExtensionManagerBus();
    final ProviderFactory pf = ClientProviderFactory.createInstance(bus);
    @ConstrainedTo(RuntimeType.SERVER)
    class ServerParameterHandler extends CustomerParameterHandler {
        // Server parameter handler
    }
    @ConstrainedTo(RuntimeType.CLIENT)
    class ClientParameterHandler extends CustomerParameterHandler {
        // Client parameter handler
    }
    ParamConverterProvider h = new ServerParameterHandler();
    ParamConverterProvider hp = new ClientParameterHandler();
    pf.registerUserProvider(h);
    pf.registerUserProvider(hp);
    ParamConverter<Customer> h2 = pf.createParameterHandler(Customer.class, Customer.class, null, new MessageImpl());
    assertSame(h2, hp);
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) ConstrainedTo(javax.ws.rs.ConstrainedTo) ProviderFactory(org.apache.cxf.jaxrs.provider.ProviderFactory) ParamConverterProvider(javax.ws.rs.ext.ParamConverterProvider) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 14 with ExtensionManagerBus

use of org.apache.cxf.bus.extension.ExtensionManagerBus in project cxf by apache.

the class ClientProviderFactoryTest method testParameterHandlerProviderWithPriority.

@Test
public void testParameterHandlerProviderWithPriority() throws Exception {
    final Bus bus = new ExtensionManagerBus();
    final ProviderFactory pf = ClientProviderFactory.createInstance(bus);
    ParamConverterProvider h = new CustomerParameterHandler();
    ParamConverterProvider hp = new PriorityCustomerParameterHandler();
    pf.registerUserProvider(h);
    pf.registerUserProvider(hp);
    ParamConverter<Customer> h2 = pf.createParameterHandler(Customer.class, Customer.class, null, new MessageImpl());
    assertSame(h2, hp);
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) ProviderFactory(org.apache.cxf.jaxrs.provider.ProviderFactory) ParamConverterProvider(javax.ws.rs.ext.ParamConverterProvider) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 15 with ExtensionManagerBus

use of org.apache.cxf.bus.extension.ExtensionManagerBus in project cxf by apache.

the class RestClientCdiTest method testCreationalContextsReleasedOnClientClose.

@Test
@SuppressWarnings({ "unchecked", "rawTypes" })
public void testCreationalContextsReleasedOnClientClose() throws Exception {
    IMocksControl control = EasyMock.createStrictControl();
    BeanManager mockedBeanMgr = control.createMock(BeanManager.class);
    CreationalContext<?> mockedCreationalCtx = control.createMock(CreationalContext.class);
    Bean<?> mockedBean = control.createMock(Bean.class);
    List<String> stringList = new ArrayList<>(Collections.singleton("abc"));
    EasyMock.expect(mockedBeanMgr.getBeans(List.class)).andReturn(Collections.singleton(mockedBean));
    EasyMock.expect(mockedBeanMgr.createCreationalContext(mockedBean)).andReturn((CreationalContext) mockedCreationalCtx);
    EasyMock.expect(mockedBeanMgr.getReference(mockedBean, List.class, mockedCreationalCtx)).andReturn(stringList);
    EasyMock.expect(mockedBean.getScope()).andReturn((Class) ApplicationScoped.class);
    EasyMock.expect(mockedBeanMgr.isNormalScope(ApplicationScoped.class)).andReturn(false);
    mockedCreationalCtx.release();
    EasyMock.expectLastCall().once();
    control.replay();
    Bus bus = new ExtensionManagerBus();
    bus.setExtension(mockedBeanMgr, BeanManager.class);
    Instance<List> i = CDIUtils.getInstanceFromCDI(List.class, bus);
    assertEquals(stringList, i.getValue());
    i.release();
    control.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ApplicationScoped(javax.enterprise.context.ApplicationScoped) BeanManager(javax.enterprise.inject.spi.BeanManager) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Test(org.junit.Test)

Aggregations

ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)59 Bus (org.apache.cxf.Bus)48 Test (org.junit.Test)44 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)28 Message (org.apache.cxf.message.Message)14 HTTPTransportFactory (org.apache.cxf.transport.http.HTTPTransportFactory)14 QName (javax.xml.namespace.QName)8 DestinationRegistry (org.apache.cxf.transport.http.DestinationRegistry)8 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)7 ArrayList (java.util.ArrayList)6 AtmosphereInterceptor (org.atmosphere.cpr.AtmosphereInterceptor)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 URL (java.net.URL)4 List (java.util.List)4 ASMHelperImpl (org.apache.cxf.common.util.ASMHelperImpl)4 MessageObserver (org.apache.cxf.transport.MessageObserver)4 HTTPServerPolicy (org.apache.cxf.transports.http.configuration.HTTPServerPolicy)4 HttpURLConnection (java.net.HttpURLConnection)3 Hashtable (java.util.Hashtable)3