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