Search in sources :

Example 11 with HTTPTransportFactory

use of org.apache.cxf.transport.http.HTTPTransportFactory in project cxf by apache.

the class NettyHttpDestinationTest method testServerPolicyInServiceModel.

@Test
public void testServerPolicyInServiceModel() throws Exception {
    policy = new HTTPServerPolicy();
    address = getEPR("bar/foo");
    bus = new ExtensionManagerBus();
    transportFactory = new HTTPTransportFactory();
    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setName(new QName("bla", "Service"));
    endpointInfo = new EndpointInfo(serviceInfo, "");
    endpointInfo.setName(new QName("bla", "Port"));
    endpointInfo.addExtensor(policy);
    engine = EasyMock.createMock(NettyHttpServerEngine.class);
    EasyMock.replay();
    endpointInfo.setAddress(NOWHERE + "bar/foo");
    NettyHttpDestination dest = new EasyMockJettyHTTPDestination(bus, transportFactory.getRegistry(), endpointInfo, null, engine);
    assertEquals(policy, dest.getServer());
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) QName(javax.xml.namespace.QName) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Test(org.junit.Test)

Example 12 with HTTPTransportFactory

use of org.apache.cxf.transport.http.HTTPTransportFactory in project cxf by apache.

the class HTTPTransportActivator method start.

public void start(final BundleContext context) throws Exception {
    ConfigAdminHttpConduitConfigurer conduitConfigurer = new ConfigAdminHttpConduitConfigurer();
    registerService(context, ManagedServiceFactory.class, conduitConfigurer, ConfigAdminHttpConduitConfigurer.FACTORY_PID);
    registerService(context, HTTPConduitConfigurer.class, conduitConfigurer, "org.apache.cxf.http.conduit-configurer");
    if (PropertyUtils.isTrue(context.getProperty(DISABLE_DEFAULT_HTTP_TRANSPORT))) {
        // directly in the CXF_CONFIG_SCOPE properties file
        return;
    }
    DestinationRegistry destinationRegistry = new DestinationRegistryImpl();
    HTTPTransportFactory transportFactory = new HTTPTransportFactory(destinationRegistry);
    HttpServiceTrackerCust customizer = new HttpServiceTrackerCust(destinationRegistry, context);
    httpServiceTracker = new ServiceTracker<>(context, HttpService.class, customizer);
    httpServiceTracker.open();
    context.registerService(DestinationRegistry.class.getName(), destinationRegistry, null);
    context.registerService(HTTPTransportFactory.class.getName(), transportFactory, null);
    BlueprintNameSpaceHandlerFactory factory = new BlueprintNameSpaceHandlerFactory() {

        @Override
        public Object createNamespaceHandler() {
            return new HttpBPHandler();
        }
    };
    NamespaceHandlerRegisterer.register(context, factory, "http://cxf.apache.org/transports/http/configuration");
}
Also used : DestinationRegistry(org.apache.cxf.transport.http.DestinationRegistry) BlueprintNameSpaceHandlerFactory(org.apache.cxf.bus.blueprint.BlueprintNameSpaceHandlerFactory) HttpBPHandler(org.apache.cxf.transport.http.blueprint.HttpBPHandler) HttpService(org.osgi.service.http.HttpService) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) DestinationRegistryImpl(org.apache.cxf.transport.http.DestinationRegistryImpl)

Example 13 with HTTPTransportFactory

use of org.apache.cxf.transport.http.HTTPTransportFactory in project cxf by apache.

the class UndertowHTTPDestinationTest method setUpDestination.

private UndertowHTTPDestination 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(UndertowHTTPServerEngine.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(UndertowHTTPHandler.class));
    EasyMock.expectLastCall();
    engine.getContinuationsEnabled();
    EasyMock.expectLastCall().andReturn(true);
    EasyMock.replay(engine);
    UndertowHTTPDestination dest = new EasyMockUndertowHTTPDestination(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) HttpString(io.undertow.util.HttpString) 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 14 with HTTPTransportFactory

use of org.apache.cxf.transport.http.HTTPTransportFactory in project cxf by apache.

the class UndertowHTTPDestinationTest method testGetMultiple.

@Test
public void testGetMultiple() throws Exception {
    bus = BusFactory.getDefaultBus(true);
    transportFactory = new HTTPTransportFactory();
    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setName(new QName("bla", "Service"));
    EndpointInfo ei = new EndpointInfo(serviceInfo, "");
    ei.setName(new QName("bla", "Port"));
    ei.setAddress("http://foo");
    Destination d1 = transportFactory.getDestination(ei, bus);
    Destination d2 = transportFactory.getDestination(ei, bus);
    // Second get should not generate a new destination. It should just retrieve the existing one
    assertEquals(d1, d2);
    d2.shutdown();
    Destination d3 = transportFactory.getDestination(ei, bus);
    // Now a new destination should have been created
    assertNotSame(d1, d3);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Destination(org.apache.cxf.transport.Destination) AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination) QName(javax.xml.namespace.QName) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) Test(org.junit.Test)

Example 15 with HTTPTransportFactory

use of org.apache.cxf.transport.http.HTTPTransportFactory in project cxf by apache.

the class AtmosphereWebSocketJettyDestinationTest method testUseCustomAtmoosphereInterceptors.

@Test
public void testUseCustomAtmoosphereInterceptors() throws Exception {
    Bus bus = new ExtensionManagerBus();
    bus.setProperty("atmosphere.interceptors", Arrays.asList(new CustomInterceptor1(), new CustomInterceptor2()));
    DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(ENDPOINT_ADDRESS);
    endpoint.setName(ENDPOINT_NAME);
    AtmosphereWebSocketServletDestination dest = new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);
    List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
    int added = 0;
    for (AtmosphereInterceptor a : ais) {
        if (CustomInterceptor1.class.equals(a.getClass())) {
            added++;
        } else if (CustomInterceptor2.class.equals(a.getClass())) {
            added++;
            break;
        }
    }
    assertEquals(2, added);
}
Also used : AtmosphereInterceptor(org.atmosphere.cpr.AtmosphereInterceptor) Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) DestinationRegistry(org.apache.cxf.transport.http.DestinationRegistry) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Test(org.junit.Test)

Aggregations

HTTPTransportFactory (org.apache.cxf.transport.http.HTTPTransportFactory)28 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)23 Test (org.junit.Test)22 QName (javax.xml.namespace.QName)15 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)15 Bus (org.apache.cxf.Bus)14 ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)14 DestinationRegistry (org.apache.cxf.transport.http.DestinationRegistry)10 AbstractHTTPDestination (org.apache.cxf.transport.http.AbstractHTTPDestination)7 URL (java.net.URL)6 Message (org.apache.cxf.message.Message)6 Destination (org.apache.cxf.transport.Destination)6 AtmosphereInterceptor (org.atmosphere.cpr.AtmosphereInterceptor)6 HTTPServerPolicy (org.apache.cxf.transports.http.configuration.HTTPServerPolicy)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HashSet (java.util.HashSet)3 ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)3 ConduitInitiatorManager (org.apache.cxf.transport.ConduitInitiatorManager)3 MessageObserver (org.apache.cxf.transport.MessageObserver)3 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)3