當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。