use of org.eclipse.jetty.servlet.FilterHolder in project druid by druid-io.
the class CoordinatorJettyServerInitializer method initialize.
@Override
public void initialize(Server server, Injector injector) {
final ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
root.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
root.addServlet(holderPwd, "/");
if (config.getConsoleStatic() == null) {
ResourceCollection staticResources;
if (beOverlord) {
staticResources = new ResourceCollection(Resource.newClassPathResource("io/druid/console"), Resource.newClassPathResource("static"), Resource.newClassPathResource("indexer_static"));
} else {
staticResources = new ResourceCollection(Resource.newClassPathResource("io/druid/console"), Resource.newClassPathResource("static"));
}
root.setBaseResource(staticResources);
} else {
// used for console development
root.setResourceBase(config.getConsoleStatic());
}
JettyServerInitUtils.addExtensionFilters(root, injector);
// /status should not redirect, so add first
root.addFilter(GuiceFilter.class, "/status/*", null);
// redirect anything other than status to the current lead
root.addFilter(new FilterHolder(injector.getInstance(RedirectFilter.class)), "/*", null);
// The coordinator really needs a standarized api path
// Can't use '/*' here because of Guice and Jetty static content conflicts
root.addFilter(GuiceFilter.class, "/info/*", null);
root.addFilter(GuiceFilter.class, "/druid/coordinator/*", null);
if (beOverlord) {
root.addFilter(GuiceFilter.class, "/druid/indexer/*", null);
}
// this will be removed in the next major release
root.addFilter(GuiceFilter.class, "/coordinator/*", null);
if (!beOverlord) {
root.addServlet(new ServletHolder(injector.getInstance(OverlordProxyServlet.class)), "/druid/indexer/*");
}
HandlerList handlerList = new HandlerList();
handlerList.setHandlers(new Handler[] { JettyServerInitUtils.getJettyRequestLogHandler(), JettyServerInitUtils.wrapWithDefaultGzipHandler(root) });
server.setHandler(handlerList);
}
use of org.eclipse.jetty.servlet.FilterHolder in project jetty.project by eclipse.
the class PutFilterTest method setUp.
@Before
public void setUp() throws Exception {
_dir = File.createTempFile("testPutFilter", null);
assertTrue(_dir.delete());
assertTrue(_dir.mkdir());
_dir.deleteOnExit();
assertTrue(_dir.isDirectory());
tester = new ServletTester("/context");
tester.setResourceBase(_dir.getCanonicalPath());
tester.addServlet(org.eclipse.jetty.servlet.DefaultServlet.class, "/");
FilterHolder holder = tester.addFilter(PutFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
holder.setInitParameter("delAllowed", "true");
// Bloody Windows does not allow file renaming
if (!System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows"))
holder.setInitParameter("putAtomic", "true");
tester.start();
}
use of org.eclipse.jetty.servlet.FilterHolder in project jetty.project by eclipse.
the class QoSFilterTest method testQosFilter.
@Test
public void testQosFilter() throws Exception {
FilterHolder holder = new FilterHolder(QoSFilter2.class);
holder.setAsyncSupported(true);
holder.setInitParameter(QoSFilter.MAX_REQUESTS_INIT_PARAM, String.valueOf(MAX_QOS));
_tester.getContext().getServletHandler().addFilterWithMapping(holder, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
List<Worker2> workers = new ArrayList<>();
for (int i = 0; i < NUM_CONNECTIONS; ++i) {
workers.add(new Worker2(i));
}
ExecutorService executor = Executors.newFixedThreadPool(NUM_CONNECTIONS);
List<Future<Void>> futures = executor.invokeAll(workers, 20, TimeUnit.SECONDS);
rethrowExceptions(futures);
if (TestServlet.__maxSleepers < MAX_QOS)
LOG.warn("TEST WAS NOT PARALLEL ENOUGH!");
else
Assert.assertEquals(TestServlet.__maxSleepers, MAX_QOS);
}
use of org.eclipse.jetty.servlet.FilterHolder in project jetty.project by eclipse.
the class AbstractDoSFilterTest method startServer.
public void startServer(Class<? extends Filter> filter) throws Exception {
_tester = new ServletTester("/ctx");
HttpURI uri = new HttpURI(_tester.createConnector(true));
_host = uri.getHost();
_port = uri.getPort();
_tester.getContext().addServlet(TestServlet.class, "/*");
FilterHolder dosFilter = _tester.getContext().addFilter(filter, "/dos/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
dosFilter.setInitParameter("maxRequestsPerSec", "4");
dosFilter.setInitParameter("delayMs", "200");
dosFilter.setInitParameter("throttledRequests", "1");
dosFilter.setInitParameter("waitMs", "10");
dosFilter.setInitParameter("throttleMs", "4000");
dosFilter.setInitParameter("remotePort", "false");
dosFilter.setInitParameter("insertHeaders", "true");
FilterHolder timeoutFilter = _tester.getContext().addFilter(filter, "/timeout/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
timeoutFilter.setInitParameter("maxRequestsPerSec", "4");
timeoutFilter.setInitParameter("delayMs", "200");
timeoutFilter.setInitParameter("throttledRequests", "1");
timeoutFilter.setInitParameter("waitMs", "10");
timeoutFilter.setInitParameter("throttleMs", "4000");
timeoutFilter.setInitParameter("remotePort", "false");
timeoutFilter.setInitParameter("insertHeaders", "true");
timeoutFilter.setInitParameter("maxRequestMs", _requestMaxTime + "");
_tester.start();
}
use of org.eclipse.jetty.servlet.FilterHolder in project jetty.project by eclipse.
the class CrossOriginFilterTest method testNonSimpleRequestWithoutPreflight.
@Test
public void testNonSimpleRequestWithoutPreflight() throws Exception {
// We cannot know if an actual request has performed the preflight before:
// we'll trust browsers to do it right, so responses to actual requests
// will contain the CORS response headers.
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
tester.getContext().addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
CountDownLatch latch = new CountDownLatch(1);
tester.getContext().addServlet(new ServletHolder(new ResourceServlet(latch)), "/*");
String request = "" + "PUT / HTTP/1.1\r\n" + "Host: localhost\r\n" + "Connection: close\r\n" + "Origin: http://localhost\r\n" + "\r\n";
String response = tester.getResponses(request);
Assert.assertTrue(response.contains("HTTP/1.1 200"));
Assert.assertTrue(response.contains(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER));
Assert.assertTrue(response.contains(CrossOriginFilter.ACCESS_CONTROL_ALLOW_CREDENTIALS_HEADER));
Assert.assertTrue(latch.await(1, TimeUnit.SECONDS));
}
Aggregations