本文整理汇总了Java中org.eclipse.jetty.webapp.WebAppContext.setContextPath方法的典型用法代码示例。如果您正苦于以下问题:Java WebAppContext.setContextPath方法的具体用法?Java WebAppContext.setContextPath怎么用?Java WebAppContext.setContextPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.webapp.WebAppContext
的用法示例。
在下文中一共展示了WebAppContext.setContextPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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();
}
示例3: 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;
}
示例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: run
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
public void run( ) {
logger.info(masterConfig.toString());
try {
Server server = new Server(masterConfig.getWebServerPort());
WebAppContext context = new WebAppContext();
context.setDescriptor( masterConfig.getWebServerContentPath() + "/WEB-INF/web.xml" );
context.setResourceBase( masterConfig.getWebServerContentPath() );
context.setContextPath( masterConfig.getWebServerContextPath() );
context.setParentLoaderPriority(true);
server.setHandler(context);
logger.info("Starting");
server.start();
logger.info("Started");
server.join();
} catch( Exception e ) {
logger.error(e.getMessage(), e);
}
}
示例6: setupWebAppContext
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
private static WebAppContext setupWebAppContext(
ZeppelinConfiguration conf) {
WebAppContext webApp = new WebAppContext();
webApp.setContextPath(conf.getServerContextPath());
File warPath = new File(conf.getString(ConfVars.ZEPPELIN_WAR));
if (warPath.isDirectory()) {
// Development mode, read from FS
// webApp.setDescriptor(warPath+"/WEB-INF/web.xml");
webApp.setResourceBase(warPath.getPath());
webApp.setParentLoaderPriority(true);
} else {
// use packaged WAR
webApp.setWar(warPath.getAbsolutePath());
File warTempDirectory = new File(conf.getRelativeDir(ConfVars.ZEPPELIN_WAR_TEMPDIR));
warTempDirectory.mkdir();
LOG.info("ZeppelinServer Webapp path: {}", warTempDirectory.getPath());
webApp.setTempDirectory(warTempDirectory);
}
// Explicit bind to root
webApp.addServlet(new ServletHolder(new DefaultServlet()), "/*");
return webApp;
}
示例7: main
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
Properties p = PropertyUtil.loadProperties("/ws.properties");
System.out.println(JsonUtil.toJsonStr(p));
Server server = new Server(Integer.parseInt(p
.getProperty("webSocketPort")));
try {
HandlerList handlerList = new HandlerList();
/* websocket */
ServletContextHandler context = new ServletContextHandler(
ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.addServlet(
new ServletHolder(new Jwservlet(p
.getProperty("handlerClass"))), p
.getProperty("webSocketPath"));
/* webapp */
WebAppContext c = new WebAppContext();
c.setContextPath("/w");
c.setDescriptor("../websockets/WebRoot/WEB-INF/web.xml");
c.setResourceBase("../websockets/WebRoot");
handlerList.addHandler(c);
handlerList.addHandler(context);
handlerList.addHandler(new DefaultHandler());
server.setHandler(handlerList);
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: main
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(8080);
server.setConnectors(new Connector[]{connector});
WebAppContext context = new WebAppContext();
context.setServer(server);
context.setContextPath("/");
context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*taglibs.*\\.jar$");
context.setAttribute("org.eclipse.jetty.containerInitializers", jspInitializers());
context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
context.addBean(new ServletContainerInitializersStarter(context), true);
// Prevent loading of logging classes
context.getSystemClasspathPattern().add("org.apache.log4j.");
context.getSystemClasspathPattern().add("org.slf4j.");
context.getSystemClasspathPattern().add("org.apache.commons.logging.");
ProtectionDomain protectionDomain = EmbeddedJettyServer.class.getProtectionDomain();
URL location = protectionDomain.getCodeSource().getLocation();
context.setWar(location.toExternalForm());
server.setHandler(context);
try {
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
示例9: createDevServer
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
public static Server createDevServer() {
PlatformServerConfig.DEV_MODE = true;
Path projectPath = Paths.get(System.getProperty("user.dir")).toAbsolutePath();
Server jettyServer = new Server(8080);
WebAppContext context = new WebAppContext();
context.setContextPath("/BIMplatform");
context.setDescriptor(projectPath.resolve("WebContent/WEB-INF/web.xml").toAbsolutePath().toString()); // 指定web.xml配置文件
context.setResourceBase(projectPath.resolve("WebContent/").toAbsolutePath().toString());// 指定webapp目录
context.setParentLoaderPriority(true);
jettyServer.setHandler(context);
return jettyServer;
}
示例10: run
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
@Override
public void run() {
try {
Server server = new Server(port);
URL warUrl = DoctorKafkaWebServer.class.getClassLoader().getResource(WEBAPP_DIR);
if (warUrl == null) {
LOG.error("warUrl is null");
}
String warUrlString = warUrl.toExternalForm();
WebAppContext webapp = new WebAppContext();
webapp.addServlet(ClusterInfoServlet.class, "/servlet/clusterinfo");
webapp.addServlet(KafkaTopicStatsServlet.class, "/servlet/topicstats");
webapp.addServlet(DoctorKafkaActionsServlet.class, "/servlet/actions");
webapp.addServlet(DoctorKafkaInfoServlet.class, "/servlet/info");
webapp.addServlet(DoctorKafkaBrokerStatsServlet.class, "/servlet/brokerstats");
webapp.addServlet(UnderReplicatedPartitionsServlet.class, "/servlet/urp");
webapp.addServlet(OperatorIndexServlet.class, "/");
webapp.setContextPath("/");
webapp.setServer(server);
webapp.setWar(warUrlString);
server.setHandler(webapp);
server.start();
if (LOG.isDebugEnabled()) {
server.dumpStdErr();
}
server.join();
} catch (Exception e) {
LOG.error("Exception in KafkaOperatorWebServer.", e);
}
}
示例11: startServer
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
/**
* Method for starting the Jetty server with the ATS Agent webapp.
* @param port the port on which to start the server.
* @return the started server.
* @throws IOException
*/
private static Server startServer() throws IOException {
addAppender();
final int agentPort = getAgentDefaultPort();
log.info("Starting ATS agent at port: " + agentPort);
final String jettyHome = getJettyHome();
logSystemInformation(jettyHome);
// start the server
Connector connector = new SelectChannelConnector();
connector.setPort(agentPort);
Server server = new Server();
server.setConnectors(new Connector[]{ connector });
WebAppContext webApp = new WebAppContext();
webApp.setContextPath("/agentapp");
webApp.setWar(jettyHome + "/webapp/agentapp.war");
server.setHandler(webApp);
server.setStopAtShutdown(true);
setExtraClasspath(webApp, jettyHome);
try {
server.start();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
log.info("ATS agent started");
return server;
}
示例12: createServer
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
public static Server createServer(int port) {
WebAppContext context = new WebAppContext();
context.setContextPath("/");
context.setResourceBase(WEBAPP);
context.setConfigurations(new Configuration[] { new JettyAnnotationConfiguration() });
// Create server and configure it
final Server server = new Server(port);
server.setHandler(context);
return server;
}
示例13: beforeClass
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() throws Exception {
/*
* This runs under maven, and I'm not sure how else to figure out the target directory from code..
*/
String path = ExampleServerIT.class.getClassLoader().getResource(".keep_hapi-fhir-jpaserver-example").getPath();
path = new File(path).getParent();
path = new File(path).getParent();
path = new File(path).getParent();
ourLog.info("Project base path is: {}", path);
ourPort = RandomServerPortProvider.findFreePort();
ourServer = new Server(ourPort);
WebAppContext webAppContext = new WebAppContext();
webAppContext.setContextPath("/");
webAppContext.setDescriptor(path + "/src/main/webapp/WEB-INF/web.xml");
webAppContext.setResourceBase(path + "/target/hapi-fhir-jpaserver-example");
webAppContext.setParentLoaderPriority(true);
ourServer.setHandler(webAppContext);
ourServer.start();
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
ourServerBase = "http://localhost:" + ourPort + "/baseDstu2";
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
ourClient.registerInterceptor(new LoggingInterceptor(true));
}
示例14: createWebApp
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
/**
* Creates a web-app deployment for a war file gives as path
* @param webappWar
* path to the war file
* @return
* a webApplication context that can be deployed on the jetty server.
*/
private static WebAppContext createWebApp(final Path webappWar) throws IOException {
// Path tempWar = Files.createTempFile("bdj-", webappWar.getFileName().toString());
// LOG.info("Creating temporary copy of war " + tempWar);
// Files.copy(webappWar, tempWar, StandardCopyOption.REPLACE_EXISTING);
// LOG.info("Deploying web app from " + tempWar);
final WebAppContext webapp = new WebAppContext();
webapp.setSystemClasses(new String[] {
Configuration.class.getName(), ConfigChangeListener.class.getName()
});
webapp.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$");
/*
* Configure the application to support the compilation of JSP files.
* We need a new class loader and some stuff so that Jetty can call the
* onStartup() methods as required.
*/
webapp.setAttribute("org.eclipse.jetty.containerInitializers", jspInitializers());
webapp.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
webapp.addBean(new ServletContainerInitializersStarter(webapp), true);
webapp.setContextPath("/");
webapp.setWar(webappWar.toString());
return webapp;
}
示例15: loadWar
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
private WebAppContext loadWar(final File warFile, final String contextPath) throws IOException {
final WebAppContext webappContext = new WebAppContext(warFile.getPath(), contextPath);
webappContext.setContextPath(contextPath);
webappContext.setDisplayName(contextPath);
// remove slf4j server class to allow WAR files to have slf4j dependencies in WEB-INF/lib
List<String> serverClasses = new ArrayList<>(Arrays.asList(webappContext.getServerClasses()));
serverClasses.remove("org.slf4j.");
webappContext.setServerClasses(serverClasses.toArray(new String[0]));
webappContext.setDefaultsDescriptor(WEB_DEFAULTS_XML);
// get the temp directory for this webapp
final File webWorkingDirectory = properties.getWebWorkingDirectory();
final File tempDir = new File(webWorkingDirectory, warFile.getName());
if (tempDir.exists() && !tempDir.isDirectory()) {
throw new RuntimeException(tempDir.getAbsolutePath() + " is not a directory");
} else if (!tempDir.exists()) {
final boolean made = tempDir.mkdirs();
if (!made) {
throw new RuntimeException(tempDir.getAbsolutePath() + " could not be created");
}
}
if (!(tempDir.canRead() && tempDir.canWrite())) {
throw new RuntimeException(tempDir.getAbsolutePath() + " directory does not have read/write privilege");
}
// configure the temp dir
webappContext.setTempDirectory(tempDir);
// configure the max form size (3x the default)
webappContext.setMaxFormContentSize(600000);
webappContext.setClassLoader(new WebAppClassLoader(ClassLoader.getSystemClassLoader(), webappContext));
logger.info("Loading WAR: " + warFile.getAbsolutePath() + " with context path set to " + contextPath);
return webappContext;
}