@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()); } }
tomcat.getConnector().setProtocol("org.apache.coyote.http11.Http11NioProtocol"); Context context = tomcat.addContext("/", baseDir); Tomcat.addServlet(context, "dispatcher", new DispatcherServlet()); context.addServletMapping("/*", "dispatcher");
tomcat.getConnector().setProtocol("org.apache.coyote.http11.Http11NioProtocol"); Context context = tomcat.addContext("/", baseDir); Tomcat.addServlet(context, "dispatcher", new DispatcherServlet()); context.addServletMapping("/*", "dispatcher");
@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); } }
tomcat.setPort(0); tomcat.setBaseDir(path); Context ctx = tomcat.addContext("", path);
Files.createDirectories(contextPath); context = tomcat.addContext(contextPathURIBase, contextPath.toAbsolutePath().toString());
tomcat.setPort(0); tomcat.setBaseDir(path); Context ctx = tomcat.addContext("", path);
/** * @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); }
Context context = tomcat.addContext(getSettings().getContextPath(), docBase.getAbsolutePath()); context.setAllowCasualMultipartParsing(true); PippoServlet pippoServlet = new PippoServlet();
/** * @see #addContext(String, String) */ public Context addContext(Host host, String contextPath, String dir) { return addContext(host, contextPath, contextPath, dir); }
/** * @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); }
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"); }
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 ...
@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(); }
Tomcat tomcat = new Tomcat(); // skipping a few steps Context ctx = tomcat.addContext(contextPath, baseDir); ServletContext sc = ctx.getServletContext();
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; }
/** * 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; }
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(); }
@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; }
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(); }