Search in sources :

Example 36 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project Ebselen by Ardesco.

the class JettyServer method startJettyServer.

public void startJettyServer(int port) throws Exception {
    String resourceBasePath = this.getClass().getResource("/web").toExternalForm();
    jettyServer = new Server(port);
    WebAppContext webapp = new WebAppContext();
    webapp.setResourceBase(resourceBasePath);
    jettyServer.setHandler(webapp);
    jettyServer.start();
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server)

Example 37 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project lucene-solr by apache.

the class JettyWebappTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    System.setProperty("solr.solr.home", SolrJettyTestBase.legacyExampleCollection1SolrHome());
    System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong()));
    System.setProperty("solr.tests.doContainerStreamCloseAssert", "false");
    File dataDir = createTempDir().toFile();
    dataDir.mkdirs();
    System.setProperty("solr.data.dir", dataDir.getCanonicalPath());
    String path = ExternalPaths.WEBAPP_HOME;
    server = new Server(port);
    // insecure: only use for tests!!!!
    server.setSessionIdManager(new HashSessionIdManager(new Random(random().nextLong())));
    new WebAppContext(server, path, context);
    ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory());
    connector.setIdleTimeout(1000 * 60 * 60);
    connector.setSoLingerTime(-1);
    connector.setPort(0);
    server.setConnectors(new Connector[] { connector });
    server.setStopAtShutdown(true);
    server.start();
    port = connector.getLocalPort();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server) Random(java.util.Random) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) File(java.io.File) HashSessionIdManager(org.eclipse.jetty.server.session.HashSessionIdManager)

Example 38 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project jena by apache.

the class JettyFuseki method buildServerWebapp.

private void buildServerWebapp(String contextPath, String jettyConfig) {
    if (jettyConfig != null)
        // --jetty-config=jetty-fuseki.xml
        // for detailed configuration of the server using Jetty features.
        configServer(jettyConfig);
    else
        defaultServerConfig(serverConfig.port, serverConfig.loopback);
    WebAppContext webapp = createWebApp(contextPath);
    if (false) /*enable symbolic links */
    {
        // See http://www.eclipse.org/jetty/documentation/current/serving-aliased-files.html
        // Record what would be needed:
        // 1 - Allow all symbolic links without checking
        webapp.addAliasCheck(new ContextHandler.ApproveAliases());
        // 2 - Check links are to valid resources. But default for Unix?
        webapp.addAliasCheck(new AllowSymLinkAliasChecker());
    }
    servletContext = webapp.getServletContext();
    server.setHandler(webapp);
    // Replaced by Shiro.
    if (jettyConfig == null && serverConfig.authConfigFile != null)
        security(webapp, serverConfig.authConfigFile);
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) AllowSymLinkAliasChecker(org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker)

Example 39 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project spring-boot by spring-projects.

the class EmbeddedWarStarter method main.

public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    WebAppContext webAppContext = new WebAppContext();
    webAppContext.setContextPath("/");
    webAppContext.setConfigurations(new Configuration[] { new WebApplicationInitializersConfiguration(SpringInitializer.class) });
    webAppContext.setParentLoaderPriority(true);
    server.setHandler(webAppContext);
    server.start();
    server.join();
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server) SpringInitializer(org.springframework.boot.load.it.war.SpringInitializer)

Example 40 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project solo by b3log.

the class Starter method main.

/**
     * Main.
     *
     * @param args the specified arguments
     * @throws java.lang.Exception if start failed
     */
public static void main(final String[] args) throws Exception {
    final Logger logger = Logger.getLogger(Starter.class);
    final Options options = new Options();
    final Option listenPortOpt = Option.builder("lp").longOpt("listen_port").argName("LISTEN_PORT").hasArg().desc("listen port, default is 8080").build();
    options.addOption(listenPortOpt);
    final Option serverSchemeOpt = Option.builder("ss").longOpt("server_scheme").argName("SERVER_SCHEME").hasArg().desc("browser visit protocol, default is http").build();
    options.addOption(serverSchemeOpt);
    final Option serverHostOpt = Option.builder("sh").longOpt("server_host").argName("SERVER_HOST").hasArg().desc("browser visit domain name, default is localhost").build();
    options.addOption(serverHostOpt);
    final Option serverPortOpt = Option.builder("sp").longOpt("server_port").argName("SERVER_PORT").hasArg().desc("browser visit port, default is 8080").build();
    options.addOption(serverPortOpt);
    final Option staticServerSchemeOpt = Option.builder("sss").longOpt("static_server_scheme").argName("STATIC_SERVER_SCHEME").hasArg().desc("browser visit static resource protocol, default is http").build();
    options.addOption(staticServerSchemeOpt);
    final Option staticServerHostOpt = Option.builder("ssh").longOpt("static_server_host").argName("STATIC_SERVER_HOST").hasArg().desc("browser visit static resource domain name, default is localhost").build();
    options.addOption(staticServerHostOpt);
    final Option staticServerPortOpt = Option.builder("ssp").longOpt("static_server_port").argName("STATIC_SERVER_PORT").hasArg().desc("browser visit static resource port, default is 8080").build();
    options.addOption(staticServerPortOpt);
    final Option runtimeModeOpt = Option.builder("rm").longOpt("runtime_mode").argName("RUNTIME_MODE").hasArg().desc("runtime mode (DEVELOPMENT/PRODUCTION), default is DEVELOPMENT").build();
    options.addOption(runtimeModeOpt);
    options.addOption("h", "help", false, "print help for the command");
    final HelpFormatter helpFormatter = new HelpFormatter();
    final CommandLineParser commandLineParser = new DefaultParser();
    CommandLine commandLine;
    final boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows");
    final String cmdSyntax = isWindows ? "java -cp WEB-INF/lib/*;WEB-INF/classes org.b3log.solo.Starter" : "java -cp WEB-INF/lib/*:WEB-INF/classes org.b3log.solo.Starter";
    final String header = "\nSolo is a blogging system written in Java, feel free to create your or your team own blog.\nSolo 是一个用 Java 实现的博客系统,为你或你的团队创建个博客吧。\n\n";
    final String footer = "\nReport bugs or request features please visit our project website: https://github.com/b3log/solo\n\n";
    try {
        commandLine = commandLineParser.parse(options, args);
    } catch (final ParseException e) {
        helpFormatter.printHelp(cmdSyntax, header, options, footer, true);
        return;
    }
    if (commandLine.hasOption("h")) {
        helpFormatter.printHelp(cmdSyntax, header, options, footer, true);
        return;
    }
    String portArg = commandLine.getOptionValue("listen_port");
    if (!Strings.isNumeric(portArg)) {
        portArg = "8080";
    }
    String serverScheme = commandLine.getOptionValue("server_scheme");
    Latkes.setServerScheme(serverScheme);
    String serverHost = commandLine.getOptionValue("server_host");
    Latkes.setServerHost(serverHost);
    String serverPort = commandLine.getOptionValue("server_port");
    Latkes.setServerPort(serverPort);
    String staticServerScheme = commandLine.getOptionValue("static_server_scheme");
    Latkes.setStaticServerScheme(staticServerScheme);
    String staticServerHost = commandLine.getOptionValue("static_server_host");
    Latkes.setStaticServerHost(staticServerHost);
    String staticServerPort = commandLine.getOptionValue("static_server_port");
    Latkes.setStaticServerPort(staticServerPort);
    String runtimeMode = commandLine.getOptionValue("runtime_mode");
    if (null != runtimeMode) {
        Latkes.setRuntimeMode(RuntimeMode.valueOf(runtimeMode));
    }
    // For Latke IoC 
    Latkes.setScanPath("org.b3log.solo");
    logger.info("Standalone mode, see [https://github.com/b3log/solo/wiki/standalone_mode] for more details.");
    Latkes.initRuntimeEnv();
    // POM structure in dev env
    String webappDirLocation = "src/main/webapp/";
    final File file = new File(webappDirLocation);
    if (!file.exists()) {
        // production environment
        webappDirLocation = ".";
    }
    final int port = Integer.valueOf(portArg);
    final Server server = new Server(port);
    final WebAppContext root = new WebAppContext();
    // Use parent class loader
    root.setParentLoaderPriority(true);
    root.setContextPath("/");
    root.setDescriptor(webappDirLocation + "/WEB-INF/web.xml");
    root.setResourceBase(webappDirLocation);
    server.setHandler(root);
    try {
        server.start();
    } catch (final Exception e) {
        logger.log(Level.ERROR, "Server start failed", e);
        System.exit(-1);
    }
    serverScheme = Latkes.getServerScheme();
    serverHost = Latkes.getServerHost();
    serverPort = Latkes.getServerPort();
    final String contextPath = Latkes.getContextPath();
    try {
        Desktop.getDesktop().browse(new URI(serverScheme + "://" + serverHost + ":" + serverPort + contextPath));
    } catch (final Throwable e) {
    // Ignored
    }
    server.join();
}
Also used : Options(org.apache.commons.cli.Options) Server(org.eclipse.jetty.server.Server) Logger(org.b3log.latke.logging.Logger) URI(java.net.URI) ParseException(org.apache.commons.cli.ParseException) HelpFormatter(org.apache.commons.cli.HelpFormatter) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) CommandLine(org.apache.commons.cli.CommandLine) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) File(java.io.File) DefaultParser(org.apache.commons.cli.DefaultParser)

Aggregations

WebAppContext (org.eclipse.jetty.webapp.WebAppContext)291 Server (org.eclipse.jetty.server.Server)108 File (java.io.File)74 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)38 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)35 IOException (java.io.IOException)31 ServerConnector (org.eclipse.jetty.server.ServerConnector)31 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)31 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)22 URL (java.net.URL)21 URISyntaxException (java.net.URISyntaxException)20 Handler (org.eclipse.jetty.server.Handler)17 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)17 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)15 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)15 WebXmlConfiguration (org.eclipse.jetty.webapp.WebXmlConfiguration)15 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)14 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)14 Resource (org.eclipse.jetty.util.resource.Resource)13