Search in sources :

Example 1 with JettyHTTPDestination

use of org.apache.cxf.transport.http_jetty.JettyHTTPDestination in project cxf by apache.

the class EngineLifecycleTest method testUpDownWithServlets.

@Test
public void testUpDownWithServlets() throws Exception {
    setUpBus(true);
    Bus bus = (Bus) applicationContext.getBean("cxf");
    ServerRegistry sr = bus.getExtension(ServerRegistry.class);
    ServerImpl si = (ServerImpl) sr.getServers().get(0);
    JettyHTTPDestination jhd = (JettyHTTPDestination) si.getDestination();
    JettyHTTPServerEngine e = (JettyHTTPServerEngine) jhd.getEngine();
    org.eclipse.jetty.server.Server jettyServer = e.getServer();
    Handler[] contexts = jettyServer.getChildHandlersByClass(WebAppContext.class);
    WebAppContext servletContext = null;
    for (Handler h : contexts) {
        WebAppContext wac = (WebAppContext) h;
        if (wac.getContextPath().equals("/jsunit")) {
            servletContext = wac;
            break;
        }
    }
    servletContext.addServlet("org.eclipse.jetty.servlet.DefaultServlet", "/bloop");
    getTestHtml();
    invokeService();
    shutdownService();
    verifyNoServer(PORT2);
    verifyNoServer(PORT1);
}
Also used : Bus(org.apache.cxf.Bus) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ServerImpl(org.apache.cxf.endpoint.ServerImpl) JettyHTTPServerEngine(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine) ServerRegistry(org.apache.cxf.endpoint.ServerRegistry) Handler(org.eclipse.jetty.server.Handler) JettyHTTPDestination(org.apache.cxf.transport.http_jetty.JettyHTTPDestination) Test(org.junit.Test)

Example 2 with JettyHTTPDestination

use of org.apache.cxf.transport.http_jetty.JettyHTTPDestination in project cxf by apache.

the class ApplicationContextTest method checkContext.

private void checkContext(TestApplicationContext ctx) throws Exception {
    ConfigurerImpl cfg = new ConfigurerImpl(ctx);
    EndpointInfo info = getEndpointInfo("bla", "Foo", "http://localhost:9000");
    Bus bus = (Bus) ctx.getBean(Bus.DEFAULT_BUS_ID);
    bus.setExtension(cfg, Configurer.class);
    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    DestinationFactory factory = dfm.getDestinationFactory("http://cxf.apache.org/transports/http");
    Destination d = factory.getDestination(info, bus);
    assertTrue(d instanceof JettyHTTPDestination);
    JettyHTTPDestination jd = (JettyHTTPDestination) d;
    assertEquals("foobar", jd.getServer().getContentEncoding());
    JettyHTTPServerEngine engine = (JettyHTTPServerEngine) jd.getEngine();
    assertEquals(111, engine.getThreadingParameters().getMinThreads());
    assertEquals(120, engine.getThreadingParameters().getMaxThreads());
    assertEquals("TestPrefix", engine.getThreadingParameters().getThreadNamePrefix());
    ConduitInitiatorManager cim = bus.getExtension(ConduitInitiatorManager.class);
    ConduitInitiator ci = cim.getConduitInitiator("http://cxf.apache.org/transports/http");
    HTTPConduit conduit = (HTTPConduit) ci.getConduit(info, bus);
    assertEquals(97, conduit.getClient().getConnectionTimeout());
    info.setName(new QName("urn:test:ns", "Bar"));
    conduit = (HTTPConduit) ci.getConduit(info, bus);
    assertEquals(79, conduit.getClient().getConnectionTimeout());
    JettyHTTPDestination jd2 = (JettyHTTPDestination) factory.getDestination(getEndpointInfo("foo", "bar", "http://localhost:9001"), bus);
    engine = (JettyHTTPServerEngine) jd2.getEngine();
    assertEquals(40000, engine.getMaxIdleTime());
    assertFalse(engine.getSendServerVersion());
    assertEquals(99, engine.getThreadingParameters().getMinThreads());
    assertEquals(777, engine.getThreadingParameters().getMaxThreads());
    assertEquals("AnotherPrefix", engine.getThreadingParameters().getThreadNamePrefix());
    assertTrue("The engine should support session manager", engine.isSessionSupport());
    assertNotNull("The handlers should not be null", engine.getHandlers());
    assertEquals(1, engine.getHandlers().size());
    JettyHTTPDestination jd3 = (JettyHTTPDestination) factory.getDestination(getEndpointInfo("sna", "foo", "https://localhost:9002"), bus);
    engine = (JettyHTTPServerEngine) jd3.getEngine();
    assertEquals(111, engine.getThreadingParameters().getMinThreads());
    assertEquals(120, engine.getThreadingParameters().getMaxThreads());
    assertEquals("TestPrefix", engine.getThreadingParameters().getThreadNamePrefix());
    assertEquals(engine.getTlsServerParameters().getClientAuthentication().isWant(), true);
    assertEquals(engine.getTlsServerParameters().getClientAuthentication().isRequired(), true);
    JettyHTTPDestination jd4 = (JettyHTTPDestination) factory.getDestination(getEndpointInfo("sna", "foo2", "https://localhost:9003"), bus);
    engine = (JettyHTTPServerEngine) jd4.getEngine();
    assertEquals(engine.getTlsServerParameters().getClientAuthentication().isWant(), false);
    assertEquals(engine.getTlsServerParameters().getClientAuthentication().isRequired(), false);
    JettyHTTPDestination jd5 = (JettyHTTPDestination) factory.getDestination(getEndpointInfo("sna", "foo", "http://localhost:9100"), bus);
    engine = (JettyHTTPServerEngine) jd5.getEngine();
    String r = "expected fallback thread parameters configured for port 0";
    assertNotNull(r, engine.getThreadingParameters());
    assertEquals(r, 21, engine.getThreadingParameters().getMinThreads());
    assertEquals(r, 389, engine.getThreadingParameters().getMaxThreads());
}
Also used : Bus(org.apache.cxf.Bus) DestinationFactory(org.apache.cxf.transport.DestinationFactory) Destination(org.apache.cxf.transport.Destination) JettyHTTPDestination(org.apache.cxf.transport.http_jetty.JettyHTTPDestination) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) ConfigurerImpl(org.apache.cxf.configuration.spring.ConfigurerImpl) QName(javax.xml.namespace.QName) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) JettyHTTPServerEngine(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) JettyHTTPDestination(org.apache.cxf.transport.http_jetty.JettyHTTPDestination)

Aggregations

Bus (org.apache.cxf.Bus)2 JettyHTTPDestination (org.apache.cxf.transport.http_jetty.JettyHTTPDestination)2 JettyHTTPServerEngine (org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine)2 QName (javax.xml.namespace.QName)1 ConfigurerImpl (org.apache.cxf.configuration.spring.ConfigurerImpl)1 ServerImpl (org.apache.cxf.endpoint.ServerImpl)1 ServerRegistry (org.apache.cxf.endpoint.ServerRegistry)1 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)1 ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)1 ConduitInitiatorManager (org.apache.cxf.transport.ConduitInitiatorManager)1 Destination (org.apache.cxf.transport.Destination)1 DestinationFactory (org.apache.cxf.transport.DestinationFactory)1 DestinationFactoryManager (org.apache.cxf.transport.DestinationFactoryManager)1 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)1 Handler (org.eclipse.jetty.server.Handler)1 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)1 Test (org.junit.Test)1