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

The following examples show how to use org.apache.cxf.transport.http.HTTPTransportFactory. 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: 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 #2
Source File: JettyHTTPDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testServerPolicyInServiceModel()
    throws Exception {
    policy = new HTTPServerPolicy();
    address = getEPR("bar/foo");
    bus = BusFactory.getDefaultBus(true);

    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(JettyHTTPServerEngine.class);
    EasyMock.replay();
    endpointInfo.setAddress(NOWHERE + "bar/foo");

    JettyHTTPDestination dest =
        new EasyMockJettyHTTPDestination(
                bus, transportFactory.getRegistry(), endpointInfo, null, engine);
    assertEquals(policy, dest.getServer());
}
 
Example #3
Source File: JettyHTTPDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: JettyHTTPServerEngineFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * This test makes sure that a default Spring initialized bus will
 * have the JettyHTTPServerEngineFactory (absent of <httpj:engine-factory>
 * configuration.
 */
@Test
public void testMakeSureTransportFactoryHasEngineFactory() throws Exception {
    bus = BusFactory.getDefaultBus(true);

    assertNotNull("Cannot get bus", bus);

    // Make sure we got the Transport Factory.
    DestinationFactoryManager destFM =
        bus.getExtension(DestinationFactoryManager.class);
    assertNotNull("Cannot get DestinationFactoryManager", destFM);
    DestinationFactory destF =
        destFM.getDestinationFactory(
                "http://cxf.apache.org/transports/http");
    assertNotNull("No DestinationFactory", destF);
    assertTrue(HTTPTransportFactory.class.isInstance(destF));

    // And the JettyHTTPServerEngineFactory should be there.
    JettyHTTPServerEngineFactory factory =
        bus.getExtension(JettyHTTPServerEngineFactory.class);
    assertNotNull("EngineFactory is not configured.", factory);
}
 
Example #5
Source File: UndertowHTTPDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #6
Source File: UndertowHTTPDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testServerPolicyInServiceModel()
    throws Exception {
    policy = new HTTPServerPolicy();
    address = getEPR("bar/foo");
    bus = BusFactory.getDefaultBus(true);

    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(UndertowHTTPServerEngine.class);
    EasyMock.replay();
    endpointInfo.setAddress(NOWHERE + "bar/foo");

    UndertowHTTPDestination dest =
        new EasyMockUndertowHTTPDestination(
                bus, transportFactory.getRegistry(), endpointInfo, null, engine);
    assertEquals(policy, dest.getServer());
}
 
Example #7
Source File: UndertowHTTPServerEngineFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * This test makes sure that a default Spring initialized bus will
 * have the UndertowHTTPServerEngineFactory (absent of <httpu:engine-factory>
 * configuration.
 */
@Test
public void testMakeSureTransportFactoryHasEngineFactory() throws Exception {
    bus = BusFactory.getDefaultBus(true);

    assertNotNull("Cannot get bus", bus);

    // Make sure we got the Transport Factory.
    DestinationFactoryManager destFM =
        bus.getExtension(DestinationFactoryManager.class);
    assertNotNull("Cannot get DestinationFactoryManager", destFM);
    DestinationFactory destF =
        destFM.getDestinationFactory(
                "http://cxf.apache.org/transports/http");
    assertNotNull("No DestinationFactory", destF);
    assertTrue(HTTPTransportFactory.class.isInstance(destF));

    // And the UndertowHTTPServerEngineFactory should be there.
    UndertowHTTPServerEngineFactory factory =
        bus.getExtension(UndertowHTTPServerEngineFactory.class);
    assertNotNull("EngineFactory is not configured.", factory);
}
 
Example #8
Source File: NettyHttpServerEngineFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testTransportFactoryHasEngineFactory() throws Exception {
    bus = BusFactory.getDefaultBus(true);

    assertNotNull("Cannot get bus", bus);

    // Make sure we got the Transport Factory.
    DestinationFactoryManager destFM =
        bus.getExtension(DestinationFactoryManager.class);
    assertNotNull("Cannot get DestinationFactoryManager", destFM);
    DestinationFactory destF =
        destFM.getDestinationFactory(
                "http://cxf.apache.org/transports/http");
    assertNotNull("No DestinationFactory", destF);
    assertTrue(HTTPTransportFactory.class.isInstance(destF));


    NettyHttpServerEngineFactory factory =
        bus.getExtension(NettyHttpServerEngineFactory.class);
    assertNotNull("EngineFactory is not configured.", factory);
}
 
Example #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
Source File: NettyHttpDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetMultiple() throws Exception {
    transportFactory = new HTTPTransportFactory();
    bus = BusFactory.getDefaultBus();

    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);
}
 
Example #17
Source File: NettyHttpDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #18
Source File: NettyHttpConduitFactory.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public HTTPConduit createConduit(HTTPTransportFactory f,
                                 Bus bus,
                                 EndpointInfo localInfo,
                                 EndpointReferenceType target)
    throws IOException {
    // need to check if the EventLoopGroup is created or not
    // if not create a new EventLoopGroup for it
    EventLoopGroup eventLoopGroup = bus.getExtension(EventLoopGroup.class);
    if (eventLoopGroup == null) {
        final EventLoopGroup group = new NioEventLoopGroup();
        // register a BusLifeCycleListener for it
        bus.setExtension(group, EventLoopGroup.class);
        registerBusLifeListener(bus, group);
    }
    return new NettyHttpConduit(bus, localInfo, target, this);
}
 
Example #19
Source File: WebClientSubstitution.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@Substitute
static JAXRSClientFactoryBean getBean(String baseAddress, String configLocation) {
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    // configLocation is always null and no need to create SpringBusFactory.
    CXFBusFactory bf = new CXFBusFactory();

    // It can not load the extensions from the bus-extensions.txt dynamically.
    // So have to set all of necessary ones here.
    List<Extension> extensions = new ArrayList<>();
    Extension http = new Extension();
    http.setClassname(HTTPTransportFactory.class.getName());
    http.setDeferred(true);
    extensions.add(http);
    ExtensionRegistry.addExtensions(extensions);

    Bus bus = bf.createBus();
    bus.setExtension(new PhaseManagerImpl(), PhaseManager.class);
    bus.setExtension(new ClientLifeCycleManagerImpl(), ClientLifeCycleManager.class);
    bus.setExtension(new ConduitInitiatorManagerImpl(bus), ConduitInitiatorManager.class);

    bean.setBus(bus);
    bean.setAddress(baseAddress);
    return bean;
}
 
Example #20
Source File: HttpConduitConfigurationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testConduitBeanWithTLSReferences() throws Exception {
    SpringBusFactory factory = new SpringBusFactory();
    bus = factory.createBus("org/apache/cxf/transport/http/spring/conduit-tlsrefs-bean.xml");
    HTTPTransportFactory atf = new HTTPTransportFactory();
    HTTPConduit conduit = (HTTPConduit)atf.getConduit(ei, bus);

    verifyConduit(conduit);
}
 
Example #21
Source File: NettyHttpDestinationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testRandomPortAllocation() throws Exception {
    bus = BusFactory.getDefaultBus();
    transportFactory = new HTTPTransportFactory();
    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setName(new QName("bla", "Service"));
    EndpointInfo ei = new EndpointInfo(serviceInfo, "");
    ei.setName(new QName("bla", "Port"));

    Destination d1 = transportFactory.getDestination(ei, bus);
    URL url = new URL(d1.getAddress().getAddress().getValue());
    assertTrue("No random port has been allocated",
               url.getPort() > 0);

}
 
Example #22
Source File: NettyHttpDestinationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testContinuationsIgnored() throws Exception {

    HttpServletRequest httpRequest = EasyMock.createMock(HttpServletRequest.class);

    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setName(new QName("bla", "Service"));
    EndpointInfo ei = new EndpointInfo(serviceInfo, "");
    ei.setName(new QName("bla", "Port"));

    // Just create a fake engine
    final NettyHttpServerEngine httpEngine = new NettyHttpServerEngine("localhost", 8080);
    //httpEngine.setContinuationsEnabled(false);
    NettyHttpServerEngineFactory factory = new NettyHttpServerEngineFactory() {
        @Override
        public NettyHttpServerEngine retrieveNettyHttpServerEngine(int port) {
            return httpEngine;
        }
    };
    transportFactory = new HTTPTransportFactory();
    bus = BusFactory.getDefaultBus();
    bus.setExtension(factory, NettyHttpServerEngineFactory.class);

    TestJettyDestination testDestination =
        new TestJettyDestination(bus,
                                 transportFactory.getRegistry(),
                                 ei,
                                 factory);
    testDestination.finalizeConfig();
    Message mi = testDestination.retrieveFromContinuation(httpRequest);
    assertNull("Continuations must be ignored", mi);
}
 
Example #23
Source File: UndertowHTTPDestinationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testContinuationsIgnored() throws Exception {

    HttpServletRequest httpRequest = EasyMock.createMock(HttpServletRequest.class);

    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setName(new QName("bla", "Service"));
    EndpointInfo ei = new EndpointInfo(serviceInfo, "");
    ei.setName(new QName("bla", "Port"));

    final UndertowHTTPServerEngine httpEngine = new UndertowHTTPServerEngine();
    httpEngine.setContinuationsEnabled(false);
    UndertowHTTPServerEngineFactory factory = new UndertowHTTPServerEngineFactory() {
        @Override
        public UndertowHTTPServerEngine retrieveUndertowHTTPServerEngine(int port) {
            return httpEngine;
        }
    };
    Bus b2 = new ExtensionManagerBus();
    transportFactory = new HTTPTransportFactory();
    b2.setExtension(factory, UndertowHTTPServerEngineFactory.class);

    TestUndertowDestination testDestination =
        new TestUndertowDestination(b2,
                                 transportFactory.getRegistry(),
                                 ei,
                                 factory);
    testDestination.finalizeConfig();
    Message mi = testDestination.retrieveFromContinuation(httpRequest);
    assertNull("Continuations must be ignored", mi);
}
 
Example #24
Source File: UndertowHTTPDestinationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testRandomPortAllocation() 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"));

    Destination d1 = transportFactory.getDestination(ei, bus);
    URL url = new URL(d1.getAddress().getAddress().getValue());
    assertTrue("No random port has been allocated",
               url.getPort() > 0);

}
 
Example #25
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 #26
Source File: JettyHTTPDestinationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testContinuationsIgnored() throws Exception {

    HttpServletRequest httpRequest = EasyMock.createMock(HttpServletRequest.class);

    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setName(new QName("bla", "Service"));
    EndpointInfo ei = new EndpointInfo(serviceInfo, "");
    ei.setName(new QName("bla", "Port"));

    final JettyHTTPServerEngine httpEngine = new JettyHTTPServerEngine();
    httpEngine.setContinuationsEnabled(false);
    JettyHTTPServerEngineFactory factory = new JettyHTTPServerEngineFactory() {
        @Override
        public JettyHTTPServerEngine retrieveJettyHTTPServerEngine(int port) {
            return httpEngine;
        }
    };
    Bus b2 = new ExtensionManagerBus();
    transportFactory = new HTTPTransportFactory();
    b2.setExtension(factory, JettyHTTPServerEngineFactory.class);

    TestJettyDestination testDestination =
        new TestJettyDestination(b2,
                                 transportFactory.getRegistry(),
                                 ei,
                                 factory);
    testDestination.finalizeConfig();
    Message mi = testDestination.retrieveFromContinuation(httpRequest);
    assertNull("Continuations must be ignored", mi);
}
 
Example #27
Source File: JettyHTTPDestinationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testRandomPortAllocation() 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"));

    Destination d1 = transportFactory.getDestination(ei, bus);
    URL url = new URL(d1.getAddress().getAddress().getValue());
    assertTrue("No random port has been allocated",
               url.getPort() > 0);

}
 
Example #28
Source File: HttpConduitConfigurationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testConduitBean() throws Exception {
    SpringBusFactory factory = new SpringBusFactory();
    bus = factory.createBus("org/apache/cxf/transport/http/spring/conduit-bean.xml");
    HTTPTransportFactory atf = new HTTPTransportFactory();
    HTTPConduit conduit = (HTTPConduit)atf.getConduit(ei, bus);

    verifyConduit(conduit);
}
 
Example #29
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 #30
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;
}