Search in sources :

Example 1 with Server

use of org.eclipse.jetty.server.Server in project camel by apache.

the class CMISTestSupport method startServer.

@BeforeClass
public static void startServer() throws Exception {
    port = AvailablePortFinder.getNextAvailable(26500);
    cmisServer = new Server(port);
    cmisServer.setHandler(new WebAppContext(OPEN_CMIS_SERVER_WAR_PATH, "/chemistry-opencmis-server-inmemory"));
    cmisServer.start();
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server) BeforeClass(org.junit.BeforeClass)

Example 2 with Server

use of org.eclipse.jetty.server.Server in project camel by apache.

the class CometdComponent method createServer.

protected Server createServer() throws Exception {
    Server server = new Server();
    ContextHandlerCollection collection = new ContextHandlerCollection();
    server.setHandler(collection);
    return server;
}
Also used : Server(org.eclipse.jetty.server.Server) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection)

Example 3 with Server

use of org.eclipse.jetty.server.Server in project camel by apache.

the class CometdComponent method connect.

/**
     * Connects the URL specified on the endpoint to the specified processor.
     */
public void connect(CometdProducerConsumer prodcon) throws Exception {
    Server server = null;
    // Make sure that there is a connector for the requested endpoint.
    CometdEndpoint endpoint = prodcon.getEndpoint();
    String connectorKey = endpoint.getProtocol() + ":" + endpoint.getUri().getHost() + ":" + endpoint.getPort();
    synchronized (connectors) {
        ConnectorRef connectorRef = connectors.get(connectorKey);
        if (connectorRef == null) {
            ServerConnector connector;
            server = createServer();
            if ("cometds".equals(endpoint.getProtocol())) {
                connector = getSslSocketConnector(server);
            } else {
                connector = new ServerConnector(server);
            }
            connector.setPort(endpoint.getPort());
            connector.setHost(endpoint.getUri().getHost());
            if ("localhost".equalsIgnoreCase(endpoint.getUri().getHost())) {
                LOG.warn("You use localhost interface! It means that no external connections will be available." + " Don't you want to use 0.0.0.0 instead (all network interfaces)?");
            }
            server.addConnector(connector);
            CometDServlet servlet = createServletForConnector(server, connector, endpoint);
            connectorRef = new ConnectorRef(connector, servlet, server);
            server.start();
            connectors.put(connectorKey, connectorRef);
        } else {
            connectorRef.increment();
        }
        BayeuxServerImpl bayeux = connectorRef.servlet.getBayeux();
        if (securityPolicy != null) {
            bayeux.setSecurityPolicy(securityPolicy);
        }
        if (extensions != null) {
            for (BayeuxServer.Extension extension : extensions) {
                bayeux.addExtension(extension);
            }
        }
        if (serverListeners != null) {
            for (BayeuxServer.BayeuxServerListener serverListener : serverListeners) {
                bayeux.addListener(serverListener);
            }
        }
        prodcon.setBayeux(bayeux);
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) BayeuxServerImpl(org.cometd.server.BayeuxServerImpl) Server(org.eclipse.jetty.server.Server) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) CometDServlet(org.cometd.server.CometDServlet)

Example 4 with Server

use of org.eclipse.jetty.server.Server in project camel by apache.

the class CometdCrossOriginConsumerTest method testCrossOriginFilterNotAddedWhenOff.

@Test
public void testCrossOriginFilterNotAddedWhenOff() throws Exception {
    // setup
    CometdComponent component = context.getComponent("cometd", CometdComponent.class);
    Server server = new Server();
    when(endpoint.isCrossOriginFilterOn()).thenReturn(false);
    // act
    component.createServletForConnector(server, connector, endpoint);
    // assert
    ServletContextHandler handler = (ServletContextHandler) server.getHandler();
    assertEquals(0, handler.getServletHandler().getFilters().length);
}
Also used : Server(org.eclipse.jetty.server.Server) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Test(org.junit.Test)

Example 5 with Server

use of org.eclipse.jetty.server.Server in project camel by apache.

the class CometdCrossOriginConsumerTest method testCrossOriginFilterAddedWhenOn.

@Test
public void testCrossOriginFilterAddedWhenOn() throws Exception {
    // setup
    CometdComponent component = context.getComponent("cometd", CometdComponent.class);
    Server server = new Server();
    when(endpoint.isCrossOriginFilterOn()).thenReturn(true);
    when(endpoint.getFilterPath()).thenReturn(FILTER_PATH);
    when(endpoint.getAllowedOrigins()).thenReturn(ALLOWED_ORIGINS);
    // act
    component.createServletForConnector(server, connector, endpoint);
    // assert
    ServletContextHandler handler = (ServletContextHandler) server.getHandler();
    assertEquals(1, handler.getServletHandler().getFilters().length);
    FilterHolder filterHolder = handler.getServletHandler().getFilters()[0];
    Filter filter = filterHolder.getFilter();
    assertTrue(filter instanceof CrossOriginFilter);
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) Filter(javax.servlet.Filter) CrossOriginFilter(org.eclipse.jetty.servlets.CrossOriginFilter) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) CrossOriginFilter(org.eclipse.jetty.servlets.CrossOriginFilter) Test(org.junit.Test)

Aggregations

Server (org.eclipse.jetty.server.Server)521 ServerConnector (org.eclipse.jetty.server.ServerConnector)209 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)129 Test (org.junit.Test)103 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)99 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)68 IOException (java.io.IOException)66 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)65 File (java.io.File)62 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)61 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)58 URI (java.net.URI)52 Before (org.junit.Before)50 BeforeClass (org.junit.BeforeClass)47 ServletException (javax.servlet.ServletException)44 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)43 LocalConnector (org.eclipse.jetty.server.LocalConnector)42 URL (java.net.URL)37 HttpServletRequest (javax.servlet.http.HttpServletRequest)33 HttpServletResponse (javax.servlet.http.HttpServletResponse)31