Search in sources :

Example 6 with DestinationRegistry

use of org.apache.cxf.transport.http.DestinationRegistry 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 7 with DestinationRegistry

use of org.apache.cxf.transport.http.DestinationRegistry 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)

Example 8 with DestinationRegistry

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

the class AtmosphereWebSocketServletDestinationTest 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)

Example 9 with DestinationRegistry

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

the class JettyWebSocketDestinationTest method testRegisteration.

@Test
public void testRegisteration() throws Exception {
    Bus bus = new ExtensionManagerBus();
    DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(ENDPOINT_ADDRESS);
    endpoint.setName(ENDPOINT_NAME);
    JettyHTTPServerEngine engine = EasyMock.createMock(JettyHTTPServerEngine.class);
    control.replay();
    TestJettyWebSocketDestination dest = new TestJettyWebSocketDestination(bus, registry, endpoint, null, engine);
    dest.activate();
    assertNotNull(registry.getDestinationForPath(ENDPOINT_ADDRESS));
    dest.deactivate();
    assertNull(registry.getDestinationForPath(ENDPOINT_ADDRESS));
}
Also used : 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) JettyHTTPServerEngine(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Test(org.junit.Test)

Example 10 with DestinationRegistry

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

the class CXFNonSpringServlet method getDestinationRegistryFromBusOrDefault.

protected DestinationRegistry getDestinationRegistryFromBusOrDefault(final String transportId) {
    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    try {
        String peferredTransportId = transportId;
        // extension or customization).
        if (StringUtils.isEmpty(peferredTransportId) && getBus() != null) {
            peferredTransportId = (String) getBus().getProperty(AbstractTransportFactory.PREFERRED_TRANSPORT_ID);
        }
        if (StringUtils.isEmpty(peferredTransportId)) {
            final Set<String> candidates = dfm.getRegisteredDestinationFactoryNames();
            // consider other candidates
            if (!candidates.contains(DEFAULT_TRANSPORT_ID)) {
                peferredTransportId = candidates.stream().filter(name -> name.endsWith("/configuration")).findAny().orElse(DEFAULT_TRANSPORT_ID);
            }
        }
        DestinationFactory df = StringUtils.isEmpty(peferredTransportId) ? dfm.getDestinationFactory(DEFAULT_TRANSPORT_ID) : dfm.getDestinationFactory(peferredTransportId);
        if (df instanceof HTTPTransportFactory) {
            HTTPTransportFactory transportFactory = (HTTPTransportFactory) df;
            return transportFactory.getRegistry();
        }
    } catch (BusException e) {
    // why are we throwing a busexception if the DF isn't found?
    }
    return null;
}
Also used : Bus(org.apache.cxf.Bus) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) FilterChain(javax.servlet.FilterChain) ServletException(javax.servlet.ServletException) StringUtils(org.apache.cxf.common.util.StringUtils) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination) ResourceManager(org.apache.cxf.resource.ResourceManager) HttpServletRequest(javax.servlet.http.HttpServletRequest) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) Method(java.lang.reflect.Method) ServletRequest(javax.servlet.ServletRequest) ServiceListGeneratorServlet(org.apache.cxf.transport.servlet.servicelist.ServiceListGeneratorServlet) ServletConfig(javax.servlet.ServletConfig) HttpServlet(javax.servlet.http.HttpServlet) CastUtils(org.apache.cxf.helpers.CastUtils) DestinationFactory(org.apache.cxf.transport.DestinationFactory) Collection(java.util.Collection) BusException(org.apache.cxf.BusException) HttpServletResponse(javax.servlet.http.HttpServletResponse) Set(java.util.Set) IOException(java.io.IOException) AbstractTransportFactory(org.apache.cxf.transport.AbstractTransportFactory) ClassLoaderUtils(org.apache.cxf.common.classloader.ClassLoaderUtils) ServletResponse(javax.servlet.ServletResponse) BusFactory(org.apache.cxf.BusFactory) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) ServletContext(javax.servlet.ServletContext) DestinationRegistry(org.apache.cxf.transport.http.DestinationRegistry) DestinationFactory(org.apache.cxf.transport.DestinationFactory) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) BusException(org.apache.cxf.BusException)

Aggregations

DestinationRegistry (org.apache.cxf.transport.http.DestinationRegistry)10 HTTPTransportFactory (org.apache.cxf.transport.http.HTTPTransportFactory)10 Bus (org.apache.cxf.Bus)9 ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)8 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)8 Test (org.junit.Test)8 AtmosphereInterceptor (org.atmosphere.cpr.AtmosphereInterceptor)6 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 Set (java.util.Set)1 FilterChain (javax.servlet.FilterChain)1 ServletConfig (javax.servlet.ServletConfig)1 ServletContext (javax.servlet.ServletContext)1 ServletException (javax.servlet.ServletException)1 ServletRequest (javax.servlet.ServletRequest)1 ServletResponse (javax.servlet.ServletResponse)1 HttpServlet (javax.servlet.http.HttpServlet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletRequestWrapper (javax.servlet.http.HttpServletRequestWrapper)1