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


Java Server类代码示例

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


Server类属于org.mortbay.jetty包,在下文中一共展示了Server类的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: testJetty

import org.mortbay.jetty.Server; //导入依赖的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:naver,项目名称:hadoop,代码行数:17,代码来源:TestHTestCase.java

示例5: createJettyServer

import org.mortbay.jetty.Server; //导入依赖的package包/类
private Server createJettyServer() {
  try {
    InetAddress localhost = InetAddress.getByName("localhost");
    String host = "localhost";
    ServerSocket ss = new ServerSocket(0, 50, localhost);
    int port = ss.getLocalPort();
    ss.close();
    Server server = new Server(0);
    if (!ssl) {
      server.getConnectors()[0].setHost(host);
      server.getConnectors()[0].setPort(port);
    } else {
      SslSocketConnector c = new SslSocketConnectorSecure();
      c.setHost(host);
      c.setPort(port);
      c.setNeedClientAuth(false);
      c.setKeystore(keyStore);
      c.setKeystoreType(keyStoreType);
      c.setKeyPassword(keyStorePassword);
      server.setConnectors(new Connector[] {c});
    }
    return server;
  } catch (Exception ex) {
    throw new RuntimeException("Could not stop embedded servlet container, " + ex.getMessage(), ex);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:27,代码来源:TestJettyHelper.java

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

示例7: createJettyServer

import org.mortbay.jetty.Server; //导入依赖的package包/类
private Server createJettyServer() {
  try {
    InetAddress localhost = InetAddress.getByName("localhost");
    String host = "localhost";
    ServerSocket ss = new ServerSocket(0, 50, localhost);
    int port = ss.getLocalPort();
    ss.close();
    Server server = new Server(0);
    if (!ssl) {
      server.getConnectors()[0].setHost(host);
      server.getConnectors()[0].setPort(port);
    } else {
      SslSocketConnector c = new SslSocketConnectorSecure();
      c.setHost(host);
      c.setPort(port);
      c.setNeedClientAuth(false);
      c.setKeystore(keyStore);
      c.setKeystoreType(keyStoreType);
      c.setKeyPassword(keyStorePassword);
      server.setConnectors(new Connector[] {c});
    }
    return server;
  } catch (Exception ex) {
    throw new RuntimeException("Could not start embedded servlet container, " + ex.getMessage(), ex);
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:27,代码来源:TestJettyHelper.java

示例8: createJettyServer

import org.mortbay.jetty.Server; //导入依赖的package包/类
private static Server createJettyServer(String keyStore, String password, int inPort) {
  try {
    boolean ssl = keyStore != null;
    String host = "localhost";
    Server server = new Server(inPort);
    if (!ssl) {
      server.getConnectors()[0].setHost(host);
    } else {
      SslSocketConnector c = new SslSocketConnectorSecure();
      c.setHost(host);
      c.setNeedClientAuth(false);
      c.setKeystore(keyStore);
      c.setKeystoreType("jks");
      c.setKeyPassword(password);
      server.setConnectors(new Connector[]{c});
    }
    return server;
  } catch (Exception ex) {
    throw new RuntimeException("Could not start embedded servlet container, "
        + ex.getMessage(), ex);
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:23,代码来源:MiniKMS.java

示例9: start

import org.mortbay.jetty.Server; //导入依赖的package包/类
/**
 * Starts the server, which will listen to the given path going forward.
 * @throws Exception
 */
public void start() throws Exception {
  logger.info("Starting API server on {}:{}{}", HOST, port, contextPath);
  
  server = new Server();
  server.addListener(String.format("%s:%d", HOST, port));
  
  ServletHttpContext context = (ServletHttpContext) server.getContext(contextPath);
  
  context.addServlet(SERVLET_NAME, SERVLET_PATH, ServletContainer.class.getName());
  context.getServletHandler().getServletHolder(SERVLET_NAME)
      .setInitParameter(INIT_PARAM_PACKAGES, getClass().getPackage().getName());
  
  if (!Strings.isNullOrEmpty(adsPropertiesPath)) {
    context.getServletHandler().getServletHolder(SERVLET_NAME)
        .setInitParameter(INIT_PARAM_ADS_PROPERTIES, adsPropertiesPath);
  }
  if (!Strings.isNullOrEmpty(propertiesPath)) {
    context.getServletHandler().getServletHolder(SERVLET_NAME)
        .setInitParameter(INIT_PARAM_PROPERTIES, propertiesPath);
  }
  
  server.start();
}
 
开发者ID:googleads,项目名称:keyword-optimizer,代码行数:28,代码来源:ApiServer.java

示例10: setUp

import org.mortbay.jetty.Server; //导入依赖的package包/类
@Before
public void setUp() throws Exception {

  ContextHandler context = new ContextHandler();
  context.setContextPath("/");
  context.setResourceBase(RES_DIR);
  ServletHandler sh = new ServletHandler();
  sh.addServletWithMapping("org.apache.jasper.servlet.JspServlet", "*.jsp");
  context.addHandler(sh);
  context.addHandler(new SessionHandler());

  server = new Server();
  server.addHandler(context);

  conf = new Configuration();
  conf.addResource("nutch-default.xml");
  conf.addResource("nutch-site-test.xml");

  http = new Http();
  http.setConf(conf);
}
 
开发者ID:jorcox,项目名称:GeoCrawler,代码行数:22,代码来源:TestProtocolHttpClient.java

示例11: setupPspMithraService

import org.mortbay.jetty.Server; //导入依赖的package包/类
protected void setupPspMithraService()
    {
        server = new Server(this.getApplicationPort1());
        Context context = new Context (server,"/",Context.SESSIONS);
        ServletHolder holder = context.addServlet(PspServlet.class, "/PspServlet");
        holder.setInitParameter("serviceInterface.MasterCacheService", "com.gs.fw.common.mithra.cache.offheap.MasterCacheService");
        holder.setInitParameter("serviceClass.MasterCacheService", "com.gs.fw.common.mithra.cache.offheap.MasterCacheServiceImpl");
        holder.setInitOrder(10);
//        System.out.println(holder.getServlet().getClass().getName());

        try
        {
            server.start();
        }
        catch (Exception e)
        {
            throw new RuntimeException("could not start server", e);
        }
        finally
        {
        }
    }
 
开发者ID:goldmansachs,项目名称:reladomo,代码行数:23,代码来源:CacheReplicationTestCase.java

示例12: setupServerWithHandler

import org.mortbay.jetty.Server; //导入依赖的package包/类
protected void setupServerWithHandler(
        Handler handler) throws Exception
{
    this.port = (int) (Math.random() * 10000.0 + 10000.0);
    this.pspUrl = "http://localhost:" + this.port + "/PspServlet";
    this.server = new Server(this.port);
    Context context = new Context(server, "/", Context.SESSIONS);
    if (handler != null)
    {
        context.addHandler(handler);
    }
    ServletHolder holder = context.addServlet(PspServlet.class, "/PspServlet");
    holder.setInitParameter("serviceInterface.Echo", "com.gs.fw.common.mithra.test.tinyproxy.Echo");
    holder.setInitParameter("serviceClass.Echo", "com.gs.fw.common.mithra.test.tinyproxy.EchoImpl");
    holder.setInitOrder(10);

    this.server.start();
    this.servlet = (PspServlet) holder.getServlet();
}
 
开发者ID:goldmansachs,项目名称:reladomo,代码行数:20,代码来源:PspTestCase.java

示例13: setupPspMithraService

import org.mortbay.jetty.Server; //导入依赖的package包/类
protected void setupPspMithraService()
{
    server = new Server(this.getApplicationPort1());
    Context context = new Context (server,"/",Context.SESSIONS);
    ServletHolder holder = context.addServlet(PspServlet.class, "/PspServlet");
    holder.setInitParameter("serviceInterface.RemoteMithraService", "com.gs.fw.common.mithra.remote.RemoteMithraService");
    holder.setInitParameter("serviceClass.RemoteMithraService", "com.gs.fw.common.mithra.remote.RemoteMithraServiceImpl");
    holder.setInitOrder(10);

    try
    {
        server.start();
    }
    catch (Exception e)
    {
        throw new RuntimeException("could not start server", e);
    }
    finally
    {
    }
}
 
开发者ID:goldmansachs,项目名称:reladomo,代码行数:22,代码来源:RemoteMithraServerTestCase.java

示例14: setup

import org.mortbay.jetty.Server; //导入依赖的package包/类
@BeforeClass
public static void setup() throws Exception {
  try {
    JobCallbackRequestMaker.initialize(new Props());
    jobCBMaker = JobCallbackRequestMaker.getInstance();

    contextInfo = new HashMap<String, String>();
    contextInfo.put(CONTEXT_SERVER_TOKEN, SERVER_NAME);
    contextInfo.put(CONTEXT_PROJECT_TOKEN, PROJECT_NANE);
    contextInfo.put(CONTEXT_FLOW_TOKEN, FLOW_NANE);
    contextInfo.put(CONTEXT_EXECUTION_ID_TOKEN, EXECUTION_ID);
    contextInfo.put(CONTEXT_JOB_TOKEN, JOB_NANE);
    contextInfo.put(CONTEXT_JOB_STATUS_TOKEN, JobCallbackStatusEnum.STARTED.name());

    embeddedJettyServer = new Server(PORT_NUMBER);

    Context context = new Context(embeddedJettyServer, "/", Context.SESSIONS);
    context.addServlet(new ServletHolder(new DelayServlet()), "/delay");

    System.out.println("Start server");
    embeddedJettyServer.start();
  } catch (Exception e) {
    e.printStackTrace();
    throw e;
  }
}
 
开发者ID:JasonBian,项目名称:azkaban,代码行数:27,代码来源:JobCallbackRequestMakerTest.java

示例15: getRedirectUri

import org.mortbay.jetty.Server; //导入依赖的package包/类
@Override
public String getRedirectUri() throws IOException {
  if (port == -1) {
    port = getUnusedPort();
  }
  server = new Server(port);
  for (Connector c : server.getConnectors()) {
    c.setHost(host);
  }
  server.addHandler(new CallbackHandler());
  try {
    server.start();
  } catch (Exception e) {
    Throwables.propagateIfPossible(e);
    throw new IOException(e);
  }
  return "http://" + host + ":" + port + CALLBACK_PATH;
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:19,代码来源:LocalServerReceiver.java


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