本文整理了Java中org.apache.catalina.startup.Tomcat.addContext()
方法的一些代码示例,展示了Tomcat.addContext()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tomcat.addContext()
方法的具体详情如下:
包路径:org.apache.catalina.startup.Tomcat
类名称:Tomcat
方法名:addContext
[英]Add a context - programmatic mode, no default web.xml used. This means that there is no JSP support (no JSP servlet), no default servlet and no web socket support unless explicitly enabled via the programmatic interface. There is also no javax.servlet.ServletContainerInitializer processing and no annotation processing. If a javax.servlet.ServletContainerInitializer is added programmatically, there will still be no scanning for javax.servlet.annotation.HandlesTypes matches. API calls equivalent with web.xml: context-param ctx.addParameter("name", "value"); error-page ErrorPage ep = new ErrorPage(); ep.setErrorCode(500); ep.setLocation("/error.html"); ctx.addErrorPage(ep); ctx.addMimeMapping("ext", "type"); Note: If you reload the Context, all your configuration will be lost. If you need reload support, consider using a LifecycleListener to provide your configuration. TODO: add the rest
[中]添加上下文编程模式,无默认web。使用xml。这意味着没有JSP支持(没有JSP servlet),没有默认servlet,也没有web套接字支持,除非通过编程接口显式启用。也没有javax。servlet。ServletContainerInitializer处理,不进行注释处理。如果是javax。servlet。ServletContainerInitializer是以编程方式添加的,仍然不会扫描javax。servlet。注释。手型匹配。API调用与web相当。xml:context-param-ctx。addParameter(“名称”、“值”);error page ErrorPage ep=新建ErrorPage();ep。设置错误代码(500);ep。setLocation(“/error.html”);ctx。addErrorPage(ep);ctx。addMimeMapping(“ext”、“type”);注意:如果重新加载上下文,所有配置都将丢失。如果需要重新加载支持,请考虑使用LIFECKEYLististor提供配置。TODO:把剩下的加起来
代码示例来源:origin: spring-projects/spring-framework
@Override
protected void initServer() throws Exception {
this.tomcatServer = new Tomcat();
this.tomcatServer.setBaseDir(baseDir);
this.tomcatServer.setHostname(getHost());
this.tomcatServer.setPort(getPort());
ServletHttpHandlerAdapter servlet = initServletAdapter();
File base = new File(System.getProperty("java.io.tmpdir"));
Context rootContext = tomcatServer.addContext(this.contextPath, base.getAbsolutePath());
Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet).setAsyncSupported(true);
rootContext.addServletMappingDecoded(this.servletMapping, "httpHandlerServlet");
if (wsListener != null) {
rootContext.addApplicationListener(wsListener.getName());
}
}
代码示例来源:origin: apache/incubator-dubbo
tomcat.getConnector().setProtocol("org.apache.coyote.http11.Http11NioProtocol");
Context context = tomcat.addContext("/", baseDir);
Tomcat.addServlet(context, "dispatcher", new DispatcherServlet());
context.addServletMapping("/*", "dispatcher");
代码示例来源:origin: apache/incubator-dubbo
tomcat.getConnector().setProtocol("org.apache.coyote.http11.Http11NioProtocol");
Context context = tomcat.addContext("/", baseDir);
Tomcat.addServlet(context, "dispatcher", new DispatcherServlet());
context.addServletMapping("/*", "dispatcher");
代码示例来源:origin: spring-projects/spring-framework
@Override
public void deployConfig(WebApplicationContext wac, Filter... filters) {
Assert.state(this.port != -1, "setup() was never called.");
this.context = this.tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
this.context.addApplicationListener(WsContextListener.class.getName());
Tomcat.addServlet(this.context, "dispatcherServlet", new DispatcherServlet(wac)).setAsyncSupported(true);
this.context.addServletMappingDecoded("/", "dispatcherServlet");
for (Filter filter : filters) {
FilterDef filterDef = new FilterDef();
filterDef.setFilterName(filter.getClass().getName());
filterDef.setFilter(filter);
filterDef.setAsyncSupported("true");
this.context.addFilterDef(filterDef);
FilterMap filterMap = new FilterMap();
filterMap.setFilterName(filter.getClass().getName());
filterMap.addURLPattern("/*");
filterMap.setDispatcher("REQUEST,FORWARD,INCLUDE,ASYNC");
this.context.addFilterMap(filterMap);
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
tomcat.setPort(0);
tomcat.setBaseDir(path);
Context ctx = tomcat.addContext("", path);
代码示例来源:origin: OryxProject/oryx
Files.createDirectories(contextPath);
context = tomcat.addContext(contextPathURIBase, contextPath.toAbsolutePath().toString());
代码示例来源:origin: AsyncHttpClient/async-http-client
tomcat.setPort(0);
tomcat.setBaseDir(path);
Context ctx = tomcat.addContext("", path);
代码示例来源:origin: org.apache.tomcat/tomcat-catalina
/**
* @param host The host in which the context will be deployed
* @param contextPath The context mapping to use, "" for root context.
* @param dir Base directory for the context, for static files.
* Must exist, relative to the server home
* @return the deployed context
* @see #addContext(String, String)
*/
public Context addContext(Host host, String contextPath, String dir) {
return addContext(host, contextPath, contextPath, dir);
}
代码示例来源:origin: pippo-java/pippo
Context context = tomcat.addContext(getSettings().getContextPath(), docBase.getAbsolutePath());
context.setAllowCasualMultipartParsing(true);
PippoServlet pippoServlet = new PippoServlet();
代码示例来源:origin: codefollower/Tomcat-Research
/**
* @see #addContext(String, String)
*/
public Context addContext(Host host, String contextPath, String dir) {
return addContext(host, contextPath, contextPath, dir);
}
代码示例来源:origin: org.ops4j.pax.tipi/org.ops4j.pax.tipi.tomcat-embed-core
/**
* @param host The host in which the context will be deployed
* @param contextPath The context mapping to use, "" for root context.
* @param dir Base directory for the context, for static files.
* Must exist, relative to the server home
* @return the deployed context
* @see #addContext(String, String)
*/
public Context addContext(Host host, String contextPath, String dir) {
return addContext(host, contextPath, contextPath, dir);
}
代码示例来源:origin: spring-projects/spring-integration
public TomcatWebSocketTestServer(Class<?>... serverConfigs) {
this.tomcatServer = new Tomcat();
this.tomcatServer.setPort(0);
this.tomcatServer.setBaseDir(createTempDir());
this.serverContext = new AnnotationConfigWebApplicationContext();
this.serverContext.register(serverConfigs);
Context context = this.tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
context.addApplicationListener(WsContextListener.class.getName());
Tomcat.addServlet(context, "dispatcherServlet", new DispatcherServlet(this.serverContext))
.setAsyncSupported(true);
context.addServletMappingDecoded("/", "dispatcherServlet");
}
代码示例来源:origin: stackoverflow.com
Tomcat tomcat = new Tomcat();
// this defines Tomcat's working directory
File base = new File(System.getProperty("java.io.tmpdir"));
Context rootContext = tomcat.addContext("", base.getAbsolutePath());
// more configuration ...
代码示例来源:origin: spring-projects/spring-restdocs
@Override
protected void before() throws LifecycleException {
this.tomcat = new Tomcat();
this.tomcat.getConnector().setPort(0);
Context context = this.tomcat.addContext("/", null);
this.tomcat.addServlet("/", "test", new TestServlet());
context.addServletMappingDecoded("/", "test");
this.tomcat.addServlet("/", "set-cookie", new CookiesServlet());
context.addServletMappingDecoded("/set-cookie", "set-cookie");
this.tomcat.start();
this.port = this.tomcat.getConnector().getLocalPort();
}
代码示例来源:origin: stackoverflow.com
Tomcat tomcat = new Tomcat();
// skipping a few steps
Context ctx = tomcat.addContext(contextPath, baseDir);
ServletContext sc = ctx.getServletContext();
代码示例来源:origin: org.nuxeo.runtime/nuxeo-runtime-server
protected Context getContextForPath(String contextPath) {
contextPath = normalizeContextPath(contextPath);
Context context = (Context) tomcat.getHost().findChild(contextPath);
if (context == null) {
context = tomcat.addContext(contextPath, null);
}
return context;
}
代码示例来源:origin: com.bsb.common.vaadin/com.bsb.common.vaadin7.embed
/**
* Returns the {@link Context} to use for the webapp.
*/
protected Context getContext() {
if (context == null) {
context = getTomcat().addContext(getConfig().getContextPath(),
getConfig().getContextRootDirectory().getAbsolutePath());
}
return context;
}
代码示例来源:origin: fabric8io/shootout-docker-maven
public static void main(String[] args) throws LifecycleException, SQLException {
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
File base = new File(System.getProperty("java.io.tmpdir"));
Context rootCtx = tomcat.addContext("/", base.getAbsolutePath());
Tomcat.addServlet(rootCtx, "log", new LogService());
rootCtx.addServletMapping("/*", "log");
tomcat.start();
tomcat.getServer().await();
}
代码示例来源:origin: hantsy/spring-reactive-sample
@Bean
public Tomcat embededTomcatServer(ApplicationContext context) throws Exception {
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
// Tomcat and Jetty (also see notes below)
Servlet servlet = new TomcatHttpHandlerAdapter(handler);
Tomcat tomcatServer = new Tomcat();
tomcatServer.setHostname("localhost");
tomcatServer.setPort(this.port);
Context rootContext = tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
rootContext.addServletMappingDecoded("/", "httpHandlerServlet");
return tomcatServer;
}
代码示例来源:origin: poutsma/web-function-sample
public void startTomcatServer() throws LifecycleException {
RouterFunction<?> route = routingFunction();
HttpHandler httpHandler = toHttpHandler(route);
Tomcat tomcatServer = new Tomcat();
tomcatServer.setHostname(HOST);
tomcatServer.setPort(PORT);
Context rootContext = tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);
Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
rootContext.addServletMapping("/", "httpHandlerServlet");
tomcatServer.start();
}
内容来源于网络,如有侵权,请联系作者删除!