本文整理汇总了Java中org.eclipse.jetty.webapp.WebAppContext.addServlet方法的典型用法代码示例。如果您正苦于以下问题:Java WebAppContext.addServlet方法的具体用法?Java WebAppContext.addServlet怎么用?Java WebAppContext.addServlet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.webapp.WebAppContext
的用法示例。
在下文中一共展示了WebAppContext.addServlet方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initWebApp
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
private WebAppContext initWebApp() throws IOException {
WebAppContext ctx = new WebAppContext();
ctx.setContextPath(CONFIG.getContextPath());
ctx.setResourceBase(new ClassPathResource("webapp").getURI().toString());
// Disable directory listings if no index.html is found.
ctx.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
ServletHolder web = new ServletHolder("spring-dispatcher", new DispatcherServlet(springContext));
ServletHolder cxf = new ServletHolder("cxf", new CXFServlet());
ctx.addEventListener(new ContextLoaderListener(springContext));
ctx.addServlet(web, CONFIG.getSpringMapping());
ctx.addServlet(cxf, CONFIG.getCxfMapping());
if (CONFIG.getProfile().isProd()) {
addSecurityFilter(ctx);
}
initJSP(ctx);
return ctx;
}
示例2: 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;
}
示例3: configureWebAppContext
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
@Override
protected void configureWebAppContext(WebAppContext webAppContext)
{
super.configure(webAppContext);
// the Chemistry OpenCMIS servlet
ServletHolder servletHolder = new ServletHolder(CmisAtomPubServlet.class);
servletHolder.setInitParameter("callContextHandler", "org.apache.chemistry.opencmis.server.shared.BasicAuthCallContextHandler");
webAppContext.addServlet(servletHolder, "/cmisatom/*");
}
示例4: configureWebAppContext
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
@Override
protected void configureWebAppContext(WebAppContext webAppContext)
{
super.configureWebAppContext(webAppContext);
// the tenant servlet with alfresco managed authentication
ServletHolder servletHolder = new ServletHolder(CmisAtomPubServlet.class);
servletHolder.setInitParameter("callContextHandler", "org.apache.chemistry.opencmis.server.shared.BasicAuthCallContextHandler");
webAppContext.addServlet(servletHolder, "/cmisatom/*");
}
示例5: 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);
}
}
示例6: start
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
public void start(boolean devMode, int port) throws Exception {
Server server = new Server(new QueuedThreadPool(500));
WebAppContext appContext = new WebAppContext();
String resourceBasePath = "";
//开发者模式
if (devMode) {
String artifact = MavenUtils.get(Thread.currentThread().getContextClassLoader()).getArtifactId();
resourceBasePath = artifact + "/src/main/webapp";
}
appContext.setDescriptor(resourceBasePath + "WEB-INF/web.xml");
appContext.setResourceBase(resourceBasePath);
appContext.setExtractWAR(true);
//init param
appContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
if (CommonUtils.isWindowOs()) {
appContext.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
}
//for jsp support
appContext.addBean(new JettyJspParser(appContext));
appContext.addServlet(JettyJspServlet.class, "*.jsp");
appContext.setContextPath("/");
appContext.getServletContext().setExtendedListenerTypes(true);
appContext.setParentLoaderPriority(true);
appContext.setThrowUnavailableOnStartupException(true);
appContext.setConfigurationDiscovered(true);
appContext.setClassLoader(Thread.currentThread().getContextClassLoader());
ServerConnector connector = new ServerConnector(server);
connector.setHost("0.0.0.0");
connector.setPort(port);
server.setConnectors(new Connector[]{connector});
server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", 1024 * 1024 * 1024);
server.setDumpAfterStart(false);
server.setDumpBeforeStop(false);
server.setStopAtShutdown(true);
server.setHandler(appContext);
logger.info("[opencron] JettyLauncher starting...");
server.start();
}
示例7: run
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
public static Server run(ResourceConfig application, Properties properties, int port, String originFilter,
String aliasName, File keystoreFile, String password, String frontendRoot, String apiPathPattern, boolean copyWebDir) {
try {
QueuedThreadPool threadPool = new QueuedThreadPool(
Integer.valueOf(properties.getProperty("jetty.maxThreads")),
Integer.valueOf(properties.getProperty("jetty.minThreads")),
Integer.valueOf(properties.getProperty("jetty.idleTimeout")),
new ArrayBlockingQueue<>(Integer.valueOf(properties.getProperty("jetty.maxQueueSize"))));
Server server = new Server(threadPool);
HttpConfiguration config = new HttpConfiguration();
if (keystoreFile != null) {
log.info("Jetty runner {}. SSL enabled.", application.getClass());
SslContextFactory sslFactory = new SslContextFactory();
sslFactory.setCertAlias(aliasName);
String path = keystoreFile.getAbsolutePath();
if (!keystoreFile.exists()) {
log.error("Couldn't load keystore file: {}", path);
return null;
}
sslFactory.setKeyStorePath(path);
sslFactory.setKeyStorePassword(password);
sslFactory.setKeyManagerPassword(password);
sslFactory.setTrustStorePath(path);
sslFactory.setTrustStorePassword(password);
config.setSecureScheme("https");
config.setSecurePort(port);
config.addCustomizer(new SecureRequestCustomizer());
ServerConnector https = new ServerConnector(server,
new SslConnectionFactory(sslFactory, "http/1.1"),
new HttpConnectionFactory(config));
https.setPort(port);
server.setConnectors(new Connector[]{https});
} else {
ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(config));
http.setPort(port);
server.setConnectors(new Connector[]{http});
}
Handler handler = ContainerFactory.createContainer(JettyHttpContainer.class, application);
if (originFilter != null)
handler = new CrossDomainFilter(handler, originFilter);
if (frontendRoot != null) {
WebAppContext htmlHandler = new WebAppContext();
htmlHandler.setResourceBase(frontendRoot);
htmlHandler.setCopyWebDir(copyWebDir);
Map<Pattern, Handler> pathToHandler = new HashMap<>();
pathToHandler.put(Pattern.compile(apiPathPattern), handler);
SessionManager sm = new HashSessionManager();
SessionHandler sh = new SessionHandler(sm);
htmlHandler.setSessionHandler(sh);
DefaultServlet defaultServlet = new DefaultServlet();
ServletHolder holder = new ServletHolder(defaultServlet);
holder.setInitParameter("useFileMappedBuffer", Boolean.toString(!copyWebDir));
holder.setInitParameter("cacheControl", "no-store,no-cache,must-revalidate,max-age=-1,public");
htmlHandler.addServlet(holder, "/");
handler = new RequestsRouter(htmlHandler, pathToHandler, frontendRoot);
}
server.setHandler(handler);
server.start();
while (!server.isStarted()) {
Thread.sleep(50);
}
log.info("Jetty server started {} on port {}", application.getClass(), port);
return server;
} catch (Exception e) {
log.error(String.format("Jetty start failed %s.", application.getClass()), e);
return null;
}
}
示例8: build
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
/**
* 创建用于正常运行调试的Jetty Server, 以src/main/webapp为Web应用目录.
*/
@Override
public Server build(int port, String webApp, String contextPath) throws BindException {
port = this.getAutoPort(port);
serverInitializer.run();
Server server = new Server(port);
WebAppContext webContext = new WebAppContext(webApp, contextPath);
if (false) {
ServletHolder holder = new ServletHolder(new ProxyServlet());
holder.setInitParameter("proxyTo", "http://localhost:3000/");
holder.setInitParameter("prefix", "/");
webContext.addServlet(holder, "/app/");
webContext.addServlet(new ServletHolder(new IndexServlet()), "/proxy/");
}
// webContext.setDefaultsDescriptor("leopard-jetty/webdefault.xml");
// 问题点:http://stackoverflow.com/questions/13222071/spring-3-1-webapplicationinitializer-embedded-jetty-8-annotationconfiguration
webContext.setConfigurations(new Configuration[] { //
new EmbedWebInfConfiguration(), //
new MetaInfConfiguration(), //
new AnnotationConfiguration(), //
new WebXmlConfiguration(), //
new FragmentConfiguration() //
// new TagLibConfiguration() //
});
// webContext.setConfigurations(new Configuration[] { //
// new EmbedWebInfConfiguration()//
// , new EmbedWebXmlConfiguration()//
// , new EmbedMetaInfConfiguration()//
// , new EmbedFragmentConfiguration()//
// , new EmbedAnnotionConfiguration() //
// // , new PlusConfiguration(),//
// // new EnvConfiguration()//
// });
WebAppClassLoader classLoader = null;
try {
// addTldLib(webContext);
classLoader = new LeopardWebAppClassLoader(webContext);
}
catch (IOException e) {
e.printStackTrace();
}
// ClassLoader tldClassLoader = addTldLib(classLoader);
webContext.setClassLoader(classLoader);
webContext.setParentLoaderPriority(true);
// logger.debug(webContext.dump());
Handler rewriteHandler = ResourcesManager.getHandler();
if (rewriteHandler == null) {
server.setHandler(webContext);
}
else {
HandlerCollection handlers = new HandlerCollection();
handlers.addHandler(rewriteHandler);
handlers.addHandler(webContext);
server.setHandler(handlers);
}
server.setStopAtShutdown(true);
return server;
}