Java Code Examples for org.mortbay.jetty.Server#join()

The following examples show how to use org.mortbay.jetty.Server#join() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmbeddedServer.java    From xdocreport.samples with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8081 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/reporting" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );

    server.start();
    server.join();
}
 
Example 2
Source File: EmbeddedServer.java    From xdocreport.samples with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8081 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/reporting" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );

    server.start();
    server.join();
}
 
Example 3
Source File: EmbeddedServer.java    From xdocreport.samples with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/xdocreport-webapp" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );

    // JSP Servlet + Context
    Context jsp_ctx = new Context( servlet_contexts, "/jsp", Context.SESSIONS );
    jsp_ctx.addServlet( new ServletHolder( new org.apache.jasper.servlet.JspServlet() ), "*.jsp" );

    server.start();
    server.join();
}
 
Example 4
Source File: EmbeddedServer.java    From xdocreport.samples with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8081 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/reporting" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );

    server.start();
    server.join();
}
 
Example 5
Source File: GitkitExample.java    From identity-toolkit-java with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  Server server = new Server(4567);
  ServletHandler servletHandler = new ServletHandler();
  SessionHandler sessionHandler = new SessionHandler();
  sessionHandler.setHandler(servletHandler);
  server.setHandler(sessionHandler);
  servletHandler.addServletWithMapping(LoginServlet.class, "/login");
  servletHandler.addServletWithMapping(WidgetServlet.class, "/gitkit");
  servletHandler.addServletWithMapping(LoginServlet.class, "/");
  server.start();
  server.join();
}
 
Example 6
Source File: JettyLauncher.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Server server = new Server();

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(PORT);
    server.addConnector(connector);
    server.setStopAtShutdown(true);

    // the orders of handlers is very important!
    ContextHandler contextHandler = new ContextHandler();
    contextHandler.setContextPath("/reports");
    contextHandler.setResourceBase("./reports/");
    contextHandler.addHandler(new ResourceHandler());
    server.addHandler(contextHandler);

    server.addHandler(new WebAppContext("webapp", "/nextreports-server"));

    long t = System.currentTimeMillis();
    server.start();
    t = System.currentTimeMillis() - t;
    String version = server.getClass().getPackage().getImplementationVersion();
    System.out.println("Started Jetty Server " + version + " on port " + PORT + " in " + t / 1000 + "s");
    
    server.join();
}
 
Example 7
Source File: Main.java    From blog-codes with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception
{
	Server server = new Server(PORT);
	
	// Static file handler
	Context fileContext = new Context(server, "/mxgraph", Context.SESSIONS);
	ResourceHandler fileHandler = new ResourceHandler();
	fileHandler.setResourceBase(".");
	fileContext.setHandler(fileHandler);

	// Servlets
	Context context = new Context(server, "/", Context.SESSIONS);
	context.addServlet(new ServletHolder(new Roundtrip()), "/Roundtrip");
	context.addServlet(new ServletHolder(new ServerView()), "/ServerView");
	context.addServlet(new ServletHolder(new ExportServlet()), "/Export");
	context.addServlet(new ServletHolder(new EchoServlet()), "/Echo");
	context.addServlet(new ServletHolder(new Deploy()), "/Deploy");
	context.addServlet(new ServletHolder(new Link()), "/Link");
	context.addServlet(new ServletHolder(new EmbedImage()), "/EmbedImage");
	context.addServlet(new ServletHolder(new Backend()), "/Backend");

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

	System.out.println("Go to http://localhost:" + PORT + "/");
	
	server.start();
	server.join();
}
 
Example 8
Source File: ServerMojo.java    From opoopress with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeInternal(SiteConfigImpl config, SiteImpl site) throws MojoExecutionException, MojoFailureException {
    Server server = createJettyServer(site);

    try {
        server.start();
        onServerStart(site, server);

        server.join();
    } catch (Exception e) {
        throw new MojoExecutionException("Start server failed: " + e.getMessage(), e);
    }
}
 
Example 9
Source File: JettyServer.java    From ezScrum with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
		System.setProperty("ntut.csie.ezScrum.container", "Jetty");
		
		server = new Server();
		logger = Logger.getLogger(JettyServer.class.getName());
		FileHandler handler = new FileHandler("JettyServer.log");
		logger.addHandler(handler);
		
		try {
			while (restart == true) {
				restart = false;
				XmlConfiguration configuration = new XmlConfiguration(
						new FileInputStream("JettyServer.xml"));
				configuration.configure(server);
				
/*
 * comment by liullen
 * 因為socket監聽固定的port,為了讓 jetty能夠執行多個instance,所以把重新啟動的功能註解
 * 
				// 開啟一個localhost的Socket專門接收Stop的訊息
				Thread monitor = new MonitorThread();
				monitor.start();
*/

				server.start();
				server.join();
				
			}
		} catch (Exception e) {
			logger.severe(e.getMessage());
		}
	}
 
Example 10
Source File: JettyMain.java    From fraud-detection-tutorial with Apache License 2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {

    if (args.length == 0) {
      System.out.println("JettyMain {port} {zookeeperQuorum}");
    }
    try {
      Configuration config = HBaseConfiguration.create();
      config.addResource("/etc/hbase/conf/hbase-site.xml");
      config.set(HConstants.ZOOKEEPER_QUORUM, args[1]);
      //config.set(HConstants.ZOOKEEPER_CLIENT_PORT, "2181");

      HBaseService hbaseService = new HBaseService(config);

      Server server = new Server(Integer.parseInt(args[0]));

      WebAppContext webapp = new WebAppContext();
      webapp.setContextPath("/fe");
      webapp.setResourceBase("./webapp");
      webapp.setWelcomeFiles(new String[]{"index.html"});

      Context servletContext = new Context();
      servletContext.setContextPath("/be");
      servletContext.addServlet(GraphTsvServlet.class, "/graph.tsv");
      servletContext.addServlet(FileGetterServlet.class, "/file/*");
      servletContext.addServlet(NodeAutoCompleteServlet.class, "/auto/*");
      servletContext.addServlet(GraphNodeJsonServlet.class, "/nodeGraph/*");
      servletContext.addServlet(NodeHomeDashBoardInfoServlet.class, "/nodeDash/*");

      server.setHandlers(new Handler[]{webapp, servletContext});

      System.out.println("-");

      GraphTsvServlet.setHBaseService(hbaseService);
      FileGetterServlet.setHBaseService(hbaseService);
      NodeAutoCompleteServlet.setHBaseService(hbaseService);
      GraphNodeJsonServlet.setHBaseService(hbaseService);
      NodeHomeDashBoardInfoServlet.setHBaseService(hbaseService);

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

    } finally {
      System.out.println("Step 7: Shut Down");
    }
  }
 
Example 11
Source File: Main.java    From stanbol-freeling with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * @param args
 * @throws Exception 
 */
public static void main(String[] args) throws Exception {
    CommandLineParser parser = new PosixParser();
    CommandLine line = parser.parse(options, args);
    args = line.getArgs();
    if(line.hasOption('h')){
        printHelp();
        System.exit(0);
    }
    //Parse the Freeling parameter and init the Freeling instance
    String sharedFolder = System.getenv(ENV_FREELING_SHARED_FOLDER);
    sharedFolder = System.getProperty(PROPERTY_FREELING_SHARED_FOLDER, sharedFolder);
    sharedFolder = line.getOptionValue('s', sharedFolder);
    if(sharedFolder == null){
        System.err.println("The Freeling shared Folder MUST BE set! \n");
        printHelp();
        System.exit(0);
    }
    File shared = new File(sharedFolder);
    if(!shared.isDirectory()){
        System.err.println("The configured Freeling shared folder '"
            + sharedFolder + "' is not a directory!\n");
        System.exit(1);
    }
    String configFolder = FilenameUtils.concat(sharedFolder, "config");
    configFolder = System.getProperty(PROPERTY_FREELING_CONFIG_FOLDER, configFolder);
    configFolder = line.getOptionValue('c', configFolder);
    File config = new File(configFolder);
    if(!config.isDirectory()){
        System.err.println("The configured Freeling config folder '"
            + configFolder + "' is not a directory!\n");
        System.exit(1);
    }
    String nativeLib = FilenameUtils.concat(sharedFolder, Freeling.DEFAULT_FREELING_LIB_PATH);
    if(new File(Freeling.DEFAULT_FREELING_LIB_PATH).isFile()){
        nativeLib = Freeling.DEFAULT_FREELING_LIB_PATH;
    }
    nativeLib = line.getOptionValue('l', nativeLib);
    if(!new File(nativeLib).isFile()){
        System.err.println("The configured Freeling native lib '"
                + nativeLib + "' is not a file!\n");
        System.exit(1);
    }
    Freeling freeling = new Freeling(
        config.getPath(), Freeling.DEFAULT_CONFIGURATION_FILENAME_SUFFIX, 
        shared.getPath(), nativeLib, Freeling.DEFAULT_FREELING_LOCALE, 
        getInt(line, 'i', DEFAULT_INIT_THREADS), 
        getInt(line, 'm', DEFAULT_MAX_POOL_SIZE), 
        getInt(line, 'q', DEFAULT_MIN_QUEUE_SIZE));
    
    
    //init the Jetty Server
    Server server = new Server();
    Connector con = new SelectChannelConnector();
    //we need the port
    con.setPort(getInt(line,'p',DEFAULT_PORT));
    server.addConnector(con);

    //init the Servlet and the ServletContext
    Context context = new Context(server, "/", Context.SESSIONS);
    ServletHolder holder = new ServletHolder(RestServlet.class);
    holder.setInitParameter("javax.ws.rs.Application", FreelingApplication.class.getName());
    context.addServlet(holder, "/*");
    
    //now initialise the servlet context
    context.setAttribute(Constants.SERVLET_ATTRIBUTE_CONTENT_ITEM_FACTORY, 
        lookupService(ContentItemFactory.class));
    context.setAttribute(Constants.SERVLET_ATTRIBUTE_FREELING, freeling);
    context.setAttribute(Constants.SERVLET_ATTRIBUTE_MAX_RESOURCE_WAIT_TIEM, 
        getLong(line,'w',Constants.DEFAULT_RESOURCE_WAIT_TIME));
    //Freeling
    
    server.start();
    try {
        server.join();
    }catch (InterruptedException e) {
    }
    System.err.println("Shutting down Freeling");
    freeling.close();
}
 
Example 12
Source File: JettyTest.java    From fraud-detection-tutorial with Apache License 2.0 2 votes vote down vote up
public static void main(String args[]) throws Exception {

    LocalHBaseCluster hbaseCluster = new LocalHBaseCluster();
    Configuration config = hbaseCluster.getConfiguration();
    QueueToHBaseProcess queueHBaseProcess = null;
    try {
      System.out.println("Step 1: Config");

      HBaseService hbaseService = new HBaseService(config);

      System.out.println("Step 2: Service");

      hbaseService.generateTables();

      System.out.println("Step 2.5: Tables");

      populateInitialNodes(hbaseService);

      System.out.println("Step 2.75: Rules");

      //populateRules(hbaseService);

      System.out.println("Step 3: Nodes Populated");

      EventListener listener = new InternalQueueListener();

      System.out.println("Step 4: Listener");

      long sleepBetweenIterations = 5000;
      long maxIterations = 200;
      int updateNodeListEveryNIterations = 100;
      int updateEtcFileEveryNRequest = 7;

      NodeDataSymulator sym = new NodeDataSymulator(listener, hbaseService,
              sleepBetweenIterations, maxIterations,
              updateNodeListEveryNIterations, updateEtcFileEveryNRequest);

      queueHBaseProcess = new QueueToHBaseProcess(hbaseService);

      queueHBaseProcess.start();

      sym.run(10);

      System.out.println("Step 5: Sym");


      System.out.println("Step 6: API Test");

      Server server = new Server(8082);

      WebAppContext webapp = new WebAppContext();
      webapp.setContextPath("/fe");
      webapp.setResourceBase("./webapp");
      webapp.setWelcomeFiles(new String[]{"index.html"});


      Context servletContext = new Context();
      servletContext.setContextPath("/be");
      servletContext.addServlet(GraphTsvServlet.class, "/graph.tsv");
      servletContext.addServlet(FileGetterServlet.class, "/file/*");
      servletContext.addServlet(NodeAutoCompleteServlet.class, "/auto/*");
      servletContext.addServlet(GraphNodeJsonServlet.class, "/nodeGraph/*");
      servletContext.addServlet(NodeHomeDashBoardInfoServlet.class, "/nodeDash/*");

      server.setHandlers(new Handler[]{webapp, servletContext});

      System.out.println("-");

      GraphTsvServlet.setHBaseService(hbaseService);
      FileGetterServlet.setHBaseService(hbaseService);
      NodeAutoCompleteServlet.setHBaseService(hbaseService);
      GraphNodeJsonServlet.setHBaseService(hbaseService);
      NodeHomeDashBoardInfoServlet.setHBaseService(hbaseService);

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

    } finally {
      queueHBaseProcess.stop();

      hbaseCluster.shutDown();


      System.out.println("Step 7: Shut Down");
    }
  }