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


Java Server类代码示例

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


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

示例1: JettyAdminServer

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

    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setHost(address);
    connector.setPort(port);
    connector.setIdleTimeout(idleTimeout);
    server.addConnector(connector);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/*");
    server.setHandler(context);

    context.addServlet(new ServletHolder(new CommandServlet()), commandUrl + "/*");
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:20,代码来源:JettyAdminServer.java

示例2: main

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

        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setResourceBase(PUBLIC_HTML);

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

        //page reloaded by the timer
        context.addServlet(TimerServlet.class, "/timer");
        //part of a page reloaded by the timer
        context.addServlet(AjaxTimerServlet.class, "/server-time");
        //long-polling waits till a message
        context.addServlet(new ServletHolder(new MessengerServlet()), "/messenger");
        //web chat
        context.addServlet(WebSocketChatServlet.class, "/chat");

        Server server = new Server(PORT);
        server.setHandler(new HandlerList(resourceHandler, context));

        server.start();
        server.join();
    }
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_06,代码行数:23,代码来源:Main.java

示例3: main

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

        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setResourceBase(PUBLIC_HTML);

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

        context.addServlet(new ServletHolder(new LoginServlet("anonymous")), "/login");
        context.addServlet(AdminServlet.class, "/admin");
        context.addServlet(TimerServlet.class, "/timer");

        Server server = new Server(PORT);
        server.setHandler(new HandlerList(resourceHandler, context));

        server.start();
        server.join();
    }
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_04,代码行数:18,代码来源:Main.java

示例4: main

import org.eclipse.jetty.server.Server; //导入依赖的package包/类
public static void main(String[] args) {
    int port = Configuration.INSTANCE.getInt("port", 8080);
    Server server = new Server(port);
    ServletContextHandler contextHandler
            = new ServletContextHandler(ServletContextHandler.SESSIONS);
    contextHandler.setContextPath("/");
    ServletHolder sh = new ServletHolder(new VaadinServlet());
    contextHandler.addServlet(sh, "/*");
    contextHandler.setInitParameter("ui", CrawlerAdminUI.class.getCanonicalName());
    contextHandler.setInitParameter("productionMode", String.valueOf(PRODUCTION_MODE));
    server.setHandler(contextHandler);
    try {
        server.start();
        server.join();
    } catch (Exception e) {
        LOG.error("Failed to start application", e);
    }
}
 
开发者ID:tokenmill,项目名称:crawling-framework,代码行数:19,代码来源:Application.java

示例5: reverseProxy

import org.eclipse.jetty.server.Server; //导入依赖的package包/类
private static void reverseProxy() throws Exception{
  Server server = new Server();

  SocketConnector connector = new SocketConnector();
  connector.setHost("127.0.0.1");
  connector.setPort(8888);

  server.setConnectors(new Connector[]{connector});

  // Setup proxy handler to handle CONNECT methods
  ConnectHandler proxy = new ConnectHandler();
  server.setHandler(proxy);

  // Setup proxy servlet
  ServletContextHandler context = new ServletContextHandler(proxy, "/", ServletContextHandler.SESSIONS);
  ServletHolder proxyServlet = new ServletHolder(ProxyServlet.Transparent.class);
  proxyServlet.setInitParameter("ProxyTo", "https://localhost:54321/");
  proxyServlet.setInitParameter("Prefix", "/");
  context.addServlet(proxyServlet, "/*");

  server.start();
}
 
开发者ID:tomkraljevic,项目名称:jetty-embed-reverse-proxy-example,代码行数:23,代码来源:ProxyServer.java

示例6: init

import org.eclipse.jetty.server.Server; //导入依赖的package包/类
public @NotNull CollectorServer init(@NotNull InetSocketAddress address, @NotNull ExpositionFormat format) {
  try {
    Log.setLog(new Slf4jLog());

    final Server serverInstance = new Server(address);
    format.handler(serverInstance);
    serverInstance.start();

    server = serverInstance;

    Logger.instance.info("Prometheus server with JMX metrics started at " + address);
  } catch (Exception e) {
    Logger.instance.error("Failed to start server at " + address, e);
  }
  return this;
}
 
开发者ID:nolequen,项目名称:jmx-prometheus-exporter,代码行数:17,代码来源:CollectorServer.java

示例7: start

import org.eclipse.jetty.server.Server; //导入依赖的package包/类
private void start() throws Exception {
    resourcesExample();

    ResourceHandler resourceHandler = new ResourceHandler();
    Resource resource = Resource.newClassPathResource(PUBLIC_HTML);
    resourceHandler.setBaseResource(resource);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

    context.addServlet(new ServletHolder(new TimerServlet()), "/timer");

    Server server = new Server(PORT);
    server.setHandler(new HandlerList(resourceHandler, context));

    server.start();
    server.join();
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_06,代码行数:18,代码来源:Main.java

示例8: main

import org.eclipse.jetty.server.Server; //导入依赖的package包/类
public static void main(String[] args) {  
try {  
    MergedLogSource src = new MergedLogSource(args);
    System.out.println(src);

    Server server = new Server(8182);
    server.setHandler(new LogServer(src));
    
    server.start();
    server.join();

} catch (Exception e) {  
    // Something is wrong.  
    e.printStackTrace();  
}  
   }
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:17,代码来源:LogServer.java

示例9: addWebApplication

import org.eclipse.jetty.server.Server; //导入依赖的package包/类
public static Server addWebApplication(final Server jetty, final String webAppContext,
    final String warFilePath) {
  WebAppContext webapp = new WebAppContext();
  webapp.setContextPath(webAppContext);
  webapp.setWar(warFilePath);
  webapp.setParentLoaderPriority(false);
  webapp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");

  File tmpPath = new File(getWebAppBaseDirectory(webAppContext));
  tmpPath.mkdirs();
  webapp.setTempDirectory(tmpPath);

  ((HandlerCollection) jetty.getHandler()).addHandler(webapp);

  return jetty;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:17,代码来源:JettyHelper.java

示例10: configureSpnego

import org.eclipse.jetty.server.Server; //导入依赖的package包/类
/**
 * Configures the <code>connector</code> given the <code>config</code> for using SPNEGO.
 *
 * @param connector The connector to configure
 * @param config The configuration
 */
protected ConstraintSecurityHandler configureSpnego(Server server, ServerConnector connector,
    AvaticaServerConfiguration config) {
  final String realm = Objects.requireNonNull(config.getKerberosRealm());
  final String principal = Objects.requireNonNull(config.getKerberosPrincipal());

  // A customization of SpnegoLoginService to explicitly set the server's principal, otherwise
  // we would have to require a custom file to set the server's principal.
  PropertyBasedSpnegoLoginService spnegoLoginService =
      new PropertyBasedSpnegoLoginService(realm, principal);

  // Roles are "realms" for Kerberos/SPNEGO
  final String[] allowedRealms = getAllowedRealms(realm, config);

  return configureCommonAuthentication(server, connector, config, Constraint.__SPNEGO_AUTH,
      allowedRealms, new AvaticaSpnegoAuthenticator(), realm, spnegoLoginService);
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:23,代码来源:HttpServer.java

示例11: isRunning

import org.eclipse.jetty.server.Server; //导入依赖的package包/类
@Override
public boolean isRunning(final int port) {

	if (!isValidPort(port)) {
		return false;
	}

	final Server server = serverCache.getIfPresent(port);
	if (null == server) {
		return false;
	}
	if (!server.isStarted()) {
		return false;
	}

	return isPortInUse(port);
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:18,代码来源:JettyManager.java

示例12: startServer

import org.eclipse.jetty.server.Server; //导入依赖的package包/类
/**
 * startUAVServer
 */
public void startServer(Object... args) {

    Server server = (Server) args[0];

    // integrate Tomcat log
    UAVServer.instance().setLog(new JettyLog("MonitorServer"));
    // start Monitor Server when server starts
    UAVServer.instance().start(new Object[] { UAVServer.ServerVendor.JETTY });

    // get server port
    if (UAVServer.instance().getServerInfo(CaptureConstants.INFO_APPSERVER_LISTEN_PORT) == null) {
        // set port
        ServerConnector sc = (ServerConnector) server.getConnectors()[0];

        String protocol = sc.getDefaultProtocol();
        if (protocol.toLowerCase().indexOf("http") >= 0) {
            UAVServer.instance().putServerInfo(CaptureConstants.INFO_APPSERVER_LISTEN_PORT, sc.getPort());
        }
    }

}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:25,代码来源:JettyPlusIT.java

示例13: main

import org.eclipse.jetty.server.Server; //导入依赖的package包/类
public static void main(final String... args) throws Exception {
  if (args.length > 1) {
    System.out.printf("Temporary Directory @ ($1%s)%n", USER_DIR);

    final Server jetty = JettyHelper.initJetty(null, 8090, new SSLConfig());

    for (int index = 0; index < args.length; index += 2) {
      final String webAppContext = args[index];
      final String webAppArchivePath = args[index + 1];

      JettyHelper.addWebApplication(jetty, normalizeWebAppContext(webAppContext),
          normalizeWebAppArchivePath(webAppArchivePath));
    }

    JettyHelper.startJetty(jetty);
    latch.await();
  } else {
    System.out.printf(
        "usage:%n>java org.apache.geode.management.internal.TomcatHelper <web-app-context> <war-file-path> [<web-app-context> <war-file-path>]*");
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:22,代码来源:JettyHelper.java

示例14: createDevServer

import org.eclipse.jetty.server.Server; //导入依赖的package包/类
public static Server createDevServer(int port, String contextPath) {

        Server server = new Server();
        server.setStopAtShutdown(true);

        ServerConnector connector = new ServerConnector(server);
        // 设置服务端口
        connector.setPort(port);
        connector.setReuseAddress(false);
        server.setConnectors(new Connector[] {connector});

        // 设置web资源根路径以及访问web的根路径
        WebAppContext webAppCtx = new WebAppContext(DEFAULT_APP_CONTEXT_PATH, contextPath);
        webAppCtx.setDescriptor(DEFAULT_APP_CONTEXT_PATH + "/WEB-INF/web.xml");
        webAppCtx.setResourceBase(DEFAULT_APP_CONTEXT_PATH);
        webAppCtx.setClassLoader(Thread.currentThread().getContextClassLoader());
        server.setHandler(webAppCtx);

        return server;
    }
 
开发者ID:quqiangsheng,项目名称:abhot,代码行数:21,代码来源:Launcher.java

示例15: start

import org.eclipse.jetty.server.Server; //导入依赖的package包/类
public void start() {
    // TODO: remove redundant fields from config and move this check to XRE Redirector
    if (! config.getEnableCommunicationEndpoint()) {
        log.warn("skipping Jetty endpoint due to configuration");
        return;
    }

    if (started) {
        log.warn("Jetty is already started");
    }

    started = true;
    Integer port = config.getCommunicationEndpointPort();

    log.info("Starting embedded jetty server (XRERedirector Gateway) on port: {}", port);

    WebAppContext webAppContext = new WebAppContext();
    webAppContext.setConfigurations(new Configuration[]{new AnnotationConfiguration() {
        @Override
        public void preConfigure(WebAppContext context) {
            ClassInheritanceMap map = new ClassInheritanceMap();
            map.put(WebApplicationInitializer.class.getName(), new ConcurrentHashSet<String>() {{
                add(WebAppInitializer.class.getName());
            }});
            context.setAttribute(CLASS_INHERITANCE_MAP, map);
            _classInheritanceHandler = new ClassInheritanceHandler(map);
        }
    }});

    server = new Server(port);
    server.setHandler(webAppContext);

    try {
        server.start();
    } catch (Exception e) {
        log.error("Failed to start embedded jetty server (XRERedirector communication endpoint) on port: " + port, e);
    }

    log.info("Started embedded jetty server (Redirector Gateway) on port: {}", port);
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:41,代码来源:EmbeddedJetty.java


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