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


Java Server.setHandler方法代码示例

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


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

示例1: startServer

import org.mortbay.jetty.Server; //导入方法依赖的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.Server; //导入方法依赖的package包/类
@Override
public void start() {
  jettyServer = new Server();
  //We can use Contexts etc if we have many urls to handle. For one url,
  //specifying a handler directly is the most efficient.
  SelectChannelConnector connector = new SelectChannelConnector();
  connector.setReuseAddress(true);
  connector.setPort(port);
  jettyServer.setConnectors(new Connector[] {connector});
  jettyServer.setHandler(new HTTPMetricsHandler());
  try {
    jettyServer.start();
    while (!jettyServer.isStarted()) {
      Thread.sleep(500);
    }
  } catch (Exception ex) {
    LOG.error("Error starting Jetty. JSON Metrics may not be available.", ex);
  }

}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:21,代码来源:HTTPMetricsServer.java

示例3: start

import org.mortbay.jetty.Server; //导入方法依赖的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

示例4: start

import org.mortbay.jetty.Server; //导入方法依赖的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

示例5: main

import org.mortbay.jetty.Server; //导入方法依赖的package包/类
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8081 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/reporting" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );

    server.start();
    server.join();
}
 
开发者ID:DistX,项目名称:Learning,代码行数:18,代码来源:EmbeddedServer.java

示例6: main

import org.mortbay.jetty.Server; //导入方法依赖的package包/类
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/xdocreport-webapp" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );

    // JSP Servlet + Context
    Context jsp_ctx = new Context( servlet_contexts, "/jsp", Context.SESSIONS );
    jsp_ctx.addServlet( new ServletHolder( new org.apache.jasper.servlet.JspServlet() ), "*.jsp" );

    server.start();
    server.join();
}
 
开发者ID:DistX,项目名称:Learning,代码行数:22,代码来源:EmbeddedServer.java

示例7: testExternalDelegationTokenSecretManager

import org.mortbay.jetty.Server; //导入方法依赖的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

示例8: testFallbackToPseudoDelegationTokenAuthenticator

import org.mortbay.jetty.Server; //导入方法依赖的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

示例9: testIpaddressCheck

import org.mortbay.jetty.Server; //导入方法依赖的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

示例10: startJetty

import org.mortbay.jetty.Server; //导入方法依赖的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

示例11: JettyAdminServer

import org.mortbay.jetty.Server; //导入方法依赖的package包/类
public JettyAdminServer(String address, int port, String commandUrl) {
    this.port = port;
    this.commandUrl = commandUrl;
    this.address = address;

    server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setHost(address);
    connector.setPort(port);
    server.addConnector(connector);
    Context context = new Context(server, "/");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new CommandServlet()), commandUrl
            + "/*");
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:16,代码来源:JettyAdminServer.java

示例12: main

import org.mortbay.jetty.Server; //导入方法依赖的package包/类
public static void main(String[] args) {
    try {
        String confPath = args[0];

        confPath = confPath.trim();

        Properties conf = new Properties();
        InputStream is = new FileInputStream(new File(confPath + "/conf/lts-admin.cfg"));
        conf.load(is);
        String port = conf.getProperty("port");
        if (port == null || port.trim().equals("")) {
            port = "8081";
        }

        Server server = new Server(Integer.parseInt(port));
        WebAppContext webapp = new WebAppContext();
        webapp.setWar(confPath + "/lts-admin.war");
        Map<String, String> initParams = new HashMap<String, String>();
        initParams.put("lts.admin.config.path", confPath + "/conf");
        webapp.setInitParams(initParams);
        server.setHandler(webapp);
        server.setStopAtShutdown(true);
        server.start();

        System.out.println("LTS-Admin started. http://" + NetUtils.getLocalHost() + ":" + port + "/index.htm");

    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
 
开发者ID:WenZuHuai,项目名称:light-task-scheduler,代码行数:32,代码来源:JettyContainer.java

示例13: main

import org.mortbay.jetty.Server; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception
{
    String jetty_home=System.getProperty("jetty.home","../../..");

    String jetty_port=System.getProperty("jetty.port", "8080");

    String node_name=System.getProperty("node.name", "red");

    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(Integer.parseInt(jetty_port));
    server.setConnectors(new Connector[]{connector});
    
    HandlerCollection handlers = new HandlerCollection();
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    
    //TODO: find a way to dynamically get the endpoint url
    WadiCluster wadiCluster = new WadiCluster("CLUSTER", node_name, "http://localhost:"+jetty_port+"/test");
    wadiCluster.doStart();
    
    WadiSessionManager wadiManager = new WadiSessionManager(wadiCluster, 2, 24, 360);
    
    WadiSessionHandler wSessionHandler = new WadiSessionHandler(wadiManager);
    WebAppContext wah = new WebAppContext(null, wSessionHandler, null, null);
    wah.setContextPath("/test");
    wah.setResourceBase(jetty_home+"/webapps/test");
    
    contexts.setHandlers(new Handler[]{wah});
    handlers.setHandlers(new Handler[]{contexts,new DefaultHandler()});
    server.setHandler(handlers);

    HashUserRealm hur = new HashUserRealm();
    hur.setName("Test Realm");
    hur.setConfig(jetty_home+"/etc/realm.properties");
    wah.getSecurityHandler().setUserRealm(hur);
    
    server.start();
    server.join();
}
 
开发者ID:iMartinezMateu,项目名称:openbravo-pos,代码行数:40,代码来源:WadiSessionHandler.java

示例14: main

import org.mortbay.jetty.Server; //导入方法依赖的package包/类
/** temp main - just to help testing */
public static void main(String[] args)
throws Exception
{
    Server server = new Server();
    Connector connector=new GrizzlyConnector();
    connector.setPort(8080);
    server.setConnectors(new Connector[]{connector});
    
    HandlerCollection handlers = new HandlerCollection();
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    handlers.setHandlers(new Handler[]{contexts,new DefaultHandler()});
    server.setHandler(handlers);
    
    // TODO add javadoc context to contexts
    
    WebAppContext.addWebApplications(server, "../../webapps", "org/mortbay/jetty/webapp/webdefault.xml", true, false);
    
    HashUserRealm userRealm = new HashUserRealm();
    userRealm.setName("Test Realm");
    userRealm.setConfig("../../etc/realm.properties");
    server.setUserRealms(new UserRealm[]{userRealm});
    
    
    server.start();
    server.join();
    
}
 
开发者ID:iMartinezMateu,项目名称:openbravo-pos,代码行数:29,代码来源:GrizzlyConnector.java

示例15: testDelegationTokenAuthenticatedURLWithNoDT

import org.mortbay.jetty.Server; //导入方法依赖的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


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