org.apache.cxf.transport.http.DestinationRegistry Java Examples

The following examples show how to use org.apache.cxf.transport.http.DestinationRegistry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AtmosphereWebSocketJettyDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseCustomAtmoosphereInterceptor() throws Exception {
    Bus bus = new ExtensionManagerBus();
    bus.setProperty("atmosphere.interceptors", new CustomInterceptor1());
    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++;
            break;
        }
    }
    assertEquals(1, added);
}
 
Example #2
Source File: AtmosphereWebSocketJettyDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseCXFDefaultAtmoosphereInterceptor() throws Exception {
    Bus bus = new ExtensionManagerBus();
    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 (DefaultProtocolInterceptor.class.equals(a.getClass())) {
            added++;
            break;
        }
    }
    assertEquals(1, added);
}
 
Example #3
Source File: AtmosphereWebSocketJettyDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: AtmosphereWebSocketServletDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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);

    TestAtmosphereWebSocketServletDestination dest =
        new TestAtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);

    dest.activate();

    assertNotNull(registry.getDestinationForPath(ENDPOINT_ADDRESS));

    dest.deactivate();

    assertNull(registry.getDestinationForPath(ENDPOINT_ADDRESS));
}
 
Example #5
Source File: AtmosphereWebSocketServletDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseCXFDefaultAtmoosphereInterceptor() throws Exception {
    Bus bus = new ExtensionManagerBus();
    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 (DefaultProtocolInterceptor.class.equals(a.getClass())) {
            added++;
            break;
        }
    }
    assertEquals(1, added);
}
 
Example #6
Source File: AtmosphereWebSocketServletDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseCustomAtmoosphereInterceptor() throws Exception {
    Bus bus = new ExtensionManagerBus();
    bus.setProperty("atmosphere.interceptors", new CustomInterceptor1());
    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++;
            break;
        }
    }
    assertEquals(1, added);
}
 
Example #7
Source File: AtmosphereWebSocketServletDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #8
Source File: AtmosphereWebSocketUndertowDestination.java    From cxf with Apache License 2.0 6 votes vote down vote up
public AtmosphereWebSocketUndertowDestination(Bus bus, DestinationRegistry registry, EndpointInfo ei,
                                              UndertowHTTPServerEngineFactory serverEngineFactory)
                                                  throws IOException {
    super(bus, registry, ei, serverEngineFactory);
    framework = new AtmosphereFramework(false, true);
    framework.setUseNativeImplementation(false);
    framework.addInitParameter(ApplicationConfig.PROPERTY_NATIVE_COMETSUPPORT, "true");
    framework.addInitParameter(ApplicationConfig.PROPERTY_SESSION_SUPPORT, "true");
    framework.addInitParameter(ApplicationConfig.WEBSOCKET_SUPPORT, "true");
    framework.addInitParameter(ApplicationConfig.WEBSOCKET_PROTOCOL_EXECUTION, "true");
    // workaround for atmosphere's jsr356 initialization requiring servletConfig
    framework.addInitParameter(ApplicationConfig.WEBSOCKET_SUPPRESS_JSR356, "true");
    AtmosphereUtils.addInterceptors(framework, bus);
    framework.addAtmosphereHandler("/", new DestinationHandler());
    framework.init();
    executor = bus.getExtension(WorkQueueManager.class).getAutomaticWorkQueue();
}
 
Example #9
Source File: AtmosphereWebSocketJettyDestination.java    From cxf with Apache License 2.0 6 votes vote down vote up
public AtmosphereWebSocketJettyDestination(Bus bus, DestinationRegistry registry, EndpointInfo ei,
                                 JettyHTTPServerEngineFactory serverEngineFactory)
    throws IOException {
    super(bus, registry, ei, 
          serverEngineFactory == null ? null : new URL(getNonWSAddress(ei)),
          serverEngineFactory);

    framework = new AtmosphereFramework(false, true);
    framework.setUseNativeImplementation(false);
    addInitParameter(framework, initParams, ApplicationConfig.PROPERTY_NATIVE_COMETSUPPORT, "true");
    addInitParameter(framework, initParams, ApplicationConfig.PROPERTY_SESSION_SUPPORT, "true");
    addInitParameter(framework, initParams, ApplicationConfig.WEBSOCKET_SUPPORT, "true");
    addInitParameter(framework, initParams, ApplicationConfig.WEBSOCKET_PROTOCOL_EXECUTION, "true");
    // workaround for atmosphere's jsr356 initialization requiring servletConfig
    addInitParameter(framework, initParams, ApplicationConfig.WEBSOCKET_SUPPRESS_JSR356, "true");
    AtmosphereUtils.addInterceptors(framework, bus);
    framework.addAtmosphereHandler("/", new DestinationHandler());        
}
 
Example #10
Source File: JettyWebSocketDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #11
Source File: ServletController.java    From cxf with Apache License 2.0 5 votes vote down vote up
public ServletController(DestinationRegistry destinationRegistry,
                            ServletConfig config,
                            HttpServlet serviceListGenerator) {
    this.servletConfig = config;
    this.destinationRegistry = destinationRegistry;
    this.serviceListGenerator = serviceListGenerator;
    init();
}
 
Example #12
Source File: WebSocketDestinationFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static DestinationRegistry getDestinationRegistry(Bus bus) {
    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    try {
        DestinationFactory df = dfm
            .getDestinationFactory("http://cxf.apache.org/transports/http/configuration");
        if (df instanceof HTTPTransportFactory) {
            HTTPTransportFactory transportFactory = (HTTPTransportFactory)df;
            return transportFactory.getRegistry();
        }
    } catch (Exception e) {
        // why are we throwing a busexception if the DF isn't found?
    }
    return null;
}
 
Example #13
Source File: CxfCdiAutoSetup.java    From openwebbeans-meecrowave with Apache License 2.0 5 votes vote down vote up
@Override
public void init(final ServletConfig sc) throws ServletException {
    super.init(sc);

    // just logging the endpoints
    final LogFacade log = new LogFacade(CxfCdiAutoSetup.class.getName());
    final String transportId = sc.getInitParameter(TRANSPORT_ID);
    final DestinationRegistry registry = getDestinationRegistryFromBusOrDefault(transportId);
    prefixes = registry.getDestinations().stream()
            .filter(ServletDestination.class::isInstance)
            .map(ServletDestination.class::cast)
            .map(getServletDestinationPath(sc, log))
            .filter(Objects::nonNull)
            .toArray(String[]::new);
}
 
Example #14
Source File: WebSocketDestinationFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static Constructor<?> probeConstructor(String name) {
    try {
        Class<?> clz = Class.forName(name, true, WebSocketDestinationFactory.class.getClassLoader());
        return clz.getConstructor(Bus.class, DestinationRegistry.class, EndpointInfo.class,
                                  JettyHTTPServerEngineFactory.class);
    } catch (Throwable t) {
        return null;
    }
}
 
Example #15
Source File: WebSocketDestinationFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static Constructor<?> probeUndertowConstructor(String name) {
    try {
        Class<?> clz = Class.forName(name, true, WebSocketDestinationFactory.class.getClassLoader());
        return clz.getConstructor(Bus.class, DestinationRegistry.class, EndpointInfo.class,
                                  UndertowHTTPServerEngineFactory.class);
    } catch (Throwable t) {
        return null;
    }
}
 
Example #16
Source File: ServiceListGeneratorServlet.java    From cxf with Apache License 2.0 5 votes vote down vote up
public ServiceListGeneratorServlet(DestinationRegistry destinationRegistry, Bus bus) {
    this.destinationRegistry = destinationRegistry;
    this.bus = bus;
    if (this.bus == null) {
        this.bus = BusFactory.getDefaultBus(false);
    }

    this.title = "CXF - Service list";
}
 
Example #17
Source File: ServletDestination.java    From cxf with Apache License 2.0 5 votes vote down vote up
public ServletDestination(Bus b,
                          DestinationRegistry registry,
                          EndpointInfo ei,
                          String path,
                          boolean dp)
    throws IOException {
    // would add the default port to the address
    super(b, registry, ei, path, dp);
}
 
Example #18
Source File: CxfExtractor.java    From component-runtime with Apache License 2.0 5 votes vote down vote up
public DestinationRegistry getRegistry() {
    try {
        final HTTPTransportFactory transportFactory = HTTPTransportFactory.class
                .cast(bus
                        .getExtension(DestinationFactoryManager.class)
                        .getDestinationFactory("http://cxf.apache.org/transports/http" + "/configuration"));
        return transportFactory.getRegistry();
    } catch (final BusException e) {
        throw new IllegalStateException(e);
    }
}
 
Example #19
Source File: CXFNonSpringServlet.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected DestinationRegistry getDestinationRegistryFromBusOrDefault(final String transportId) {
    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    try {
        String peferredTransportId = transportId;

        // Check if the preferred transport is set on a bus level (f.e., from any
        // 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();

            // If the default transport is present, fall back to it and don't even
            // 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;
}
 
Example #20
Source File: HTTPTransportActivator.java    From cxf with Apache License 2.0 5 votes vote down vote up
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))) {
            //TODO: Review if it also makes sense to support "http.transport.disable"
            //      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");
    }
 
Example #21
Source File: ServletControllerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    req = EasyMock.createMock(HttpServletRequest.class);
    res = EasyMock.createMock(HttpServletResponse.class);
    registry = EasyMock.createMock(DestinationRegistry.class);
    serviceListGenerator = EasyMock.createMock(HttpServlet.class);
}
 
Example #22
Source File: JettyHTTPDestination.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @param bus  the associated Bus
 * @param registry the associated destinationRegistry
 * @param ei the endpoint info of the destination
 * @param serverEngineFactory the serverEngineFactory which could be used to create ServerEngine
 * @throws java.io.IOException
 */
public JettyHTTPDestination(
        Bus bus,
        DestinationRegistry registry,
        EndpointInfo ei,
        JettyHTTPServerEngineFactory serverEngineFactory
) throws IOException {
    this(bus, registry, ei, 
         serverEngineFactory == null ? null : new URL(getAddressValue(ei, true).getAddress()),
         serverEngineFactory);
}
 
Example #23
Source File: JettyHTTPDestination.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected JettyHTTPDestination(Bus bus,
                               DestinationRegistry registry,
                               EndpointInfo ei,
                               URL nurl,
                               JettyHTTPServerEngineFactory serverEngineFactory)
    throws IOException {
    //Add the default port if the address is missing it
    super(bus, registry, ei, getAddressValue(ei, true).getAddress(), true);
    this.serverEngineFactory = serverEngineFactory;
    this.nurl = nurl;
    loader = bus.getExtension(ClassLoader.class);
}
 
Example #24
Source File: JettyHTTPDestinationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
EasyMockJettyHTTPDestination(Bus bus,
                                    DestinationRegistry registry,
                                    EndpointInfo endpointInfo,
                                    JettyHTTPServerEngineFactory serverEngineFactory,
                                    JettyHTTPServerEngine easyMockEngine) throws IOException {
    super(bus, registry, endpointInfo, serverEngineFactory);
    engine = easyMockEngine;
}
 
Example #25
Source File: UndertowHTTPDestination.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @param bus  the associated Bus
 * @param registry the associated destinationRegistry
 * @param ei the endpoint info of the destination
 * @param serverEngineFactory the serverEngineFactory which could be used to create ServerEngine
 * @throws java.io.IOException
 */
public UndertowHTTPDestination(Bus bus,
                               DestinationRegistry registry,
                               EndpointInfo ei,
                               UndertowHTTPServerEngineFactory serverEngineFactory)
    throws IOException {
    //Add the default port if the address is missing it
    super(bus, registry, ei, getAddressValue(ei, true).getAddress(), true);
    this.serverEngineFactory = serverEngineFactory;
    loader = bus.getExtension(ClassLoader.class);
}
 
Example #26
Source File: UndertowHTTPDestinationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
EasyMockUndertowHTTPDestination(Bus bus,
                                    DestinationRegistry registry,
                                    EndpointInfo endpointInfo,
                                    UndertowHTTPServerEngineFactory serverEngineFactory,
                                    UndertowHTTPServerEngine easyMockEngine) throws IOException {
    super(bus, registry, endpointInfo, serverEngineFactory);
    engine = easyMockEngine;
}
 
Example #27
Source File: NettyHttpTransportFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
public NettyHttpTransportFactory(DestinationRegistry registry) {
    super(DEFAULT_NAMESPACES);
    if (registry == null) {
        registry = new DestinationRegistryImpl();
    }
    this.registry = registry;
}
 
Example #28
Source File: NettyHttpDestinationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
EasyMockJettyHTTPDestination(Bus bus,
                             DestinationRegistry registry,
                             EndpointInfo endpointInfo,
                             NettyHttpServerEngineFactory serverEngineFactory,
                             NettyHttpServerEngine easyMockEngine) throws IOException {
    super(bus, registry, endpointInfo, serverEngineFactory);
    engine = easyMockEngine;
}
 
Example #29
Source File: GenericWebServiceServlet.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private static DestinationRegistry getDestinationRegistryFromBus(Bus bus) {
	DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
	try {
		DestinationFactory df = dfm.getDestinationFactory("http://cxf.apache.org/transports/http/configuration");
		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;
}
 
Example #30
Source File: UndertowHTTPDestination.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @param bus the associated Bus
 * @param registry the associated destinationRegistry
 * @param ei the endpoint info of the destination
 * @throws java.io.IOException
 */
public UndertowHTTPDestination(Bus bus, DestinationRegistry registry, EndpointInfo ei) throws IOException {
    //Add the default port if the address is missing it
    super(bus, registry, ei, getAddressValue(ei, true).getAddress(), true);
    this.serverEngineFactory = bus.getExtension(HttpServerEngineFactory.class);
    if (serverEngineFactory != null) {
        nurl = new URL(getAddress(endpointInfo));
    }
    loader = bus.getExtension(ClassLoader.class);
}