@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.addServlet(context, "dispatcher", new DispatcherServlet()); context.addServletMapping("/*", "dispatcher"); ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext());
@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.addServlet(context, "dispatcher", new DispatcherServlet()); context.addServletMapping("/*", "dispatcher"); ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext());
protected void prepareContext(Host host, TomcatHttpHandlerAdapter servlet) { File docBase = createTempDir("tomcat-docbase"); TomcatEmbeddedContext context = new TomcatEmbeddedContext(); context.setPath(""); context.setDocBase(docBase.getAbsolutePath()); context.addLifecycleListener(new Tomcat.FixContextListener()); context.setParentClassLoader(ClassUtils.getDefaultClassLoader()); skipAllTldScanning(context); WebappLoader loader = new WebappLoader(context.getParentClassLoader()); loader.setLoaderClass(TomcatEmbeddedWebappClassLoader.class.getName()); loader.setDelegate(true); context.setLoader(loader); Tomcat.addServlet(context, "httpHandlerServlet", servlet).setAsyncSupported(true); context.addServletMappingDecoded("/", "httpHandlerServlet"); host.addChild(context); configureContext(context); }
Context ctx = tomcat.addContext("", path); Tomcat.addServlet(ctx, "webdav", new WebdavServlet() { @Override public void init(ServletConfig config) throws ServletException {
Tomcat.addServlet(context, "Jersey", "org.glassfish.jersey.servlet.ServletContainer"); wrapper.addInitParameter("javax.ws.rs.Application", OryxApplication.class.getName());
Context ctx = tomcat.addContext("", path); Wrapper wrapper = Tomcat.addServlet(ctx, "webdav", new HttpServlet() {
/** * Add an existing Servlet to the context with no class.forName or * initialisation. * * @param contextPath Context to add Servlet to * @param servletName Servlet name (used in mappings) * @param servlet The Servlet to add * @return The wrapper for the servlet */ public Wrapper addServlet(String contextPath, String servletName, Servlet servlet) { return tomcat.addServlet(contextPath, servletName, servlet); }
@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(); }
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"); }
private static Wrapper addServlet(Context context, Servlet servlet, String path) { String name = servlet.getClass().getSimpleName(); Wrapper servletWrapper = Tomcat.addServlet(context, name, servlet); servletWrapper.setLoadOnStartup(1); context.addServletMapping(path, name); return servletWrapper; }
/** * Add an existing Servlet to the context with no class.forName or * initialisation. * @param contextPath Context to add Servlet to * @param servletName Servlet name (used in mappings) * @param servlet The Servlet to add * @return The wrapper for the servlet */ public Wrapper addServlet(String contextPath, String servletName, Servlet servlet) { Container ctx = getHost().findChild(contextPath); return addServlet((Context) ctx, servletName, servlet); }
/** * Add an existing Servlet to the context with no class.forName or * initialisation. * @param contextPath Context to add Servlet to * @param servletName Servlet name (used in mappings) * @param servlet The Servlet to add * @return The wrapper for the servlet */ public Wrapper addServlet(String contextPath, String servletName, Servlet servlet) { Container ctx = getHost().findChild(contextPath); return addServlet((Context) ctx, servletName, servlet); }
/** * Add an existing Servlet to the context with no class.forName or * initialisation. * @param contextPath Context to add Servlet to * @param servletName Servlet name (used in mappings) * @param servlet The Servlet to add * @return The wrapper for the servlet */ public Wrapper addServlet(String contextPath, String servletName, Servlet servlet) { Container ctx = getHost().findChild(contextPath); return addServlet((Context) ctx, servletName, servlet); }
/** * Add an existing Servlet to the context with no class.forName or * initialisation. * @param contextPath Context to add Servlet to * @param servletName Servlet name (used in mappings) * @param servlet The Servlet to add * @return The wrapper for the servlet */ public Wrapper addServlet(String contextPath, String servletName, Servlet servlet) { Container ctx = getHost().findChild(contextPath); return addServlet((Context) ctx, servletName, servlet); }
/** * Add an existing Servlet to the context with no class.forName or * initialisation. * @param contextPath Context to add Servlet to * @param servletName Servlet name (used in mappings) * @param servlet The Servlet to add * @return The wrapper for the servlet */ public Wrapper addServlet(String contextPath, String servletName, Servlet servlet) { Container ctx = getHost().findChild(contextPath); return addServlet((Context) ctx, servletName, servlet); }
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(); }