本文整理汇总了Java中org.eclipse.jetty.webapp.WebAppContext类的典型用法代码示例。如果您正苦于以下问题:Java WebAppContext类的具体用法?Java WebAppContext怎么用?Java WebAppContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebAppContext类属于org.eclipse.jetty.webapp包,在下文中一共展示了WebAppContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initNiucloud
import org.eclipse.jetty.webapp.WebAppContext; //导入依赖的package包/类
protected void initNiucloud(WebAppContext context) {
String filename = war.replace("\\", "/");
Pattern p = Pattern.compile("/data/src/(.*?)/");
Matcher m = p.matcher(filename);
if (!m.find()) {
throw new RuntimeException("解析projectId出错[" + war + "].");
}
String projectId = m.group(1);
String className = "io.xiaoniu.niujetty.datasource.InitRunnable";
try {
Class<?> clazz = ((WebAppClassLoader) context.getClassLoader()).loadClass(className);
Runnable runnable = (Runnable) clazz.newInstance();
Method method = clazz.getDeclaredMethod("setProjectId", String.class);
method.invoke(runnable, projectId);
runnable.run();
}
catch (Exception e) {
// e.printStackTrace();
}
}
示例2: beforeClass
import org.eclipse.jetty.webapp.WebAppContext; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() throws Exception {
jettyServer = new Server(0);
WebAppContext webApp = new WebAppContext();
webApp.setServer(jettyServer);
webApp.setContextPath(CONTEXT_PATH);
webApp.setWar("src/test/webapp");
jettyServer.setHandler(webApp);
jettyServer.start();
serverPort = ((ServerConnector)jettyServer.getConnectors()[0]).getLocalPort();
testRestTemplate = new TestRestTemplate(new RestTemplateBuilder()
.rootUri("http://localhost:" + serverPort + CONTEXT_PATH));
}
示例3: startServer
import org.eclipse.jetty.webapp.WebAppContext; //导入依赖的package包/类
public static void startServer(String[] args) throws Exception {
Server server = new Server(8080);
WebAppContext ctx = new WebAppContext();
ctx.setContextPath("/");
ctx.setWar("src/main/webapp/");
HandlerCollection hc = new HandlerCollection();
hc.setHandlers(new Handler[] {ctx});
server.setHandler(hc);
server.setStopAtShutdown(true);
server.start();
server.join();
// server.removeBean(o);
// server.addBean(o);
}
示例4: startJettyServer
import org.eclipse.jetty.webapp.WebAppContext; //导入依赖的package包/类
/**
* 启动jetty服务,加载server.war
*/
public static void startJettyServer(String path) throws Exception{
String configPath=path+ File.separator+"conf"+File.separator+"conf.properties";
InputStream is = new FileInputStream(configPath);;
Properties properties =new Properties();
properties.load(is);
is.close();
int serverPort = Integer.parseInt(properties.getProperty("server.port"));
Server server = new Server(serverPort);
WebAppContext context = new WebAppContext();
context.setContextPath("/");
context.setWar(path+"/bin/service.war");
server.setHandler(context);
server.start();
server.join();
}
示例5: start
import org.eclipse.jetty.webapp.WebAppContext; //导入依赖的package包/类
public void start() throws Exception
{
String relativelyPath = System.getProperty("user.dir");
server = new Server(port);
WebAppContext webAppContext = new WebAppContext();
webAppContext.setContextPath("/");
webAppContext.setWar(relativelyPath + "\\rainbow-web\\target\\rainbow-web.war");
webAppContext.setParentLoaderPriority(true);
webAppContext.setServer(server);
webAppContext.setClassLoader(ClassLoader.getSystemClassLoader());
webAppContext.getSessionHandler().getSessionManager()
.setMaxInactiveInterval(10);
server.setHandler(webAppContext);
server.start();
}
示例6: restartWebServer
import org.eclipse.jetty.webapp.WebAppContext; //导入依赖的package包/类
private static void restartWebServer(final Server server, final WebAppContext webApp) throws Exception {
//TODO reconsider restart function
/*
restart doesnt help much regarding heap configuration, everything else can be configured at
runtime. So better approach for convenient restart would be an orderly shutdown and start.
*/
server.stop();
LOG.info("Sent stop");
server.join();
LOG.info("Server joined");
LOG.info("Starting web server");
server.setHandler(webApp);
server.start();
LOG.info("Server restarted");
}
示例7: start
import org.eclipse.jetty.webapp.WebAppContext; //导入依赖的package包/类
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!");
}
}
示例8: addWebApplication
import org.eclipse.jetty.webapp.WebAppContext; //导入依赖的package包/类
public static Server addWebApplication(final Server jetty, final String webAppContext,
final String warFilePath) {
WebAppContext webapp = new WebAppContext();
webapp.setContextPath(webAppContext);
webapp.setWar(warFilePath);
webapp.setParentLoaderPriority(false);
webapp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
File tmpPath = new File(getWebAppBaseDirectory(webAppContext));
tmpPath.mkdirs();
webapp.setTempDirectory(tmpPath);
((HandlerCollection) jetty.getHandler()).addHandler(webapp);
return jetty;
}
示例9: onAppStarting
import org.eclipse.jetty.webapp.WebAppContext; //导入依赖的package包/类
/**
* onAppStarting
*
* @param args
*/
public void onAppStarting(Object... args) {
WebAppContext sc = (WebAppContext) args[0];
InterceptSupport iSupport = InterceptSupport.instance();
InterceptContext context = iSupport.createInterceptContext(Event.WEBCONTAINER_INIT);
context.put(InterceptConstants.WEBAPPLOADER, sc.getClassLoader());
context.put(InterceptConstants.WEBWORKDIR, sc.getServletContext().getRealPath(""));
context.put(InterceptConstants.CONTEXTPATH, sc.getContextPath());
context.put(InterceptConstants.APPNAME, sc.getDisplayName());
ServletContext sContext = sc.getServletContext();
context.put(InterceptConstants.SERVLET_CONTEXT, sContext);
getBasePath(context, sContext);
iSupport.doIntercept(context);
}
示例10: onAppStop
import org.eclipse.jetty.webapp.WebAppContext; //导入依赖的package包/类
/**
* onAppStop
*
* @param args
*/
public void onAppStop(Object... args) {
System.out.println("---------------->onAppStop");
WebAppContext sc = getWebAppContext(args);
if (sc == null) {
return;
}
InterceptSupport iSupport = InterceptSupport.instance();
InterceptContext context = iSupport.createInterceptContext(Event.WEBCONTAINER_STOPPED);
context.put(InterceptConstants.WEBAPPLOADER, sc.getClassLoader());
context.put(InterceptConstants.WEBWORKDIR, sc.getServletContext().getRealPath(""));
context.put(InterceptConstants.CONTEXTPATH, sc.getContextPath());
context.put(InterceptConstants.APPNAME, sc.getDisplayName());
ServletContext sContext = sc.getServletContext();
context.put(InterceptConstants.SERVLET_CONTEXT, sContext);
getBasePath(context, sContext);
iSupport.doIntercept(context);
}
示例11: start
import org.eclipse.jetty.webapp.WebAppContext; //导入依赖的package包/类
public void start() {
// TODO: remove redundant fields from config and move this check to XRE Redirector
if (! config.getEnableCommunicationEndpoint()) {
log.warn("skipping Jetty endpoint due to configuration");
return;
}
if (started) {
log.warn("Jetty is already started");
}
started = true;
Integer port = config.getCommunicationEndpointPort();
log.info("Starting embedded jetty server (XRERedirector Gateway) on port: {}", port);
WebAppContext webAppContext = new WebAppContext();
webAppContext.setConfigurations(new Configuration[]{new AnnotationConfiguration() {
@Override
public void preConfigure(WebAppContext context) {
ClassInheritanceMap map = new ClassInheritanceMap();
map.put(WebApplicationInitializer.class.getName(), new ConcurrentHashSet<String>() {{
add(WebAppInitializer.class.getName());
}});
context.setAttribute(CLASS_INHERITANCE_MAP, map);
_classInheritanceHandler = new ClassInheritanceHandler(map);
}
}});
server = new Server(port);
server.setHandler(webAppContext);
try {
server.start();
} catch (Exception e) {
log.error("Failed to start embedded jetty server (XRERedirector communication endpoint) on port: " + port, e);
}
log.info("Started embedded jetty server (Redirector Gateway) on port: {}", port);
}
示例12: createJettyServer
import org.eclipse.jetty.webapp.WebAppContext; //导入依赖的package包/类
public static Server createJettyServer(int port, String contextPath) {
Server server = new Server(port);
server.setStopAtShutdown(true);
ProtectionDomain protectionDomain = Launcher.class.getProtectionDomain();
URL location = protectionDomain.getCodeSource().getLocation();
String warFile = location.toExternalForm();
WebAppContext context = new WebAppContext(warFile, contextPath);
context.setServer(server);
// 设置work dir,war包将解压到该目录,jsp编译后的文件也将放入其中。
String currentDir = new File(location.getPath()).getParent();
File workDir = new File(currentDir, "work");
context.setTempDirectory(workDir);
server.setHandler(context);
return server;
}
示例13: createDevServer
import org.eclipse.jetty.webapp.WebAppContext; //导入依赖的package包/类
public static Server createDevServer(int port, String contextPath) {
Server server = new Server();
server.setStopAtShutdown(true);
ServerConnector connector = new ServerConnector(server);
// 设置服务端口
connector.setPort(port);
connector.setReuseAddress(false);
server.setConnectors(new Connector[] {connector});
// 设置web资源根路径以及访问web的根路径
WebAppContext webAppCtx = new WebAppContext(DEFAULT_APP_CONTEXT_PATH, contextPath);
webAppCtx.setDescriptor(DEFAULT_APP_CONTEXT_PATH + "/WEB-INF/web.xml");
webAppCtx.setResourceBase(DEFAULT_APP_CONTEXT_PATH);
webAppCtx.setClassLoader(Thread.currentThread().getContextClassLoader());
server.setHandler(webAppCtx);
return server;
}
示例14: start
import org.eclipse.jetty.webapp.WebAppContext; //导入依赖的package包/类
public void start() {
try {
// start the server
server.start();
// ensure everything started successfully
for (Handler handler : server.getChildHandlers()) {
// see if the handler is a web app
if (handler instanceof WebAppContext) {
WebAppContext context = (WebAppContext) handler;
// see if this webapp had any exceptions that would
// cause it to be unavailable
if (context.getUnavailableException() != null) {
startUpFailure(context.getUnavailableException());
}
}
}
dumpUrls();
} catch (final Throwable t) {
startUpFailure(t);
}
}
示例15: configureWebAppContext
import org.eclipse.jetty.webapp.WebAppContext; //导入依赖的package包/类
/**
* Configure the given Jetty {@link WebAppContext} for use.
* @param context the context to configure
* @param initializers the set of initializers to apply
*/
protected final void configureWebAppContext(WebAppContext context,
ServletContextInitializer... initializers) {
Assert.notNull(context, "Context must not be null");
context.setTempDirectory(getTempDirectory());
if (this.resourceLoader != null) {
context.setClassLoader(this.resourceLoader.getClassLoader());
}
String contextPath = getContextPath();
context.setContextPath(StringUtils.hasLength(contextPath) ? contextPath : "/");
context.setDisplayName(getDisplayName());
configureDocumentRoot(context);
if (isRegisterDefaultServlet()) {
addDefaultServlet(context);
}
if (shouldRegisterJspServlet()) {
addJspServlet(context);
}
ServletContextInitializer[] initializersToUse = mergeInitializers(initializers);
Configuration[] configurations = getWebAppContextConfigurations(context,
initializersToUse);
context.setConfigurations(configurations);
configureSession(context);
postProcessWebAppContext(context);
}