Search in sources :

Example 51 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project async-http-client by AsyncHttpClient.

the class BasicHttpProxyToHttpTest method setUpGlobal.

@BeforeClass
public void setUpGlobal() throws Exception {
    httpServer = new Server();
    ServerConnector connector1 = addHttpConnector(httpServer);
    httpServer.setHandler(new EchoHandler());
    httpServer.start();
    httpPort = connector1.getLocalPort();
    proxy = new Server();
    ServerConnector connector2 = addHttpConnector(proxy);
    ServletHandler servletHandler = new ServletHandler();
    ServletHolder servletHolder = servletHandler.addServletWithMapping(BasicAuthProxyServlet.class, "/*");
    servletHolder.setInitParameter("maxThreads", "20");
    proxy.setHandler(servletHandler);
    proxy.start();
    proxyPort = connector2.getLocalPort();
    LOGGER.info("Local HTTP Server (" + httpPort + "), Proxy (" + proxyPort + ") started successfully");
}
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) EchoHandler(org.asynchttpclient.test.EchoHandler) BeforeClass(org.testng.annotations.BeforeClass)

Example 52 with ServletHandler

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

the class ChassisEurekaTestConfiguration method httpServer.

@Order(0)
@Bean(initMethod = "start", destroyMethod = "stop")
public Server httpServer(@Value("${http.hostname}") String hostname, @Value("${http.port}") int port, ConfigurableWebApplicationContext webApplicationContext) {
    // set up servlets
    ServletHandler servlets = new ServletHandler();
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS | 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 = StringUtils.isBlank(hostname) ? new InetSocketAddress(port) : new InetSocketAddress(hostname, port);
    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);
    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 53 with ServletHandler

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

the class ServletEnvironment method addServlet.

/**
 * Add a servlet instance.
 *
 * @param name    the servlet's name
 * @param servlet the servlet instance
 * @return a {@link javax.servlet.ServletRegistration.Dynamic} instance allowing for further
 *         configuration
 */
public ServletRegistration.Dynamic addServlet(String name, Servlet servlet) {
    final ServletHolder holder = new ServletHolder(name, servlet);
    final ServletHandler servletHandler = handler.getServletHandler();
    servletHandler.addServlet(holder);
    final ServletRegistration.Dynamic registration = holder.getRegistration();
    checkDuplicateRegistration(name, servlets, "servlet");
    return registration;
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler) ServletRegistration(javax.servlet.ServletRegistration) ServletHolder(org.eclipse.jetty.servlet.ServletHolder)

Example 54 with ServletHandler

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

the class ServletEnvironment method addServlet.

/**
 * Add a servlet class.
 *
 * @param name  the servlet's name
 * @param klass the servlet class
 * @return a {@link javax.servlet.ServletRegistration.Dynamic} instance allowing for further configuration
 */
public ServletRegistration.Dynamic addServlet(String name, Class<? extends Servlet> klass) {
    final ServletHolder holder = new ServletHolder(name, klass);
    final ServletHandler servletHandler = handler.getServletHandler();
    servletHandler.addServlet(holder);
    final ServletRegistration.Dynamic registration = holder.getRegistration();
    checkDuplicateRegistration(name, servlets, "servlet");
    return registration;
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler) ServletRegistration(javax.servlet.ServletRegistration) ServletHolder(org.eclipse.jetty.servlet.ServletHolder)

Example 55 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project http-request by kevinsawicki.

the class ServerTestCase method setUp.

/**
 * Set up server with handler
 *
 * @param handler
 * @return port
 * @throws Exception
 */
public static String setUp(final Handler handler) throws Exception {
    server = new Server();
    if (handler != null)
        server.setHandler(handler);
    Connector connector = new SelectChannelConnector();
    connector.setPort(0);
    server.setConnectors(new Connector[] { connector });
    server.start();
    proxy = new Server();
    Connector proxyConnector = new SelectChannelConnector();
    proxyConnector.setPort(0);
    proxy.setConnectors(new Connector[] { proxyConnector });
    ServletHandler proxyHandler = new ServletHandler();
    RequestHandler proxyCountingHandler = new RequestHandler() {

        @Override
        public void handle(Request request, HttpServletResponse response) {
            proxyHitCount.incrementAndGet();
            String auth = request.getHeader("Proxy-Authorization");
            auth = auth.substring(auth.indexOf(' ') + 1);
            try {
                auth = B64Code.decode(auth, CHARSET_UTF8);
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
            }
            int colon = auth.indexOf(':');
            proxyUser.set(auth.substring(0, colon));
            proxyPassword.set(auth.substring(colon + 1));
            request.setHandled(false);
        }
    };
    HandlerList handlerList = new HandlerList();
    handlerList.addHandler(proxyCountingHandler);
    handlerList.addHandler(proxyHandler);
    proxy.setHandler(handlerList);
    ServletHolder proxyHolder = proxyHandler.addServletWithMapping("org.eclipse.jetty.servlets.ProxyServlet", "/");
    proxyHolder.setAsyncSupported(true);
    proxy.start();
    proxyPort = proxyConnector.getLocalPort();
    return "http://localhost:" + connector.getLocalPort();
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) Connector(org.eclipse.jetty.server.Connector) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector)

Aggregations

ServletHandler (org.eclipse.jetty.servlet.ServletHandler)59 Server (org.eclipse.jetty.server.Server)24 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)24 ServerConnector (org.eclipse.jetty.server.ServerConnector)12 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 FilterMapping (org.eclipse.jetty.servlet.FilterMapping)5 ServletMapping (org.eclipse.jetty.servlet.ServletMapping)5 HashMap (java.util.HashMap)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 InetSocketAddress (java.net.InetSocketAddress)3 HttpServlet (javax.servlet.http.HttpServlet)3 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2