Package com.bleujin.dbfs

Source Code of com.bleujin.dbfs.SimpleServer

package com.bleujin.dbfs;

import org.mortbay.jetty.Server;
import org.mortbay.jetty.deployer.WebAppDeployer;
import org.mortbay.jetty.handler.ContextHandlerCollection;
import org.mortbay.jetty.handler.DefaultHandler;
import org.mortbay.jetty.handler.HandlerCollection;
import org.mortbay.jetty.handler.RequestLogHandler;

import com.bleujin.framework.util.StringUtil;

public class SimpleServer {

  private Server server;

  private String contextName;

  private SimpleServer() {
    this("/simple", 8080);
  }

  private SimpleServer(String contextName, int port) {
    this.server = new Server(port);
    this.contextName = contextName;
  }

  public void start() throws Exception {
    // WebAppContext simple = new WebAppContext(server, "resources/SIMPLE", contextName);
    // simple.setDescriptor("resources/SIMPLE/WEB-INF/web.xml");j

    HandlerCollection col = new HandlerCollection();
    ContextHandlerCollection context = new ContextHandlerCollection();
   
    col.addHandler(context);
    col.addHandler(new DefaultHandler());
    //col.addHandler(new SlayerHandler()) ;
    col.addHandler(new RequestLogHandler());
    server.setHandler(col);

    WebAppDeployer deployer = new WebAppDeployer();

    deployer.setContexts(context);
    deployer.setWebAppDir("webapps/");
    server.addLifeCycle(deployer);
   
//    ContextDeployer cdeployer = new ContextDeployer() ;
//    cdeployer.setContexts(context) ;
//    server.addLifeCycle(cdeployer);

    server.start();
    server.join();

  }

  public void stop() throws Exception {
    server.stop();
  }


  public static void main(String[] args) {
    try {
      String contextName = "simple" ;
      int port = 8080 ;
      for (int i = 0, last = args.length; i < last; i++) {
        String arg = args[i].toLowerCase() ;
              if (arg.startsWith("-contextname:")){
                contextName = StringUtil.substringAfterLast(arg, "-contextname:").trim() ;
              } else if (arg.startsWith("-port:")) {
                port = Integer.parseInt(StringUtil.substringAfterLast(arg, "-port:").trim()) ;
              }
            }

      SimpleServer server = new SimpleServer("/" + contextName, port);
      server.start();
    } catch (Exception e1) {
      e1.printStackTrace();
    }
  }
}
TOP

Related Classes of com.bleujin.dbfs.SimpleServer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.