org.eclipse.jetty.server.Server#getHandler ( )源码实例Demo

下面列出了org.eclipse.jetty.server.Server#getHandler ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: scheduling   文件: JettyStarter.java
private List<String> startServer(Server server, String schedulerHost, int restPort, String httpProtocol) {
    try {
        if (server.getHandler() == null) {
            logger.info("SCHEDULER_HOME/dist/war folder is empty, nothing is deployed");
        } else {
            server.start();
            if (server.isStarted()) {
                return printDeployedApplications(server, schedulerHost, restPort, httpProtocol);
            } else {
                logger.error("Failed to start web applications");
                System.exit(1);
            }
        }
    } catch (BindException bindException) {
        logger.error("Failed to start web applications. Port " + restPort + " is already used", bindException);
        System.exit(2);
    } catch (Exception e) {
        logger.error("Failed to start web applications", e);
        System.exit(3);
    }
    return new ArrayList<>();
}
 
源代码2 项目: java-tutorial   文件: JettyFactory.java
public static void initWebAppContext(Server server, int type) throws Exception {
	System.out.println("[INFO] Application loading");
	WebAppContext webAppContext = (WebAppContext) server.getHandler();
	webAppContext.setContextPath(CONTEXT);
	webAppContext.setResourceBase(getAbsolutePath() + RESOURCE_BASE_PATH);
	webAppContext.setDescriptor(getAbsolutePath() + RESOURCE_BASE_PATH + WEB_XML_PATH);

	if (IDE_INTELLIJ == type) {
		webAppContext.setDefaultsDescriptor(WINDOWS_WEBDEFAULT_PATH);
		supportJspAndSetTldJarNames(server, TLD_JAR_NAMES);
	} else {
		webAppContext.setParentLoaderPriority(true);
	}

	System.out.println("[INFO] Application loaded");
}
 
源代码3 项目: java-tutorial   文件: JettyFactory.java
public static void initWebAppContext(Server server, int type) {
	System.out.println("[INFO] Application loading");
	WebAppContext webAppContext = (WebAppContext) server.getHandler();
	webAppContext.setContextPath(CONTEXT);
	webAppContext.setResourceBase(getAbsolutePath() + RESOURCE_BASE_PATH);
	webAppContext.setDescriptor(getAbsolutePath() + RESOURCE_BASE_PATH + WEB_XML_PATH);

	if (IDE_INTELLIJ == type) {
		webAppContext.setDefaultsDescriptor(WINDOWS_WEBDEFAULT_PATH);
		supportJspAndSetTldJarNames(server, TLD_JAR_NAMES);
	} else {
		webAppContext.setParentLoaderPriority(true);
	}

	System.out.println("[INFO] Application loaded");
}
 
源代码4 项目: tddl5   文件: JettyEmbedServer.java
public void start() throws Exception {
    Resource configXml = Resource.newSystemResource(config);
    XmlConfiguration configuration = new XmlConfiguration(configXml.getInputStream());
    server = (Server) configuration.configure();

    // Integer port = getPort();
    // if (port != null && port > 0) {
    // Connector[] connectors = server.getConnectors();
    // for (Connector connector : connectors) {
    // connector.setPort(port);
    // }
    // }
    Handler handler = server.getHandler();
    if (handler != null && handler instanceof WebAppContext) {
        WebAppContext webAppContext = (WebAppContext) handler;
        webAppContext.setResourceBase(JettyEmbedServer.class.getResource("/webapp").toString());
    }
    server.start();
    if (logger.isInfoEnabled()) {
        logger.info("##Jetty Embed Server is startup!");
    }
}
 
源代码5 项目: java-tutorial   文件: JettyFactory.java
public static void supportJspAndSetTldJarNames(Server server, String... jarNames) {
	WebAppContext context = (WebAppContext) server.getHandler();
	// This webapp will use jsps and jstl. We need to enable the
	// AnnotationConfiguration in
	// order to correctly set up the jsp container
	org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList
		.setServerDefault(server);
	classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
		"org.eclipse.jetty.annotations.AnnotationConfiguration");
	// Set the ContainerIncludeJarPattern so that jetty examines these container-path
	// jars for
	// tlds, web-fragments etc.
	// If you omit the jar that contains the jstl .tlds, the jsp engine will scan for
	// them
	// instead.
	ArrayList jarNameExprssions = Lists.newArrayList(".*/[^/]*servlet-api-[^/]*\\.jar$",
		".*/javax.servlet.jsp.jstl-.*\\.jar$", ".*/[^/]*taglibs.*\\.jar$");

	for (String jarName : jarNames) {
		jarNameExprssions.add(".*/" + jarName + "-[^/]*\\.jar$");
	}

	context.setAttribute("org.eclipse.jetty.io.github.dunwu.javaee.server.webapp.ContainerIncludeJarPattern",
		StringUtils.join(jarNameExprssions, '|'));
}
 
源代码6 项目: java-tutorial   文件: JettyFactory.java
public static void initWebAppContext(Server server, int type) {
	System.out.println("[INFO] Application loading");
	WebAppContext webAppContext = (WebAppContext) server.getHandler();
	webAppContext.setContextPath(CONTEXT);
	webAppContext.setResourceBase(getAbsolutePath() + RESOURCE_BASE_PATH);
	webAppContext.setDescriptor(getAbsolutePath() + RESOURCE_BASE_PATH + WEB_XML_PATH);

	if (IDE_INTELLIJ == type) {
		webAppContext.setDefaultsDescriptor(WINDOWS_WEBDEFAULT_PATH);
		supportJspAndSetTldJarNames(server, TLD_JAR_NAMES);
	} else {
		webAppContext.setParentLoaderPriority(true);
	}

	System.out.println("[INFO] Application loaded");
}
 
源代码7 项目: java-tutorial   文件: JettyFactory.java
public static void supportJspAndSetTldJarNames(Server server, String... jarNames) {
	WebAppContext context = (WebAppContext) server.getHandler();
	// This webapp will use jsps and jstl. We need to enable the
	// AnnotationConfiguration in
	// order to correctly set up the jsp container
	org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList
		.setServerDefault(server);
	classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
		"org.eclipse.jetty.annotations.AnnotationConfiguration");
	// Set the ContainerIncludeJarPattern so that jetty examines these container-path
	// jars for
	// tlds, web-fragments etc.
	// If you omit the jar that contains the jstl .tlds, the jsp engine will scan for
	// them
	// instead.
	ArrayList jarNameExprssions = Lists.newArrayList(".*/[^/]*servlet-api-[^/]*\\.jar$",
		".*/javax.servlet.jsp.jstl-.*\\.jar$", ".*/[^/]*taglibs.*\\.jar$");

	for (String jarName : jarNames) {
		jarNameExprssions.add(".*/" + jarName + "-[^/]*\\.jar$");
	}

	context.setAttribute("org.eclipse.jetty.io.github.dunwu.javaee.server.webapp.ContainerIncludeJarPattern",
		StringUtils.join(jarNameExprssions, '|'));
}
 
源代码8 项目: java-tutorial   文件: JettyFactory.java
public static void supportJspAndSetTldJarNames(Server server, String... jarNames) {
	WebAppContext context = (WebAppContext) server.getHandler();
	// This webapp will use jsps and jstl. We need to enable the
	// AnnotationConfiguration in
	// order to correctly set up the jsp container
	org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList
		.setServerDefault(server);
	classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
		"org.eclipse.jetty.annotations.AnnotationConfiguration");
	// Set the ContainerIncludeJarPattern so that jetty examines these container-path
	// jars for
	// tlds, web-fragments etc.
	// If you omit the jar that contains the jstl .tlds, the jsp engine will scan for
	// them
	// instead.
	ArrayList jarNameExprssions = Lists.newArrayList(".*/[^/]*servlet-api-[^/]*\\.jar$",
		".*/javax.servlet.jsp.jstl-.*\\.jar$", ".*/[^/]*taglibs.*\\.jar$");

	for (String jarName : jarNames) {
		jarNameExprssions.add(".*/" + jarName + "-[^/]*\\.jar$");
	}

	context.setAttribute("org.eclipse.jetty.io.github.dunwu.javaee.server.webapp.ContainerIncludeJarPattern",
		StringUtils.join(jarNameExprssions, '|'));
}
 
源代码9 项目: DataLink   文件: JettyServer.java
public void startup() throws Exception {
    Resource configXml = Resource.newSystemResource(DEFAULT_JETTY_CONFIG);
    XmlConfiguration configuration = new XmlConfiguration(configXml.getInputStream());
    server = (Server) configuration.configure();

    Integer port = config.getHttpPort();
    if (port != null && port > 0) {
        Connector[] connectors = server.getConnectors();
        for (Connector connector : connectors) {
            if (connector instanceof AbstractNetworkConnector) {
                ((AbstractNetworkConnector) connector).setPort(port);
            }
        }
    }

    Handler handler = server.getHandler();
    if (handler != null && handler instanceof WebAppContext) {
        WebAppContext webAppContext = (WebAppContext) handler;
        String webAppPath = System.getProperty("webapp.conf");
        logger.info("Web App Path is " + webAppPath);

        if (StringUtils.isBlank(webAppPath)) {
            webAppContext.setResourceBase(JettyServer.class.getResource("/webapp").toString());
        } else {
            webAppContext.setResourceBase(webAppPath);
        }
    }

    server.start();
    if (logger.isInfoEnabled()) {
        logger.info("##Jetty Embed Server is started.");
    }
}
 
源代码10 项目: java-tutorial   文件: JettyFactory.java
public static void supportJspAndSetTldJarNames(Server server, String... jarNames) {
	WebAppContext context = (WebAppContext) server.getHandler();
	// This webapp will use jsps and jstl. We need to enable the
	// AnnotationConfiguration in
	// order to correctly set up the jsp container
	org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList
		.setServerDefault(server);
	classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
		"org.eclipse.jetty.annotations.AnnotationConfiguration");
	// Set the ContainerIncludeJarPattern so that jetty examines these container-path
	// jars for
	// tlds, web-fragments etc.
	// If you omit the jar that contains the jstl .tlds, the jsp engine will scan for
	// them
	// instead.

	List<String> list = new ArrayList<>();
	list.add(".*/[^/]*servlet-api-[^/]*\\.jar$");
	list.add(".*/javax.servlet.jsp.jstl-.*\\.jar$");
	list.add(".*/[^/]*taglibs.*\\.jar$");

	for (String jarName : jarNames) {
		String str = ".*/" + jarName + "-[^/]*\\.jar$";
		list.add(str);
	}

	context.setAttribute("org.eclipse.jetty.io.github.dunwu.javaee.server.webapp.ContainerIncludeJarPattern",
		StringUtils.join(list, '|'));
}
 
源代码11 项目: java-tutorial   文件: JettyFactory.java
public static void reloadWebAppContext(Server server) throws Exception {
	WebAppContext webAppContext = (WebAppContext) server.getHandler();
	System.out.println("[INFO] Application reloading");
	webAppContext.stop();
	WebAppClassLoader classLoader = new WebAppClassLoader(webAppContext);
	classLoader.addClassPath(getAbsolutePath() + "target/classes");
	classLoader.addClassPath(getAbsolutePath() + "target/test-classes");
	webAppContext.setClassLoader(classLoader);
	webAppContext.start();
	System.out.println("[INFO] Application reloaded");
}
 
源代码12 项目: java-tutorial   文件: JettyFactory.java
public static void supportJspAndSetTldJarNames(Server server, String... jarNames) {
	WebAppContext context = (WebAppContext) server.getHandler();
	// This webapp will use jsps and jstl. We need to enable the
	// AnnotationConfiguration in
	// order to correctly set up the jsp container
	org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList
		.setServerDefault(server);
	classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
		"org.eclipse.jetty.annotations.AnnotationConfiguration");
	// Set the ContainerIncludeJarPattern so that jetty examines these container-path
	// jars for
	// tlds, web-fragments etc.
	// If you omit the jar that contains the jstl .tlds, the jsp engine will scan for
	// them
	// instead.

	List<String> list = new ArrayList<>();
	list.add(".*/[^/]*servlet-api-[^/]*\\.jar$");
	list.add(".*/javax.servlet.jsp.jstl-.*\\.jar$");
	list.add(".*/[^/]*taglibs.*\\.jar$");

	for (String jarName : jarNames) {
		String str = ".*/" + jarName + "-[^/]*\\.jar$";
		list.add(str);
	}

	context.setAttribute("org.eclipse.jetty.io.github.dunwu.javaee.server.webapp.ContainerIncludeJarPattern",
		StringUtils.join(list, '|'));
}
 
源代码13 项目: java-tutorial   文件: JettyFactory.java
public static void reloadWebAppContext(Server server) throws Exception {
	WebAppContext webAppContext = (WebAppContext) server.getHandler();
	System.out.println("[INFO] Application reloading");
	webAppContext.stop();
	WebAppClassLoader classLoader = new WebAppClassLoader(webAppContext);
	classLoader.addClassPath(getAbsolutePath() + "target/classes");
	classLoader.addClassPath(getAbsolutePath() + "target/test-classes");
	webAppContext.setClassLoader(classLoader);
	webAppContext.start();
	System.out.println("[INFO] Application reloaded");
}
 
源代码14 项目: java-tutorial   文件: JettyFactory.java
public static void reloadWebAppContext(Server server) throws Exception {
	WebAppContext webAppContext = (WebAppContext) server.getHandler();
	System.out.println("[INFO] Application reloading");
	webAppContext.stop();
	WebAppClassLoader classLoader = new WebAppClassLoader(webAppContext);
	classLoader.addClassPath(getAbsolutePath() + "target/classes");
	classLoader.addClassPath(getAbsolutePath() + "target/test-classes");
	webAppContext.setClassLoader(classLoader);
	webAppContext.start();
	System.out.println("[INFO] Application reloaded");
}
 
源代码15 项目: scheduling   文件: JettyStarter.java
private List<String> printDeployedApplications(Server server, String schedulerHost, int restPort,
        String httpProtocol) {
    HandlerList handlerList = (HandlerList) server.getHandler();
    ArrayList<String> applicationsUrls = new ArrayList<>();
    if (handlerList.getHandlers() != null) {
        for (Handler handler : handlerList.getHandlers()) {
            if (!(handler instanceof WebAppContext)) {
                continue;
            }

            WebAppContext webAppContext = (WebAppContext) handler;
            Throwable startException = webAppContext.getUnavailableException();
            if (startException == null) {
                if (!"/".equals(webAppContext.getContextPath())) {
                    String applicationUrl = getApplicationUrl(httpProtocol, schedulerHost, restPort, webAppContext);
                    applicationsUrls.add(applicationUrl);
                    logger.info("The web application " + webAppContext.getContextPath() + " created on " +
                                applicationUrl);
                }
            } else {
                logger.warn("Failed to start context " + webAppContext.getContextPath(), startException);
            }
        }
        logger.info("*** Get started at " + httpProtocol + "://" + schedulerHost + ":" + restPort + " ***");
    }
    return applicationsUrls;
}
 
源代码16 项目: java-tutorial   文件: JettyFactory.java
public static void reloadWebAppContext(Server server) throws Exception {
	WebAppContext webAppContext = (WebAppContext) server.getHandler();
	System.out.println("[INFO] Application reloading");
	webAppContext.stop();
	WebAppClassLoader classLoader = new WebAppClassLoader(webAppContext);
	classLoader.addClassPath(getAbsolutePath() + "target/classes");
	classLoader.addClassPath(getAbsolutePath() + "target/test-classes");
	webAppContext.setClassLoader(classLoader);
	webAppContext.start();
	System.out.println("[INFO] Application reloaded");
}
 
源代码17 项目: java-tutorial   文件: JettyFactory.java
public static void reloadWebAppContext(Server server) throws Exception {
	WebAppContext webAppContext = (WebAppContext) server.getHandler();
	System.out.println("[INFO] Application reloading");
	webAppContext.stop();
	WebAppClassLoader classLoader = new WebAppClassLoader(webAppContext);
	classLoader.addClassPath(getAbsolutePath() + "target/classes");
	classLoader.addClassPath(getAbsolutePath() + "target/test-classes");
	webAppContext.setClassLoader(classLoader);
	webAppContext.start();
	System.out.println("[INFO] Application reloaded");
}
 
源代码18 项目: java-tutorial   文件: JettyFactory.java
public static void reloadWebAppContext(Server server) throws Exception {
	WebAppContext webAppContext = (WebAppContext) server.getHandler();
	System.out.println("[INFO] Application reloading");
	webAppContext.stop();
	WebAppClassLoader classLoader = new WebAppClassLoader(webAppContext);
	classLoader.addClassPath(getAbsolutePath() + "target/classes");
	classLoader.addClassPath(getAbsolutePath() + "target/test-classes");
	webAppContext.setClassLoader(classLoader);
	webAppContext.start();
	System.out.println("[INFO] Application reloaded");
}
 
源代码19 项目: java-tutorial   文件: DevServer.java
private static void reloadWebAppContext(Server server) throws Exception {
    WebAppContext webAppContext = (WebAppContext) server.getHandler();
    System.out.println("[INFO] Application reloading");
    webAppContext.stop();
    WebAppClassLoader classLoader = new WebAppClassLoader(webAppContext);
    classLoader.addClassPath(getAbsolutePath() + "target/classes");
    classLoader.addClassPath(getAbsolutePath() + "target/test-classes");
    webAppContext.setClassLoader(classLoader);
    webAppContext.start();
    System.out.println("[INFO] Application reloaded");
}
 
源代码20 项目: java-tutorial   文件: JettyFactory.java
public static void reloadWebAppContext(Server server) throws Exception {
	WebAppContext webAppContext = (WebAppContext) server.getHandler();
	System.out.println("[INFO] Application reloading");
	webAppContext.stop();
	WebAppClassLoader classLoader = new WebAppClassLoader(webAppContext);
	classLoader.addClassPath(getAbsolutePath() + "target/classes");
	classLoader.addClassPath(getAbsolutePath() + "target/test-classes");
	webAppContext.setClassLoader(classLoader);
	webAppContext.start();
	System.out.println("[INFO] Application reloaded");
}