use of org.eclipse.jetty.servlet.FilterHolder in project jetty.project by eclipse.
the class WebSocketUpgradeFilter method configureContext.
public static WebSocketUpgradeFilter configureContext(ServletContextHandler context) throws ServletException {
// Prevent double configure
WebSocketUpgradeFilter filter = (WebSocketUpgradeFilter) context.getAttribute(WebSocketUpgradeFilter.class.getName());
if (filter != null) {
return filter;
}
// Dynamically add filter
NativeWebSocketConfiguration configuration = NativeWebSocketServletContainerInitializer.getDefaultFrom(context.getServletContext());
filter = new WebSocketUpgradeFilter(configuration);
filter.setToAttribute(context, WebSocketUpgradeFilter.class.getName());
String name = "Jetty_WebSocketUpgradeFilter";
String pathSpec = "/*";
EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST);
FilterHolder fholder = new FilterHolder(filter);
fholder.setName(name);
fholder.setAsyncSupported(true);
fholder.setInitParameter(CONTEXT_ATTRIBUTE_KEY, WebSocketUpgradeFilter.class.getName());
context.addFilter(fholder, pathSpec, dispatcherTypes);
if (LOG.isDebugEnabled()) {
LOG.debug("Adding [{}] {} mapped to {} to {}", name, filter, pathSpec, context);
}
return filter;
}
use of org.eclipse.jetty.servlet.FilterHolder in project jetty.project by eclipse.
the class QoSFilterTest method testBlockingQosFilter.
@Test
public void testBlockingQosFilter() throws Exception {
FilterHolder holder = new FilterHolder(QoSFilter2.class);
holder.setAsyncSupported(true);
holder.setInitParameter(QoSFilter.MAX_REQUESTS_INIT_PARAM, "" + MAX_QOS);
_tester.getContext().getServletHandler().addFilterWithMapping(holder, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
List<Worker> workers = new ArrayList<>();
for (int i = 0; i < NUM_CONNECTIONS; ++i) {
workers.add(new Worker(i));
}
ExecutorService executor = Executors.newFixedThreadPool(NUM_CONNECTIONS);
List<Future<Void>> futures = executor.invokeAll(workers, 10, 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 GzipFilterLayeredTest method testGzipDos.
@Test
public void testGzipDos() throws Exception {
GzipTester tester = new GzipTester(testingdir, GzipHandler.GZIP);
// Add Gzip Filter first
FilterHolder gzipHolder = new FilterHolder(gzipFilterClass);
gzipHolder.setAsyncSupported(true);
tester.addFilter(gzipHolder, "*.txt", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
tester.addFilter(gzipHolder, "*.mp3", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
gzipHolder.setInitParameter("mimeTypes", "text/plain");
// Add (DoSFilter-like) manip filter (in chain of Gzip)
FilterHolder manipHolder = new FilterHolder(AsyncManipFilter.class);
manipHolder.setAsyncSupported(true);
tester.addFilter(manipHolder, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
// Add content servlet
tester.setContentServlet(contentServletClass);
try {
String testFilename = String.format("GzipDos-%s-%s", contentServletClass.getSimpleName(), fileName);
File testFile = tester.prepareServerFile(testFilename, fileSize);
tester.start();
HttpTester.Response response = tester.executeRequest("GET", "/context/" + testFile.getName(), 5, TimeUnit.SECONDS);
assertThat("Response status", response.getStatus(), is(HttpStatus.OK_200));
if (expectCompressed) {
// Must be gzip compressed
assertThat("Content-Encoding", response.get("Content-Encoding"), containsString(GzipHandler.GZIP));
}
// Uncompressed content Size
ContentMetadata content = tester.getResponseMetadata(response);
assertThat("(Uncompressed) Content Length", content.size, is((long) fileSize));
} finally {
tester.stop();
}
}
use of org.eclipse.jetty.servlet.FilterHolder in project jetty.project by eclipse.
the class GzipFilterLayeredTest method testDosGzip.
@Test
public void testDosGzip() throws Exception {
GzipTester tester = new GzipTester(testingdir, GzipHandler.GZIP);
// Add (DoSFilter-like) manip filter
FilterHolder manipHolder = new FilterHolder(AsyncManipFilter.class);
manipHolder.setAsyncSupported(true);
tester.addFilter(manipHolder, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
// Add Gzip Filter first (in chain of DosFilter)
FilterHolder gzipHolder = new FilterHolder(gzipFilterClass);
gzipHolder.setAsyncSupported(true);
tester.addFilter(gzipHolder, "*.txt", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
tester.addFilter(gzipHolder, "*.mp3", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
gzipHolder.setInitParameter("mimeTypes", "text/plain");
// Add content servlet
tester.setContentServlet(contentServletClass);
try {
String testFilename = String.format("DosGzip-%s-%s", contentServletClass.getSimpleName(), fileName);
File testFile = tester.prepareServerFile(testFilename, fileSize);
tester.start();
HttpTester.Response response = tester.executeRequest("GET", "/context/" + testFile.getName(), 5, TimeUnit.SECONDS);
assertThat("Response status", response.getStatus(), is(HttpStatus.OK_200));
if (expectCompressed) {
// Must be gzip compressed
assertThat("Content-Encoding", response.get("Content-Encoding"), containsString(GzipHandler.GZIP));
} else {
assertThat("Content-Encoding", response.get("Content-Encoding"), not(containsString(GzipHandler.GZIP)));
}
// Uncompressed content Size
ContentMetadata content = tester.getResponseMetadata(response);
assertThat("(Uncompressed) Content Length", content.size, is((long) fileSize));
} finally {
tester.stop();
}
}
use of org.eclipse.jetty.servlet.FilterHolder in project Openfire by igniterealtime.
the class HttpBindManager method createBoshHandler.
private void createBoshHandler(ContextHandlerCollection contexts, String boshPath) {
ServletContextHandler context = new ServletContextHandler(contexts, boshPath, ServletContextHandler.SESSIONS);
// Ensure the JSP engine is initialized correctly (in order to be able to cope with Tomcat/Jasper precompiled JSPs).
final List<ContainerInitializer> initializers = new ArrayList<>();
initializers.add(new ContainerInitializer(new JasperInitializer(), null));
context.setAttribute("org.eclipse.jetty.containerInitializers", initializers);
context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
context.setAllowNullPathInfo(true);
context.addServlet(new ServletHolder(new HttpBindServlet()), "/*");
if (isHttpCompressionEnabled()) {
Filter gzipFilter = new AsyncGzipFilter() {
@Override
public void init(FilterConfig config) throws ServletException {
super.init(config);
_methods.add(HttpMethod.POST.asString());
Log.info("Installed response compression filter");
}
};
FilterHolder filterHolder = new FilterHolder();
filterHolder.setFilter(gzipFilter);
context.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
}
}
Aggregations