Search in sources :

Example 16 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project neo4j by neo4j.

the class OcspStaplingIT method startOcspMock.

private static int startOcspMock() throws Exception {
    Server jettyServer = new Server(0);
    ServletHandler handler = new ServletHandler();
    jettyServer.setHandler(handler);
    jettyServer.setDumpBeforeStop(true);
    handler.addServletWithMapping(EndUserOcspResponderServlet.class, "/endUserCA");
    handler.addServletWithMapping(IntOcspResponderServlet.class, "/intCA");
    jettyServer.start();
    return jettyServer.getURI().getPort();
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Server(org.eclipse.jetty.server.Server)

Example 17 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project qi4j-sdk by Qi4j.

the class AbstractJettyMixin method startJetty.

@Override
public final void startJetty() throws Exception {
    // Prepare ServletContext
    ServletContextHandler root = new ServletContextHandler(server, "/", new SessionHandler(), buildSecurityHandler(), new ServletHandler(), new ErrorHandler());
    root.setDisplayName(identity);
    configureContext(root, configuration());
    // Register ContextListeners, Servlets and Filters
    addContextListeners(root, contextListeners);
    addServlets(root, servlets);
    addFilters(root, filters);
    // Prepare Connector
    Connector connector = buildConnector();
    configureConnector(connector, configuration());
    // Prepare Server
    configureServer(server, configuration());
    server.addConnector(connector);
    if (mBeanServer != null) {
        server.getContainer().addEventListener(new MBeanContainer(mBeanServer));
    }
    // Start
    server.start();
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) Connector(org.eclipse.jetty.server.Connector) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 18 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project chassis by Kixeye.

the class TestSpringWebApp method httpServer.

@Bean(initMethod = "start", destroyMethod = "stop", name = "httpServer")
@Order(0)
public Server httpServer(ConfigurableWebApplicationContext webApplicationContext) {
    // set up servlets
    ServletHandler servlets = new ServletHandler();
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY);
    context.setErrorHandler(null);
    context.setWelcomeFiles(new String[] { "/" });
    // set up spring with the servlet context
    setServletContext(context.getServletContext());
    // configure the spring mvc dispatcher
    DispatcherServlet dispatcher = new DispatcherServlet(webApplicationContext);
    // map application servlets
    context.addServlet(new ServletHolder(dispatcher), "/");
    servlets.setHandler(context);
    // create the server
    InetSocketAddress address = new InetSocketAddress(SocketUtils.findAvailableTcpPort());
    Server server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setHost(address.getHostName());
    connector.setPort(address.getPort());
    server.setConnectors(new Connector[] { connector });
    server.setHandler(servlets);
    server.setStopAtShutdown(true);
    return server;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) InetSocketAddress(java.net.InetSocketAddress) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Order(org.springframework.core.annotation.Order) Bean(org.springframework.context.annotation.Bean)

Example 19 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project druid by druid-io.

the class AsyncManagementForwardingServletTest method makeTestServer.

private static Server makeTestServer(int port, ExpectedRequest expectedRequest) {
    Server server = new Server(port);
    ServletHandler handler = new ServletHandler();
    handler.addServletWithMapping(new ServletHolder(new HttpServlet() {

        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
            handle(req, resp);
        }

        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
            handle(req, resp);
        }

        @Override
        protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException {
            handle(req, resp);
        }

        @Override
        protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
            handle(req, resp);
        }

        private void handle(HttpServletRequest req, HttpServletResponse resp) throws IOException {
            boolean passed = expectedRequest.path.equals(req.getRequestURI());
            passed &= expectedRequest.query == null || expectedRequest.query.equals(req.getQueryString());
            passed &= expectedRequest.method.equals(req.getMethod());
            if (expectedRequest.headers != null) {
                for (Map.Entry<String, String> header : expectedRequest.headers.entrySet()) {
                    passed &= header.getValue().equals(req.getHeader(header.getKey()));
                }
            }
            passed &= expectedRequest.body == null || expectedRequest.body.equals(IOUtils.toString(req.getReader()));
            expectedRequest.called = true;
            resp.setStatus(passed ? 200 : 400);
        }
    }), "/*");
    server.setHandler(handler);
    return server;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 20 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project jena by apache.

the class ExFusekiMain_1_Servlet_AddFilter method addExtraFilter.

// Find the FusekiFilter and replace it with an indirection filter.
private static void addExtraFilter(FusekiServer server) {
    Handler handler = server.getJettyServer().getHandler();
    ServletContextHandler sch = (ServletContextHandler) handler;
    ServletHandler servletHander = sch.getServletHandler();
    FilterHolder[] fHolders = servletHander.getFilters();
    for (int i = 0; i < fHolders.length; i++) {
        FilterHolder fh = fHolders[i];
        if (fh.getClassName().equals(FusekiFilter.class.getName())) {
            FilterHolder fh2 = replacement(fh);
            // ** Replacement.
            fHolders[i] = fh2;
        }
    }
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) FusekiFilter(org.apache.jena.fuseki.servlets.FusekiFilter) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

ServletHandler (org.eclipse.jetty.servlet.ServletHandler)54 Server (org.eclipse.jetty.server.Server)23 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)22 ServerConnector (org.eclipse.jetty.server.ServerConnector)11 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)10 Test (org.junit.Test)10 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)8 MockFlowFile (org.apache.nifi.util.MockFlowFile)5 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)5 HashMap (java.util.HashMap)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 FilterMapping (org.eclipse.jetty.servlet.FilterMapping)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 InetSocketAddress (java.net.InetSocketAddress)3 HttpServlet (javax.servlet.http.HttpServlet)3 ServletMapping (org.eclipse.jetty.servlet.ServletMapping)3 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2