Java 类org.eclipse.jetty.server.nio.SelectChannelConnector 实例源码

项目:reactive-components    文件:TestRs.java   
private Server createServer() {
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(8384);
    server.addConnector(connector);

    ServletHandler handler = new ServletHandler();
    Servlet servlet = new HttpServlet() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
            String path = req.getServletPath().substring(1);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
            resp.getWriter().append(path);
        }

    };
    handler.addServletWithMapping(new ServletHolder(servlet), "/");
    server.setHandler(handler);
    return server;
}
项目:little_mitm    文件:PerformanceServer.java   
public void run(int port) throws Exception {
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    server.addConnector(connector);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[] { "index.html" });

    resource_handler.setResourceBase("./performance/site/");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler,
            new DefaultHandler() });
    server.setHandler(handlers);

    server.start();
    System.out.println("Started performance file server at port: " + port);
    server.join();
}
项目:hazelcast-wm    文件:JettyServer.java   
public void buildJetty(int port, String sourceDir, String webXmlFile) throws Exception {
    server = new Server();

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    server.addConnector(connector);
    WebAppContext context = new WebAppContext();
    context.setResourceBase(sourceDir);
    context.setDescriptor(sourceDir + "/WEB-INF/" + webXmlFile);
    context.setLogUrlOnStart(true);
    context.setContextPath("/");
    context.setParentLoaderPriority(true);

    server.setHandler(context);

    server.start();
}
项目:g2    文件:JettyFactory.java   
/**
 * 创建用于开发运行调试的Jetty Server, 以src/main/webapp为Web应用目录.
 */
public static Server createServerInSource(int port, String contextPath) {
    Server server = new Server();
    // 设置在JVM退出时关闭Jetty的钩子。
    server.setStopAtShutdown(true);

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    // 解决Windows下重复启动Jetty居然不报告端口冲突的问题.
    connector.setReuseAddress(false);
    server.setConnectors(new Connector[] { connector });

    WebAppContext webContext = new WebAppContext(DEFAULT_WEBAPP_PATH, contextPath);
    // 修改webdefault.xml,解决Windows下Jetty Lock住静态文件的问题.
    webContext.setDefaultsDescriptor(WINDOWS_WEBDEFAULT_PATH);
    server.setHandler(webContext);

    return server;
}
项目:FinanceAnalytics    文件:EmbeddedJettyComponentFactory.java   
private Server initJettyServer(ComponentRepository repo) {
  SelectChannelConnector connector = new SelectChannelConnector();
  connector.setPort(getPort());
  connector.setConfidentialPort(getSecurePort());
  connector.setRequestHeaderSize(16384);

  Server jettyServer = new Server();
  jettyServer.setConnectors(new Connector[] {connector});

  ContextHandlerCollection contexts = new ContextHandlerCollection();
  HandlerCollection handlers = new HandlerCollection();
  handlers.addHandler(contexts);
  addHandlers(repo, jettyServer, contexts);

  jettyServer.setHandler(handlers);
  jettyServer.setStopAtShutdown(true);
  jettyServer.setGracefulShutdown(2000);
  jettyServer.setSendDateHeader(true);
  jettyServer.setSendServerVersion(true);

  ComponentInfo info = new ComponentInfo(Server.class, "jetty");
  repo.registerComponent(info, jettyServer);
  repo.registerLifecycle(new ServerLifecycle(jettyServer));
  return jettyServer;
}
项目:FinanceAnalytics    文件:RemoteViewRunnerTest.java   
@BeforeClass
public void startServer() throws Exception {
  int port = 49152 + RandomUtils.nextInt(65535 - 49152);
  String serverUrl = "http://localhost:" + port + "/jax";
  SelectChannelConnector connector = new SelectChannelConnector();
  connector.setPort(port);
  _jettyServer = new Server();
  _jettyServer.setConnectors(new Connector[]{connector});
  ContextHandlerCollection contexts = new ContextHandlerCollection();
  HandlerCollection handlers = new HandlerCollection();
  handlers.addHandler(contexts);
  WebAppContext ogWebAppContext = new WebAppContext("RemoteViewRunnerTest", "/");
  org.springframework.core.io.Resource resource = new ClassPathResource("web-engine");
  ogWebAppContext.setBaseResource(Resource.newResource(resource.getFile()));
  DataViewRunnerResource viewRunnerResource = new DataViewRunnerResource(new TestViewRunner());
  ComponentRepository repo = new ComponentRepository(ComponentLogger.Console.VERBOSE);
  repo.getRestComponents().publishResource(viewRunnerResource);
  repo.getRestComponents().publishHelper(new FudgeObjectBinaryConsumer());
  repo.getRestComponents().publishHelper(new FudgeObjectBinaryProducer());
  ogWebAppContext.setEventListeners(new EventListener[]{new ComponentRepositoryServletContextListener(repo)});
  handlers.addHandler(ogWebAppContext);
  _jettyServer.setHandler(handlers);
  _jettyServer.start();
  _remoteViewRunner = new RemoteViewRunner(URI.create(serverUrl));
}
项目:multilanguage-interface-demo    文件:JettyStart.java   
/**
 * 启动jetty
 */
private static void start() throws Exception {
  long bg = System.currentTimeMillis();
  Server server = new Server();
  Connector connector = new SelectChannelConnector();
  connector.setPort(PORT);
  server.setConnectors(new Connector[] {connector});

  WebAppContext webAppContext = new WebAppContext("src/main/webapp", "/");
  webAppContext.setDescriptor("src/main/webapp/WEB-INF/web.xml");
  webAppContext.setDisplayName("multilanguage");
  WebAppClassLoader classLoader = new WebAppClassLoader(webAppContext);
  webAppContext.setClassLoader(classLoader);
  webAppContext.setParentLoaderPriority(true);
  server.setHandler(webAppContext);
  System.out.println("ContextPath: " + webAppContext.getContextPath() + ";  Descriptor: "
      + webAppContext.getDescriptor());

  server.start();

  long time = System.currentTimeMillis() - bg;
  System.out.println("Jetty started in " + time + "ms");
}
项目:bartleby    文件:JettyFixtureBase.java   
public void start() throws Exception {
  server = new Server();
  Connector connector = new SelectChannelConnector();
  connector.setPort(port);
  server.setConnectors(new Connector[]{connector});

  RequestLogHandler requestLogHandler = new RequestLogHandler();
  configureRequestLogImpl();
  requestLogHandler.setRequestLog(requestLogImpl);

  HandlerList handlers = new HandlerList();
  handlers.addHandler(requestLogHandler);
  handlers.addHandler(getRequestHandler());

  server.setHandler(handlers);
  server.start();
}
项目:LittleProxy    文件:PerformanceServer.java   
public void run(int port) throws Exception {
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    server.addConnector(connector);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[] { "index.html" });

    resource_handler.setResourceBase("./performance/site/");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler,
            new DefaultHandler() });
    server.setHandler(handlers);

    server.start();
    System.out.println("Started performance file server at port: " + port);
    server.join();
}
项目:Visual-Programming-Environment-for-Coordinating-Appliances-and-Services-in-a-Smart-House    文件:WebSocketServer.java   
public WebSocketServer(int port, String rootDirPath, final MainWindow m, final Statement smt, final java.sql.Connection sqlcon) {
    idCounter = 0;

    connector = new SelectChannelConnector();
    connector.setPort(port);
    addConnector(connector);

    wsHandler = new WebSocketHandler() {
        @Override
        public WebSocket doWebSocketConnect(HttpServletRequest request,
                String protocol) {
            idCounter++;
            System.out.printf("Protocol:%s\n", protocol);
            return new MyWebSocket(idCounter, m, smt, sqlcon);
        }
    };

    resHandler = new ResourceHandler();
    resHandler.setDirectoriesListed(true);
    resHandler.setResourceBase(rootDirPath);

    wsHandler.setHandler(resHandler);
    setHandler(wsHandler);
}
项目:Wilma    文件:JettyServer.java   
/**
 * Configures and starts a new Jetty server instance.
 * This server is configured to answer incoming request in a dummy way.
 * @param server the server that should be started
 * @param httpPort the http server port
 * @param httpsPort the https server port
 * @param isPerfTest determines whether server is started in performance test mode or not
 * @throws Exception
 */
public void configureAndStart(final Server server, final Integer httpPort, final Integer httpsPort, final Boolean isPerfTest) {
    try {
        SelectChannelConnector httpConnector = createHttpConnector(httpPort);
        SslSelectChannelConnector sslConnector = createSslConnector(httpsPort);
        server.setConnectors(new Connector[]{httpConnector, sslConnector});
        if (isPerfTest) {
            server.setHandler(new PerformanceTestHandler());
        } else {
            server.setHandler(new CompositeHandler(new ExampleHandler(new InputStreamConverter()), new SequenceTestHandler(new InputStreamConverter()), new PerformanceTestHandler()));
        }
        startServer(server);
        server.join();
    } catch (Exception e) {
        throw new SystemException("server cannot be started", e);
    }
}
项目:daq-eclipse    文件:EmbeddedJettyServer.java   
public void start() throws Exception {
    URI uri = new URI(agent.getRegistryURL());

    server = new Server();
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);

    context.setContextPath("/");
    ServletHolder holder = new ServletHolder();
    holder.setServlet(camelServlet);
    context.addServlet(holder, "/*");
    server.setHandler(context);
    server.start();

    int port = 80;
    if( uri.getPort() >=0 ) {
        port = uri.getPort();
    }

    connector = new SelectChannelConnector();
    connector.setPort(port);
    server.addConnector(connector);
    connector.start();
}
项目:varOne    文件:VarOneServer.java   
private static Server setupJettyServer(VarOneConfiguration conf) {
    AbstractConnector connector = new SelectChannelConnector();


    // Set some timeout options to make debugging easier.
    int timeout = 1000 * 30;
    connector.setMaxIdleTime(timeout);
    connector.setSoLingerTime(-1);
    connector.setHost(conf.getServerAddress());
    connector.setPort(conf.getServerPort());

    final Server server = new Server();
    server.addConnector(connector);

    return server;
}
项目:DataCleaner    文件:HttpClusterManagerTest.java   
private Server createServer(final int port, final boolean multiThreaded) throws Exception {
    final String testName = getClass().getSimpleName() + "_" + getName();
    final DataCleanerConfiguration configuration = ClusterTestHelper.createConfiguration(testName, multiThreaded);

    final SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);

    final WebAppContext webApp = new WebAppContext();
    webApp.setAttribute(SlaveServlet.SERVLET_CONTEXT_ATTRIBUTE_CONFIGURATION, configuration);
    webApp.setContextPath("/");
    webApp.setWar("src/test/resources/jetty_webapp_folder");

    final Server server = new Server();
    server.addConnector(connector);
    server.setHandler(webApp);
    server.start();

    System.out.println("Jetty server started on port " + port);

    return server;
}
项目:AnalyzerBeans    文件:HttpClusterManagerTest.java   
private Server createServer(int port, boolean multiThreaded) throws Exception {
    final String testName = getClass().getSimpleName() + "_" + getName();
    final AnalyzerBeansConfiguration configuration = ClusterTestHelper.createConfiguration(testName, multiThreaded);

    final SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);

    final WebAppContext webApp = new WebAppContext();
    webApp.setAttribute(SlaveServlet.SERVLET_CONTEXT_ATTRIBUTE_CONFIGURATION, configuration);
    webApp.setContextPath("/");
    webApp.setWar("src/test/resources/jetty_webapp_folder");

    final Server server = new Server();
    server.addConnector(connector);
    server.setHandler(webApp);
    server.start();

    System.out.println("Jetty server started on port " + port);

    return server;
}
项目:rest4j    文件:HttpJettyServer.java   
@Override
public void start() throws IOException
{
  _server = new Server();
  SelectChannelConnector connector = new SelectChannelConnector();
  connector.setPort(_port);
  _server.setConnectors(new Connector[] { connector });
  _server.setThreadPool(new QueuedThreadPool(_threadPoolSize));
  ServletContextHandler root =
      new ServletContextHandler(_server, _contextPath, ServletContextHandler.SESSIONS);
  root.addServlet(new ServletHolder(_servlet), "/*");

  try
  {
    _server.start();
  }
  catch (Exception e)
  {
    throw new IOException("Failed to start Jetty", e);
  }
}
项目:jmms    文件:JettyFactory.java   
/**
 * 创建用于开发运行调试的Jetty Server, 以src/main/webapp为Web应用目录.
 */
public static Server createServerInSource(int port) {
    Server server = new Server();
    // 设置在JVM退出时关闭Jetty的钩子。
    server.setStopAtShutdown(true);

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    // 解决Windows下重复启动Jetty居然不报告端口冲突的问题.
    connector.setReuseAddress(false);
    server.setConnectors(new Connector[] { connector });

    WebAppContext webContext = new WebAppContext(DEFAULT_WEBAPP_PATH, CONTEXT_PATH);

    server.setHandler(webContext);

    return server;
}
项目:pom-manipulation-ext    文件:JettyHttpServer.java   
private Server createAndStartJetty( Integer port )
{
    Server jetty = new Server();
    Connector conn = new SelectChannelConnector();
    conn.setHost( "127.0.0.1" );
    conn.setPort( this.port );
    jetty.addConnector( conn );
    jetty.setHandler( handler );

    try
    {
        jetty.start();
    }
    catch ( Exception e )
    {
        throw new ServerSetupException( "Error starting jetty on port " + port, e );
    }

    return jetty;
}
项目:base-framework    文件:JettyFactory.java   
/**
 * 创建用于开发运行调试的Jetty Server, 以src/main/webapp为Web应用目录.
 */
public static Server createServerInSource(int port, String contextPath) {
    Server server = new Server();
    // 设置在JVM退出时关闭Jetty的钩子。
    server.setStopAtShutdown(true);

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    // 解决Windows下重复启动Jetty居然不报告端口冲突的问题.
    connector.setReuseAddress(false);
    server.setConnectors(new Connector[] { connector });

    WebAppContext webContext = new WebAppContext(DEFAULT_WEBAPP_PATH, contextPath);
    server.setHandler(webContext);

    return server;
}
项目:appengine    文件:JettyFactory.java   
/**
 * 创建用于开发运行调试的Jetty Server, 以src/main/webapp为Web应用目录.
 */
public static Server createServerInSource(int port, String contextPath) {
    Server server = new Server();
    //设置在JVM退出时关闭Jetty的钩子。
    server.setStopAtShutdown(true);

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    //解决Windows下重复启动Jetty居然不报告端口冲突的问题.
    connector.setReuseAddress(false);
    server.setConnectors(new Connector[] { connector });

    WebAppContext webContext = new WebAppContext(DEFAULT_WEBAPP_PATH, contextPath);
    //修改webdefault.xml,解决Windows下Jetty Lock住静态文件的问题.
    webContext.setDefaultsDescriptor(WINDOWS_WEBDEFAULT_PATH);
    server.setHandler(webContext);

    return server;
}
项目:gitblit    文件:GitBlitServer.java   
/**
 * Creates an http connector.
 * 
 * @param useNIO
 * @param port
 * @param threadPoolSize
 * @return an http connector
 */
private Connector createConnector(boolean useNIO, int port, int threadPoolSize) {
    Connector connector;
    if (useNIO) {
        logger.info("Setting up NIO SelectChannelConnector on port " + port);
        SelectChannelConnector nioconn = new SelectChannelConnector();
        nioconn.setSoLingerTime(-1);
        if (threadPoolSize > 0) {
            nioconn.setThreadPool(new QueuedThreadPool(threadPoolSize));
        }
        connector = nioconn;
    } else {
        logger.info("Setting up SocketConnector on port " + port);
        SocketConnector sockconn = new SocketConnector();
        if (threadPoolSize > 0) {
            sockconn.setThreadPool(new QueuedThreadPool(threadPoolSize));
        }
        connector = sockconn;
    }

    connector.setPort(port);
    connector.setMaxIdleTime(30000);
    return connector;
}
项目:iif-resultsrepository    文件:ServerStarter.java   
public static void startWebServer(int port) throws Exception {
    webServer = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    webServer.addConnector(connector);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    //resource_handler.setWelcomeFiles(new String[] { "index.html" });

    String serverRoot = ServerStarter.class.getResource("/").getFile();

    resource_handler.setResourceBase(serverRoot);

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler,
            new DefaultHandler() });
    webServer.setHandler(handlers);

    webServer.start();

}
项目:better-jsonrpc    文件:TestServer.java   
public TestServer() {
    mJsonMapper = new ObjectMapper();

    mServletHandler = new ServletHandler();
    mServletHandler.addServletWithMapping(TestServletWs.class, "/ws");
    mServletHandler.addServletWithMapping(TestServletHttp.class, "/http");

    mConnector = new SelectChannelConnector();
    mConnector.setThreadPool(new QueuedThreadPool(10));
    mConnector.setHost("localhost");
    mConnector.setPort(0);

    mServer = new Server();
    mServer.setThreadPool(new QueuedThreadPool(10));
    mServer.setHandler(mServletHandler);
    mServer.setConnectors(new Connector[]{mConnector});
}
项目:IRCBlit    文件:GitBlitServer.java   
/**
 * Creates an http connector.
 * 
 * @param useNIO
 * @param port
 * @return an http connector
 */
private Connector createConnector(boolean useNIO, int port) {
    Connector connector;
    if (useNIO) {
        logger.info("Setting up NIO SelectChannelConnector on port " + port);
        SelectChannelConnector nioconn = new SelectChannelConnector();
        nioconn.setSoLingerTime(-1);
        nioconn.setThreadPool(new QueuedThreadPool(20));
        connector = nioconn;
    } else {
        logger.info("Setting up SocketConnector on port " + port);
        SocketConnector sockconn = new SocketConnector();
        connector = sockconn;
    }

    connector.setPort(port);
    connector.setMaxIdleTime(30000);
    return connector;
}
项目:simplejmx    文件:Jetty8ConnectorFactory.java   
@Override
public Connector buildConnector(Server server, InetAddress inetAddress, int port) {
    // create the NIO connector
    SelectChannelConnector connector = new SelectChannelConnector();
    if (inetAddress != null) {
        connector.setHost(inetAddress.getHostAddress());
    }
    connector.setPort(port);

    // turn on statistics
    connector.setStatsOn(true);
    // set whether or not to reuse the addresses
    connector.setReuseAddress(true);

    // configure the thread pool for accepting connections
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMinThreads(WEB_SERVER_MIN_THREADS);
    threadPool.setMaxThreads(WEB_SERVER_MAX_THREADS);
    threadPool.setName("simplejmx-web-server");
    connector.setThreadPool(threadPool);
    connector.setAcceptors(WEB_SERVER_MIN_THREADS);

    return connector;
}
项目:iif-generic-soap-client    文件:ServerStarter.java   
public static void startWebServer(int port) throws Exception {
    webServer = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    webServer.addConnector(connector);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    //resource_handler.setWelcomeFiles(new String[] { "index.html" });

    String serverRoot = ServerStarter.class.getResource("/").getFile();

    resource_handler.setResourceBase(serverRoot);

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler,
            new DefaultHandler() });
    webServer.setHandler(handlers);

    webServer.start();

}
项目:health-and-care-developer-network    文件:TestServer.java   
public static void main(String[] args) throws Exception {
    final String baseDir = "/java/projects";
    final String sourceDir = baseDir + "/hazelcast/hazelcast-wm/src/test/webapp";

    Server server = new Server();

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(8080);
    server.addConnector(connector);

    WebAppContext context = new WebAppContext();
    context.setResourceBase(sourceDir);
    context.setDescriptor(sourceDir + "/WEB-INF/web.xml");
    context.setLogUrlOnStart(true);
    context.setContextPath("/");
    context.setParentLoaderPriority(true);

    server.setHandler(context);

    server.start();
    server.join();
}
项目:jbake-rtl-jalaali    文件:JettyServer.java   
/**
 * Run Jetty web server serving out supplied path on supplied port
 * 
 * @param path
 * @param port
 */
public void run(String path, String port) {
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
       connector.setPort(Integer.parseInt(port));
       server.addConnector(connector);

       ResourceHandler resource_handler = new ResourceHandler();
       resource_handler.setDirectoriesListed(true);
       resource_handler.setWelcomeFiles(new String[]{ "index.html" });

       resource_handler.setResourceBase(path);

       HandlerList handlers = new HandlerList();
       handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
       server.setHandler(handlers);

       LOGGER.info("Serving out contents of: [{}] on http://localhost:{}/", path, port);
       LOGGER.info("(To stop server hit CTRL-C)");

       try {
        server.start();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:demo-cas-server-web    文件:JettyBootStrap.java   
/**
 * 创建用于开发运行调试的JettyServer
 * @param port        访问服务器的端口
 * @param contextPath 访问服务器的地址
 * @param webAppPath  Web应用的目录(需指向到WebRoot目录下)
 */
private static Server createServer(int port, String contextPath, String webAppPath){
    Server server = new Server();
    //设置在JVM退出时关闭Jetty的钩子
    //这样就可以在整个功能测试时启动一次Jetty,然后让它在JVM退出时自动关闭
    server.setStopAtShutdown(true);
    //ServerConnector connector = new ServerConnector(server);
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    //解决Windows下重复启动Jetty不报告端口冲突的问题
    //在Windows下有个Windows + Sun的connector实现的问题,reuseAddress=true时重复启动同一个端口的Jetty不会报错
    //所以必须设为false,代价是若上次退出不干净(比如有TIME_WAIT),会导致新的Jetty不能启动,但权衡之下还是应该设为False
    connector.setReuseAddress(false);
    server.setConnectors(new Connector[]{connector});
    //为了设置reuseAddress=false所以创建Connector,否则直接new Server(port)即可,通过查看Server源码发现,二者是等效的
    //不过使用Connector的好处是可以让Jetty监听多个端口,此时创建多个绑定不同端口的Connector即可,最后一起setConnectors
    //Server server = new Server(port);
    //server.setStopAtShutdown(true);
    WebAppContext context = new WebAppContext(webAppPath, contextPath);
    //解决Windows环境下Lock静态文件的问题
    //Jetty运行时会锁住js、css等文件,导致不能修改保存,解决办法是修改webdefault.xml中的useFileMappedBuffer=false
    //这里试了很多遍都没成功,后来注释掉这里的setDefaultsDescriptor(),也删除项目中的webdefault-windows.xml
    //再重启应用,竟然可以修改保存了,后来又反复重启又试了几次竟然都可以修改保存,很是奇怪
    //context.setDefaultsDescriptor("F:/Tool/Code/JavaSE/MyJettyDemo/test/webdefault-windows.xml");
    server.setHandler(context);
    return server;
}
项目:demo-springmvc-shiro    文件:JettyBootStrap.java   
@SuppressWarnings("ConstantConditions")
private static Server createServer(){
    Server server = new Server();
    server.setStopAtShutdown(true);
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    connector.setReuseAddress(false);
    server.setConnectors(new Connector[]{connector});
    String webAppPath = JettyBootStrap.class.getClassLoader().getResource(".").getFile();
    webAppPath = webAppPath.substring(0, webAppPath.indexOf("target")) + "src/main/webapp";
    WebAppContext context = new WebAppContext(webAppPath, contextPath);
    server.setHandler(context);
    return server;
}
项目:ats-framework    文件:ContainerStarter.java   
/**
 * Method for starting the Jetty server with the ATS Agent webapp.
 * @param port the port on which to start the server.
 * @return the started server.
 * @throws IOException
 */
private static Server startServer() throws IOException {

    addAppender();

    final int agentPort = getAgentDefaultPort();
    log.info("Starting ATS agent at port: " + agentPort);

    final String jettyHome = getJettyHome();

    logSystemInformation(jettyHome);

    // start the server
    Connector connector = new SelectChannelConnector();
    connector.setPort(agentPort);

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

    WebAppContext webApp = new WebAppContext();
    webApp.setContextPath("/agentapp");
    webApp.setWar(jettyHome + "/webapp/agentapp.war");

    server.setHandler(webApp);
    server.setStopAtShutdown(true);

    setExtraClasspath(webApp, jettyHome);

    try {
        server.start();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

    log.info("ATS agent started");
    return server;
}
项目:demo-cas-client    文件:JettyBootStrap.java   
/**
 * 创建用于开发运行调试的JettyServer
 * @param port        访问服务器的端口
 * @param contextPath 访问服务器的地址
 * @param webAppPath  Web应用的目录(需指向到WebRoot目录下)
 */
private static Server createServer(int port, String contextPath, String webAppPath){
    Server server = new Server();
    //设置在JVM退出时关闭Jetty的钩子
    //这样就可以在整个功能测试时启动一次Jetty,然后让它在JVM退出时自动关闭
    server.setStopAtShutdown(true);
    //ServerConnector connector = new ServerConnector(server);
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    //解决Windows下重复启动Jetty不报告端口冲突的问题
    //在Windows下有个Windows + Sun的connector实现的问题,reuseAddress=true时重复启动同一个端口的Jetty不会报错
    //所以必须设为false,代价是若上次退出不干净(比如有TIME_WAIT),会导致新的Jetty不能启动,但权衡之下还是应该设为False
    connector.setReuseAddress(false);
    server.setConnectors(new Connector[]{connector});
    //为了设置reuseAddress=false所以创建Connector,否则直接new Server(port)即可,通过查看Server源码发现,二者是等效的
    //不过使用Connector的好处是可以让Jetty监听多个端口,此时创建多个绑定不同端口的Connector即可,最后一起setConnectors
    //Server server = new Server(port);
    //server.setStopAtShutdown(true);
    WebAppContext context = new WebAppContext(webAppPath, contextPath);
    //解决Windows环境下Lock静态文件的问题
    //Jetty运行时会锁住js、css等文件,导致不能修改保存,解决办法是修改webdefault.xml中的useFileMappedBuffer=false
    //这里试了很多遍都没成功,后来注释掉这里的setDefaultsDescriptor(),也删除项目中的webdefault-windows.xml
    //再重启应用,竟然可以修改保存了,后来又反复重启又试了几次竟然都可以修改保存,很是奇怪
    //context.setDefaultsDescriptor("F:/Tool/Code/JavaSE/MyJettyDemo/test/webdefault-windows.xml");
    server.setHandler(context);
    return server;
}
项目:jsf-sdk    文件:HttpWsServer.java   
@Override
public void start() {
    if (isStarted()) {
        return;
    }
    jettyServer = new org.eclipse.jetty.server.Server();
    int port = serverConfig.getPort();
    DispatcherServlet.addHttpHandler(port, new WebServiceHandler());

    int threads = serverConfig.getServerBusinessPoolSize();
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setName("JSF-WS-BZ");
    threadPool.setDaemon(true);
    threadPool.setMaxThreads(threads);
    threadPool.setMinThreads(threads);
    jettyServer.setThreadPool(threadPool);

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setHost(serverConfig.getHost());
    connector.setPort(serverConfig.getPort());
    jettyServer.addConnector(connector);

    ServletHandler servletHandler = new ServletHandler();
    ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*");
    servletHolder.setInitOrder(2);

    jettyServer.setHandler(servletHandler);

    try {
        jettyServer.start();
    } catch (Exception e) {
        throw new InitErrorException("Failed to start jetty server at port " + port
                + ", cause: " + e.getMessage(), e);
    }
}
项目:fpc    文件:JettyServer.java   
/**
 * Method used to initialize and start the SSE server
 */
public static void init()
{
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(8070);
    connector.setAcceptors(3);
    connector.setThreadPool(new QueuedThreadPool(50));
    connector.setMaxIdleTime(72*60*60*1000);
    connector.setAcceptQueueSize(50000);
    connector.setRequestBufferSize(50000);
    connector.setResponseBufferSize(50000);
    server.setConnectors(new Connector[] { connector });
    ServletContextHandler context = new ServletContextHandler(
            ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    //context.setResourceBase(System.getProperty("java.io.tmpdir"));

    ServletHolder requestServletHolder = new ServletHolder(EventServer.class);
    context.addServlet(requestServletHolder, "/response");

    ServletHolder notificationServletHolder = new ServletHolder(NotificationServer.class);
    context.addServlet(notificationServletHolder, "/notification");


    server.setHandler(context);
    context.addEventListener(new ConfigureService());
    context.addEventListener(new NotificationService());

    try {
        server.start();
        LOG.info("Server Started");
        server.join();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


}
项目:reactive-components    文件:TestServlet.java   
private Server createServer() {
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(8384);
    server.addConnector(connector);

    ServletContextHandler handler = new ServletContextHandler();
    handler.setContextPath("/");
    handler.addServlet(new ServletHolder(new TestAsyncServlet()), "/");
    server.setHandler(handler);
    return server;
}
项目:carbon    文件:JettyServerBridge.java   
@Override
public void run() throws Exception {

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(config.getPort());
    connector.setRequestHeaderSize(config.getMaxHeaderSize());
    connector.setRequestBufferSize(config.getMaxContentSize());

    server.setHandler(rootHandler);
    server.setConnectors(new Connector[]{connector});
    server.start();
}
项目:gemfirexd-oss    文件:JettyHelper.java   
private static void setAddressAndPort(final Server jetty,
    final String bindAddress, final int port) {
  SelectChannelConnector connector = new SelectChannelConnector();
  connector.setPort(port);

  if (!StringUtils.isBlank(bindAddress)) {
    connector.setHost(bindAddress);
  }
  jetty.addConnector(connector);
}
项目:venus    文件:VenusJettyServer.java   
public void start() throws Exception {
    server = new Server();

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    server.addConnector(connector);

    WebAppContext context = new WebAppContext();
    context.setContextPath(contextPath);
    context.setResourceBase(webapp);
    context.setConfigurationDiscovered(true);

    server.setHandler(context);
    server.start();
}
项目:MyTv    文件:HessianServer.java   
@Override
public void start() throws Exception {
    // 启动web应用
    org.eclipse.jetty.server.Server server = new Server();
    server.setStopAtShutdown(true);
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(Config.NET_CONFIG.getHessianPort());
    connector.setHost(Config.NET_CONFIG.getIp());
    // 解决Windows下重复启动Jetty居然不报告端口冲突的问题.
    connector.setReuseAddress(false);
    server.setConnectors(new Connector[] { connector });
    // web配置
    WebAppContext context = new WebAppContext();
    String resourcePath = MyTvUtils.getRunningPath(HessianServer.class);
    logger.info("web app context path: " + resourcePath);
    context.setContextPath("/");
    String descriptor = resourcePath + "/WEB-INF/web.xml";
    logger.info("web app descriptor: " + descriptor);
    context.setDescriptor(descriptor);
    context.setResourceBase(resourcePath);
    context.setParentLoaderPriority(true);
    ClassLoader appClassLoader = Thread.currentThread()
            .getContextClassLoader();
    context.setClassLoader(appClassLoader);

    server.setHandler(context);
    server.start();
}
项目:apex-core    文件:StramTestSupport.java   
public void start() throws Exception
{
  server = new Server();
  Connector connector = new SelectChannelConnector();
  connector.setPort(port);
  server.addConnector(connector);

    // Setup the basic application "context" for this application at "/"
  // This is also known as the handler tree (in jetty speak)
  ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
  contextHandler.setContextPath("/");
  server.setHandler(contextHandler);
  WebSocketServlet webSocketServlet = new WebSocketServlet()
  {
    @Override
    public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol)
    {
      return websocket;
    }
  };

  contextHandler.addServlet(new ServletHolder(webSocketServlet), "/pubsub");
  server.start();
  if (port == 0) {
    port = server.getConnectors()[0].getLocalPort();
  }
}