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");
}
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;
}
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;
}
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;
}
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();
}
Aggregations