Search in sources :

Example 46 with FilterHolder

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);
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) FilterMapping(org.eclipse.jetty.servlet.FilterMapping)

Example 47 with FilterHolder

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;
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) DispatcherType(javax.servlet.DispatcherType) File(java.io.File)

Example 48 with FilterHolder

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;
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) CrossOriginFilter(org.eclipse.jetty.servlets.CrossOriginFilter)

Example 49 with 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());
    }
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) TypeLiteral(com.google.inject.TypeLiteral) ISE(io.druid.java.util.common.ISE)

Example 50 with FilterHolder

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);
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) ContinuationFilter(org.eclipse.jetty.continuation.ContinuationFilter) Filter(javax.servlet.Filter) FilterRegistration(javax.servlet.FilterRegistration) Test(org.junit.Test)

Aggregations

FilterHolder (org.eclipse.jetty.servlet.FilterHolder)84 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)44 Test (org.junit.Test)35 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)32 Server (org.eclipse.jetty.server.Server)21 CountDownLatch (java.util.concurrent.CountDownLatch)18 Filter (javax.servlet.Filter)11 IOException (java.io.IOException)10 URL (java.net.URL)10 DispatcherType (javax.servlet.DispatcherType)9 ServletException (javax.servlet.ServletException)8 AuthenticationToken (org.apache.hadoop.security.authentication.server.AuthenticationToken)8 ServerConnector (org.eclipse.jetty.server.ServerConnector)8 File (java.io.File)7 HttpURLConnection (java.net.HttpURLConnection)7 PrivilegedActionException (java.security.PrivilegedActionException)7 AuthenticationException (org.apache.hadoop.security.authentication.client.AuthenticationException)7 FilterMapping (org.eclipse.jetty.servlet.FilterMapping)7 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)7 List (java.util.List)6