当前位置: 首页>>代码示例>>Java>>正文


Java Context.addFilter方法代码示例

本文整理汇总了Java中org.mortbay.jetty.servlet.Context.addFilter方法的典型用法代码示例。如果您正苦于以下问题:Java Context.addFilter方法的具体用法?Java Context.addFilter怎么用?Java Context.addFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mortbay.jetty.servlet.Context的用法示例。


在下文中一共展示了Context.addFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startServer

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
private static void startServer() throws Exception, InterruptedException {
  Server server = new Server(port);
  Context context = new Context(server, "/", Context.SESSIONS);
  context.addServlet(DefaultServlet.class, "/*");

  context.addEventListener(new ContextLoaderListener(getContext()));
  context.addEventListener(new RequestContextListener());

  WicketFilter filter = new WicketFilter();
  filter.setFilterPath("/");
  FilterHolder holder = new FilterHolder(filter);
  holder.setInitParameter("applicationFactoryClassName", APP_FACTORY_NAME);
  context.addFilter(holder, "/*", Handler.DEFAULT);

  server.setHandler(context);
  server.start();
  server.join();
}
 
开发者ID:jorcox,项目名称:GeoCrawler,代码行数:19,代码来源:NutchUiServer.java

示例2: start

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
protected void start() throws Exception {
  server = new Server(0);
  context = new Context();
  context.setContextPath("/foo");
  server.setHandler(context);
  context.addFilter(new FilterHolder(TestFilter.class), "/*", 0);
  context.addServlet(new ServletHolder(TestServlet.class), "/bar");
  host = "localhost";
  ServerSocket ss = new ServerSocket(0);
  port = ss.getLocalPort();
  ss.close();
  server.getConnectors()[0].setHost(host);
  server.getConnectors()[0].setPort(port);
  server.start();
  System.out.println("Running embedded servlet container at: http://" + host + ":" + port);
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:17,代码来源:AuthenticatorTestCase.java

示例3: addFilters

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
protected void addFilters(Context context) throws ClassNotFoundException, NoSuchMethodException,
    InstantiationException, IllegalAccessException, InvocationTargetException {

  context.addFilter(XdServletFilter.class, "/*", Handler.DEFAULT);
  context.addFilter(MethodOverrideServletFilter.class, "/*", Handler.DEFAULT);

  if (FlagConfig.enableAuth_FLAG.equalsIgnoreCase("true")) {
    ServletHolder servletHolder2 = new ServletHolder(new GetAuthTokenServlet());
    context.addServlet(servletHolder2, "/accounts/ClientLogin");
    context.addFilter(SignedRequestFilter.class, "/*", org.mortbay.jetty.Handler.DEFAULT);
    EventListener listener = new GuiceServletContextListener();
    context.addEventListener(listener);
    logger.info("FeedServer to accept signed requests");
  } else if (!FlagConfig.enableOAuthSignedFetch_FLAG.equalsIgnoreCase("false")) {
    // Register the OAuth filter
    SimpleKeyMananger sKeyManager = new SimpleKeyMananger();
    Filter oauthFilter = 
        createOAuthFilter(FlagConfig.enableOAuthSignedFetch_FLAG.equalsIgnoreCase("true") ?
        FlagConfig.OAUTH_SIGNED_FETCH_FILTER_CLASS_NAME :
 		    FlagConfig.enableOAuthSignedFetch_FLAG, sKeyManager);
    context.addFilter(new FilterHolder(oauthFilter), "/*", org.mortbay.jetty.Handler.DEFAULT);
    logger.info("FeedServer to accept OAuth signed requests");
  }
}
 
开发者ID:jyang,项目名称:google-feedserver,代码行数:25,代码来源:Main.java

示例4: testExternalDelegationTokenSecretManager

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
@Test
public void testExternalDelegationTokenSecretManager() throws Exception {
  DummyDelegationTokenSecretManager secretMgr
      = new DummyDelegationTokenSecretManager();
  final Server jetty = createJettyServer();
  Context context = new Context();
  context.setContextPath("/foo");
  jetty.setHandler(context);
  context.addFilter(new FilterHolder(AFilter.class), "/*", 0);
  context.addServlet(new ServletHolder(PingServlet.class), "/bar");
  try {
    secretMgr.startThreads();
    context.setAttribute(DelegationTokenAuthenticationFilter.
            DELEGATION_TOKEN_SECRET_MANAGER_ATTR, secretMgr);
    jetty.start();
    URL authURL = new URL(getJettyURL() + "/foo/bar?authenticated=foo");

    DelegationTokenAuthenticatedURL.Token token =
        new DelegationTokenAuthenticatedURL.Token();
    DelegationTokenAuthenticatedURL aUrl =
        new DelegationTokenAuthenticatedURL();

    aUrl.getDelegationToken(authURL, token, FOO_USER);
    Assert.assertNotNull(token.getDelegationToken());
    Assert.assertEquals(new Text("fooKind"),
        token.getDelegationToken().getKind());

  } finally {
    jetty.stop();
    secretMgr.stopThreads();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:33,代码来源:TestWebDelegationToken.java

示例5: testFallbackToPseudoDelegationTokenAuthenticator

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
@Test
public void testFallbackToPseudoDelegationTokenAuthenticator()
    throws Exception {
  final Server jetty = createJettyServer();
  Context context = new Context();
  context.setContextPath("/foo");
  jetty.setHandler(context);
  context.addFilter(new FilterHolder(PseudoDTAFilter.class), "/*", 0);
  context.addServlet(new ServletHolder(UserServlet.class), "/bar");

  try {
    jetty.start();
    final URL url = new URL(getJettyURL() + "/foo/bar");

    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(FOO_USER);
    ugi.doAs(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        DelegationTokenAuthenticatedURL.Token token =
            new DelegationTokenAuthenticatedURL.Token();
        DelegationTokenAuthenticatedURL aUrl =
            new DelegationTokenAuthenticatedURL();
        HttpURLConnection conn = aUrl.openConnection(url, token);
        Assert.assertEquals(HttpURLConnection.HTTP_OK,
            conn.getResponseCode());
        List<String> ret = IOUtils.readLines(conn.getInputStream());
        Assert.assertEquals(1, ret.size());
        Assert.assertEquals(FOO_USER, ret.get(0));

        aUrl.getDelegationToken(url, token, FOO_USER);
        Assert.assertNotNull(token.getDelegationToken());
        Assert.assertEquals(new Text("token-kind"),
            token.getDelegationToken().getKind());
        return null;
      }
    });
  } finally {
    jetty.stop();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:41,代码来源:TestWebDelegationToken.java

示例6: testIpaddressCheck

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
@Test
public void testIpaddressCheck() throws Exception {
  final Server jetty = createJettyServer();
  ((AbstractConnector)jetty.getConnectors()[0]).setResolveNames(true);
  Context context = new Context();
  context.setContextPath("/foo");
  jetty.setHandler(context);

  context.addFilter(new FilterHolder(IpAddressBasedPseudoDTAFilter.class), "/*", 0);
  context.addServlet(new ServletHolder(UGIServlet.class), "/bar");

  try {
    jetty.start();
    final URL url = new URL(getJettyURL() + "/foo/bar");

    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(FOO_USER);
    ugi.doAs(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        DelegationTokenAuthenticatedURL.Token token =
                new DelegationTokenAuthenticatedURL.Token();
        DelegationTokenAuthenticatedURL aUrl =
                new DelegationTokenAuthenticatedURL();

        // user ok-user via proxyuser foo
        HttpURLConnection conn = aUrl.openConnection(url, token, OK_USER);
        Assert.assertEquals(HttpURLConnection.HTTP_OK,
                conn.getResponseCode());
        List<String> ret = IOUtils.readLines(conn.getInputStream());
        Assert.assertEquals(1, ret.size());
        Assert.assertEquals("realugi=" + FOO_USER +":remoteuser=" + OK_USER +
                ":ugi=" + OK_USER, ret.get(0));

        return null;
      }
    });
  } finally {
    jetty.stop();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:41,代码来源:TestWebDelegationToken.java

示例7: startJetty

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
protected void startJetty() throws Exception {
  server = new Server(0);
  context = new Context();
  context.setContextPath("/foo");
  server.setHandler(context);
  context.addFilter(new FilterHolder(TestFilter.class), "/*", 0);
  context.addServlet(new ServletHolder(TestServlet.class), "/bar");
  host = "localhost";
  port = getLocalPort();
  server.getConnectors()[0].setHost(host);
  server.getConnectors()[0].setPort(port);
  server.start();
  System.out.println("Running embedded servlet container at: http://" + host + ":" + port);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:15,代码来源:AuthenticatorTestCase.java

示例8: startJetty

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
protected void startJetty() throws Exception {
    server = new Server(0);
    context = new Context();
    context.setContextPath("/foo");
    server.setHandler(context);
    context.addFilter(new FilterHolder(TestFilter.class), "/*", 0);
    context.addServlet(new ServletHolder(TestServlet.class), "/bar");
    host = "localhost";
    port = getLocalPort();
    server.getConnectors()[0].setHost(host);
    server.getConnectors()[0].setPort(port);
    server.start();
    System.out.println("Running embedded servlet container at: http://" + host + ":" + port);
}
 
开发者ID:hortonworks,项目名称:registry,代码行数:15,代码来源:AuthenticatorTestCase.java

示例9: startServletContainer

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
public void startServletContainer(Configuration conf) throws Exception {
  if (server != null) {
    LOG.error("ServletContainer already running");
    return;
  }

  // Inject the conf for the test by being first to make singleton
  RESTServlet.getInstance(conf);

  // set up the Jersey servlet container for Jetty
  ServletHolder sh = new ServletHolder(ServletContainer.class);
  sh.setInitParameter(
    "com.sun.jersey.config.property.resourceConfigClass",
    ResourceConfig.class.getCanonicalName());
  sh.setInitParameter("com.sun.jersey.config.property.packages",
    "jetty");

  LOG.info("configured " + ServletContainer.class.getName());
  
  // set up Jetty and run the embedded server
  server = new Server(0);
  server.setSendServerVersion(false);
  server.setSendDateHeader(false);
    // set up context
  Context context = new Context(server, "/", Context.SESSIONS);
  context.addServlet(sh, "/*");
  context.addFilter(GzipFilter.class, "/*", 0);
    // start the server
  server.start();
    // get the port
  testServletPort = server.getConnectors()[0].getLocalPort();

  LOG.info("started " + server.getClass().getName() + " on port " + 
    testServletPort);
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:36,代码来源:HBaseRESTTestingUtility.java

示例10: MyPetStoreServer

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
public MyPetStoreServer(int portNumber) {
  this.portNumber = portNumber;
  server = new Server(portNumber);    
  Context root = new Context(server, "/", Context.SESSIONS);
  
  root.addFilter(GuiceFilter.class, "/*", 0);
  root.addServlet(DefaultServlet.class, "/");
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:9,代码来源:MyPetStoreServer.java

示例11: PetStoreServer

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
@Inject
public PetStoreServer(int portNumber) {
  server = new Server(portNumber);
  Context root = new Context(server, "/", Context.SESSIONS);
  
  root.addFilter(GuiceFilter.class, "/*", 0);
  root.addServlet(DefaultServlet.class, "/");
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:9,代码来源:PetStoreServer.java

示例12: EmbeddedWebServer

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
@VisibleForTesting EmbeddedWebServer(Server server, Context context) {
  this.server = server;

  context.addFilter(GuiceFilter.class, "/*", 0);
  context.addServlet(DefaultServlet.class, "/");
  context.addEventListener(new GuiceServletConfig());
  context.addEventListener(new ServiceRegistryServletContextListener());
}
 
开发者ID:signal,项目名称:agathon,代码行数:9,代码来源:EmbeddedWebServer.java

示例13: testDelegationTokenAuthenticatedURLWithNoDT

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
private void testDelegationTokenAuthenticatedURLWithNoDT(
    Class<? extends Filter> filterClass)  throws Exception {
  final Server jetty = createJettyServer();
  Context context = new Context();
  context.setContextPath("/foo");
  jetty.setHandler(context);
  context.addFilter(new FilterHolder(filterClass), "/*", 0);
  context.addServlet(new ServletHolder(UserServlet.class), "/bar");

  try {
    jetty.start();
    final URL url = new URL(getJettyURL() + "/foo/bar");

    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(FOO_USER);
    ugi.doAs(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        DelegationTokenAuthenticatedURL.Token token =
            new DelegationTokenAuthenticatedURL.Token();
        DelegationTokenAuthenticatedURL aUrl =
            new DelegationTokenAuthenticatedURL();
        HttpURLConnection conn = aUrl.openConnection(url, token);
        Assert.assertEquals(HttpURLConnection.HTTP_OK,
            conn.getResponseCode());
        List<String> ret = IOUtils.readLines(conn.getInputStream());
        Assert.assertEquals(1, ret.size());
        Assert.assertEquals(FOO_USER, ret.get(0));

        try {
          aUrl.getDelegationToken(url, token, FOO_USER);
          Assert.fail();
        } catch (AuthenticationException ex) {
          Assert.assertTrue(ex.getMessage().contains(
              "delegation token operation"));
        }
        return null;
      }
    });
  } finally {
    jetty.stop();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:43,代码来源:TestWebDelegationToken.java

示例14: testHttpUGI

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
@Test
public void testHttpUGI() throws Exception {
  final Server jetty = createJettyServer();
  Context context = new Context();
  context.setContextPath("/foo");
  jetty.setHandler(context);
  context.addFilter(new FilterHolder(PseudoDTAFilter.class), "/*", 0);
  context.addServlet(new ServletHolder(UGIServlet.class), "/bar");

  try {
    jetty.start();
    final URL url = new URL(getJettyURL() + "/foo/bar");

    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(FOO_USER);
    ugi.doAs(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        DelegationTokenAuthenticatedURL.Token token =
            new DelegationTokenAuthenticatedURL.Token();
        DelegationTokenAuthenticatedURL aUrl =
            new DelegationTokenAuthenticatedURL();

        // user foo
        HttpURLConnection conn = aUrl.openConnection(url, token);
        Assert.assertEquals(HttpURLConnection.HTTP_OK,
            conn.getResponseCode());
        List<String> ret = IOUtils.readLines(conn.getInputStream());
        Assert.assertEquals(1, ret.size());
        Assert.assertEquals("remoteuser=" + FOO_USER+ ":ugi=" + FOO_USER, 
            ret.get(0));

        // user ok-user via proxyuser foo
        conn = aUrl.openConnection(url, token, OK_USER);
        Assert.assertEquals(HttpURLConnection.HTTP_OK,
            conn.getResponseCode());
        ret = IOUtils.readLines(conn.getInputStream());
        Assert.assertEquals(1, ret.size());
        Assert.assertEquals("realugi=" + FOO_USER +":remoteuser=" + OK_USER + 
                ":ugi=" + OK_USER, ret.get(0));

        return null;
      }
    });
  } finally {
    jetty.stop();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:48,代码来源:TestWebDelegationToken.java

示例15: startServletContainer

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
public void startServletContainer(Configuration conf) throws Exception {
  if (server != null) {
    LOG.error("ServletContainer already running");
    return;
  }

  // Inject the conf for the test by being first to make singleton
  RESTServlet.getInstance(conf, User.getCurrent().getUGI());

  // set up the Jersey servlet container for Jetty
  ServletHolder sh = new ServletHolder(ServletContainer.class);
  sh.setInitParameter(
    "com.sun.jersey.config.property.resourceConfigClass",
    ResourceConfig.class.getCanonicalName());
  sh.setInitParameter("com.sun.jersey.config.property.packages",
    "jetty");

  LOG.info("configured " + ServletContainer.class.getName());
  
  // set up Jetty and run the embedded server
  server = new Server(0);
  server.setSendServerVersion(false);
  server.setSendDateHeader(false);
    // set up context
  Context context = new Context(server, "/", Context.SESSIONS);
  context.addServlet(sh, "/*");
  // Load filters specified from configuration.
  String[] filterClasses = conf.getStrings(Constants.FILTER_CLASSES,
    ArrayUtils.EMPTY_STRING_ARRAY);
  for (String filter : filterClasses) {
    filter = filter.trim();
    context.addFilter(Class.forName(filter), "/*", 0);
  }
  HttpServerUtil.constrainHttpMethods(context);
  LOG.info("Loaded filter classes :" + filterClasses);
    // start the server
  server.start();
    // get the port
  testServletPort = server.getConnectors()[0].getLocalPort();

  LOG.info("started " + server.getClass().getName() + " on port " + 
    testServletPort);
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:44,代码来源:HBaseRESTTestingUtility.java


注:本文中的org.mortbay.jetty.servlet.Context.addFilter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。