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


Java Context.setContextPath方法代码示例

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


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

示例1: testJetty

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
@Test
@TestJetty
public void testJetty() throws Exception {
  Context context = new Context();
  context.setContextPath("/");
  context.addServlet(MyServlet.class, "/bar");
  Server server = TestJettyHelper.getJettyServer();
  server.addHandler(context);
  server.start();
  URL url = new URL(TestJettyHelper.getJettyURL(), "/bar");
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
  BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  assertEquals(reader.readLine(), "foo");
  reader.close();
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:17,代码来源:TestHFSTestCase.java

示例2: start

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
/**
 * Simple http server. Server should send answer with status 200
 */
@BeforeClass
public static void start() throws Exception {
  server = new Server(0);
  Context context = new Context();
  context.setContextPath("/foo");
  server.setHandler(context);
  context.addServlet(new ServletHolder(TestServlet.class), "/bar");
  server.getConnectors()[0].setHost("localhost");
  server.start();
  originalPort = server.getConnectors()[0].getLocalPort();
  LOG.info("Running embedded servlet container at: http://localhost:"
      + originalPort);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:TestWebAppProxyServlet.java

示例3: start

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
/**
 * Simple http server. Server should send answer with status 200
 */
@BeforeClass
public static void start() throws Exception {
  server = new Server(0);
  Context context = new Context();
  context.setContextPath("/foo");
  server.setHandler(context);
  context.addServlet(new ServletHolder(TestServlet.class), "/bar");
  server.getConnectors()[0].setHost("localhost");
  server.start();
  originalPort = server.getConnectors()[0].getLocalPort();
  LOG.info("Running embedded servlet container at: http://localhost:"
      + originalPort);
  // This property needs to be set otherwise CORS Headers will be dropped
  // by HttpUrlConnection
  System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:20,代码来源:TestWebAppProxyServlet.java

示例4: 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

示例5: testJetty

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
@Test
@TestJetty
public void testJetty() throws Exception {
  Context context = new Context();
  context.setContextPath("/");
  context.addServlet(MyServlet.class, "/bar");
  Server server = TestJettyHelper.getJettyServer();
  server.addHandler(context);
  server.start();
  URL url = new URL(TestJettyHelper.getJettyURL(), "/bar");
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
  BufferedReader reader =
      new BufferedReader(new InputStreamReader(conn.getInputStream()));
  assertEquals(reader.readLine(), "foo");
  reader.close();
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:18,代码来源:TestHTestCase.java

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: generateServletContextHandler

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
private static Handler generateServletContextHandler() throws IOException {
    ServletHandler servletHandler = new ServletHandler();

    servletHandler.addServletWithMapping(BlockingServlet.class, BLOCKING_PATH);
    servletHandler.addServletWithMapping(BlockingForwardServlet.class, BLOCKING_FORWARD_PATH);
    servletHandler.addFilterWithMapping(RequestTracingFilter.class.getName(), "/*", Handler.ALL);

    Context context = new Context(null, null, null, servletHandler, null);
    context.setContextPath("/");
    return context;
}
 
开发者ID:Nike-Inc,项目名称:wingtips,代码行数:12,代码来源:RequestTracingFilterOldServletComponentTest.java

示例11: 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

示例12: start

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
/**
 * Simple http server. Server should send answer with status 200
 */
@BeforeClass
public static void start() throws Exception {
  server = new Server(0);
  Context context = new Context();
  context.setContextPath("/foo");
  server.setHandler(context);
  context.addServlet(new ServletHolder(TestServlet.class), "/bar/");
  server.getConnectors()[0].setHost("localhost");
  server.start();
  originalPort = server.getConnectors()[0].getLocalPort();
  LOG.info("Running embedded servlet container at: http://localhost:"
      + originalPort);
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:17,代码来源:TestWebAppProxyServlet.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: setupHTTPServer

import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
private void setupHTTPServer() throws IOException {
  TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
  TProcessor processor = new Hbase.Processor<Hbase.Iface>(handler);
  TServlet thriftHttpServlet = new ThriftHttpServlet(processor, protocolFactory, realUser,
      conf, hbaseHandler, securityEnabled, doAsEnabled);

  httpServer = new Server();
  // Context handler
  Context context = new Context(httpServer, "/", Context.SESSIONS);
  context.setContextPath("/");
  String httpPath = "/*";
  httpServer.setHandler(context);
  context.addServlet(new ServletHolder(thriftHttpServlet), httpPath);

  // set up Jetty and run the embedded server
  Connector connector = new SelectChannelConnector();
  if(conf.getBoolean(THRIFT_SSL_ENABLED, false)) {
    SslSelectChannelConnector sslConnector = new SslSelectChannelConnector();
    String keystore = conf.get(THRIFT_SSL_KEYSTORE_STORE);
    String password = HBaseConfiguration.getPassword(conf,
        THRIFT_SSL_KEYSTORE_PASSWORD, null);
    String keyPassword = HBaseConfiguration.getPassword(conf,
        THRIFT_SSL_KEYSTORE_KEYPASSWORD, password);
    sslConnector.setKeystore(keystore);
    sslConnector.setPassword(password);
    sslConnector.setKeyPassword(keyPassword);
    connector = sslConnector;
  }
  String host = getBindAddress(conf).getHostAddress();
  connector.setPort(listenPort);
  connector.setHost(host);
  connector.setHeaderBufferSize(1024 * 64);
  httpServer.addConnector(connector);

  if (doAsEnabled) {
    ProxyUsers.refreshSuperUserGroupsConfiguration(conf);
  }

  // Set the default max thread number to 100 to limit
  // the number of concurrent requests so that Thrfit HTTP server doesn't OOM easily.
  // Jetty set the default max thread number to 250, if we don't set it.
  //
  // Our default min thread number 2 is the same as that used by Jetty.
  int minThreads = conf.getInt(HTTP_MIN_THREADS, 2);
  int maxThreads = conf.getInt(HTTP_MAX_THREADS, 100);
  QueuedThreadPool threadPool = new QueuedThreadPool(maxThreads);
  threadPool.setMinThreads(minThreads);
  httpServer.setThreadPool(threadPool);

  httpServer.setSendServerVersion(false);
  httpServer.setSendDateHeader(false);
  httpServer.setStopAtShutdown(true);

  LOG.info("Starting Thrift HTTP Server on " + Integer.toString(listenPort));
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:56,代码来源:ThriftServerRunner.java


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