use of org.eclipse.jetty.servlet.FilterHolder in project hbase by apache.
the class HttpServer method defineFilter.
/**
* Define a filter for a context and set up default url mappings.
*/
public static void defineFilter(ServletContextHandler handler, String name, String classname, Map<String, String> parameters, String[] urls) {
FilterHolder holder = new FilterHolder();
holder.setName(name);
holder.setClassName(classname);
if (parameters != null) {
holder.setInitParameters(parameters);
}
FilterMapping fmap = new FilterMapping();
fmap.setPathSpecs(urls);
fmap.setDispatches(FilterMapping.ALL);
fmap.setFilterName(name);
handler.getServletHandler().addFilter(holder, fmap);
}
use of org.eclipse.jetty.servlet.FilterHolder in project zeppelin by apache.
the class ZeppelinServer method setupWebAppContext.
private static WebAppContext setupWebAppContext(ContextHandlerCollection contexts, ZeppelinConfiguration conf) {
WebAppContext webApp = new WebAppContext();
webApp.setContextPath(conf.getServerContextPath());
File warPath = new File(conf.getString(ConfVars.ZEPPELIN_WAR));
if (warPath.isDirectory()) {
// Development mode, read from FS
// webApp.setDescriptor(warPath+"/WEB-INF/web.xml");
webApp.setResourceBase(warPath.getPath());
webApp.setParentLoaderPriority(true);
} else {
// use packaged WAR
webApp.setWar(warPath.getAbsolutePath());
File warTempDirectory = new File(conf.getRelativeDir(ConfVars.ZEPPELIN_WAR_TEMPDIR));
warTempDirectory.mkdir();
LOG.info("ZeppelinServer Webapp path: {}", warTempDirectory.getPath());
webApp.setTempDirectory(warTempDirectory);
}
// Explicit bind to root
webApp.addServlet(new ServletHolder(new DefaultServlet()), "/*");
contexts.addHandler(webApp);
webApp.addFilter(new FilterHolder(CorsFilter.class), "/*", EnumSet.allOf(DispatcherType.class));
webApp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", Boolean.toString(conf.getBoolean(ConfVars.ZEPPELIN_SERVER_DEFAULT_DIR_ALLOWED)));
return webApp;
}
use of org.eclipse.jetty.servlet.FilterHolder in project storm by apache.
the class UIHelpers method corsFilterHandle.
public static FilterHolder corsFilterHandle() {
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "GET, POST, PUT");
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "X-Requested-With, X-Requested-By, Access-Control-Allow-Origin, Content-Type, Content-Length, Accept, Origin");
filterHolder.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*");
return filterHolder;
}
use of org.eclipse.jetty.servlet.FilterHolder in project druid by druid-io.
the class JettyServerInitUtils method addExtensionFilters.
public static void addExtensionFilters(ServletContextHandler handler, Injector injector) {
Set<ServletFilterHolder> extensionFilters = injector.getInstance(Key.get(new TypeLiteral<Set<ServletFilterHolder>>() {
}));
for (ServletFilterHolder servletFilterHolder : extensionFilters) {
// Check the Filter first to guard against people who don't read the docs and return the Class even
// when they have an instance.
FilterHolder holder = null;
if (servletFilterHolder.getFilter() != null) {
holder = new FilterHolder(servletFilterHolder.getFilter());
} else if (servletFilterHolder.getFilterClass() != null) {
holder = new FilterHolder(servletFilterHolder.getFilterClass());
} else {
throw new ISE("Filter[%s] for path[%s] didn't have a Filter!?", servletFilterHolder, servletFilterHolder.getPath());
}
if (servletFilterHolder.getInitParameters() != null) {
holder.setInitParameters(servletFilterHolder.getInitParameters());
}
handler.addFilter(holder, servletFilterHolder.getPath(), servletFilterHolder.getDispatcherType());
}
}
use of org.eclipse.jetty.servlet.FilterHolder in project dropwizard by dropwizard.
the class ServletEnvironmentTest method addsFilterInstances.
@Test
public void addsFilterInstances() throws Exception {
final Filter filter = mock(Filter.class);
final FilterRegistration.Dynamic builder = environment.addFilter("filter", filter);
assertThat(builder).isNotNull();
final ArgumentCaptor<FilterHolder> holder = ArgumentCaptor.forClass(FilterHolder.class);
verify(servletHandler).addFilter(holder.capture());
assertThat(holder.getValue().getName()).isEqualTo("filter");
assertThat(holder.getValue().getFilter()).isEqualTo(filter);
}
Aggregations