public StandardWrapper addServlet(String path, String name, String clazz) throws ServletException { StandardWrapper servlet = (StandardWrapper) rootContext.createWrapper(); servlet.setName(name); servlet.setServletClass(clazz); servlet.setLoadOnStartup(1); rootContext.addChild(servlet); rootContext.addServletMapping(path, name); servlet.setParent(rootContext); // servlet.load(); return servlet; }
context.addServletMapping("/*", "dispatcher"); ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext());
context.addServletMapping("/*", "dispatcher"); ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext());
wrapper.setServlet(pippoServlet); context.addChild(wrapper); context.addServletMapping(pippoFilterPath, name);
Context rootContext = getTomcatsRootContextFromSomewhere(); Servlet dispatcherServlet = getDispatcherServletFromSomewhere(); // add the dispatcher servlet to the root context Tomcat.addServlet(rootContext, "mySpringService", dispatcherServlet); // add a mapping to the dispatcher servlet rootContext.addServletMapping("/api/*", "mySpringService");
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; }
@Override public Set<String> addMapping(String... urlPatterns) { if (urlPatterns == null) { return Collections.emptySet(); } Set<String> conflicts = new HashSet<String>(); for (String urlPattern : urlPatterns) { if (context.findServletMapping(urlPattern) != null) { conflicts.add(urlPattern); } } if (!conflicts.isEmpty()) { return conflicts; } for (String urlPattern : urlPatterns) { context.addServletMapping(urlPattern, wrapper.getName()); } return Collections.emptySet(); }
Context context = (Context) wrapper.getParent(); Wrapper newWrapper = context.createWrapper(); newWrapper.setName(name); newWrapper.setLoadOnStartup(1); newWrapper.setServletClass(servletClass); context.addChild(newWrapper); context.addServletMapping(pattern, name);
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(); }
public void startPeopleService() throws Exception { final File base = createBaseDirectory(); log.info("Using base folder: " + base.getAbsolutePath()); final Tomcat tomcat = new Tomcat(); tomcat.setPort(8080); tomcat.setBaseDir(base.getAbsolutePath()); Context context = tomcat.addContext("/", base.getAbsolutePath()); Tomcat.addServlet(context, "CXFServlet", new CXFServlet()); context.addServletMapping("/rest/*", "CXFServlet"); context.addApplicationListener(ContextLoaderListener.class.getName()); context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader())); context.addParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName()); context.addParameter("contextConfigLocation", AppConfig.class.getName()); tomcat.start(); tomcat.getServer().await(); }
public static void main(final String[] args) throws Exception { final File base = createBaseDirectory(); log.info("Using base folder: " + base.getAbsolutePath()); final Tomcat tomcat = new Tomcat(); tomcat.setPort(8080); tomcat.setBaseDir( base.getAbsolutePath() ); Context context = tomcat.addContext( "/", base.getAbsolutePath() ); Tomcat.addServlet( context, "CXFServlet", new CXFServlet() ); context.addServletMapping( "/rest/*", "CXFServlet" ); context.addApplicationListener( ContextLoaderListener.class.getName() ); context.setLoader( new WebappLoader( Thread.currentThread().getContextClassLoader() ) ); context.addParameter( "contextClass", AnnotationConfigWebApplicationContext.class.getName() ); context.addParameter( "contextConfigLocation", MusicConfig.class.getName() ); tomcat.start(); tomcat.getServer().await(); }
public static void main(final String[] args) throws Exception { final File base = createBaseDirectory(); log.info("Using base folder: " + base.getAbsolutePath()); final Tomcat tomcat = new Tomcat(); tomcat.setPort(8080); tomcat.setBaseDir( base.getAbsolutePath() ); Context context = tomcat.addContext( "/", base.getAbsolutePath() ); Tomcat.addServlet( context, "CXFServlet", new CXFServlet() ); context.addServletMapping( "/rest/*", "CXFServlet" ); context.addApplicationListener( ContextLoaderListener.class.getName() ); context.setLoader( new WebappLoader( Thread.currentThread().getContextClassLoader() ) ); context.addParameter( "contextClass", AnnotationConfigWebApplicationContext.class.getName() ); context.addParameter( "contextConfigLocation", MusicConfig.class.getName() ); tomcat.start(); tomcat.getServer().await(); }
public void startPeopleService() throws Exception { final File base = createBaseDirectory(); log.info("Using base folder: " + base.getAbsolutePath()); final Tomcat tomcat = new Tomcat(); tomcat.setPort(8080); tomcat.setBaseDir(base.getAbsolutePath()); Context context = tomcat.addContext("/", base.getAbsolutePath()); Tomcat.addServlet(context, "CXFServlet", new CXFServlet()); context.addServletMapping("/rest/*", "CXFServlet"); context.addApplicationListener(ContextLoaderListener.class.getName()); context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader())); context.addParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName()); context.addParameter("contextConfigLocation", AppConfig.class.getName()); tomcat.start(); tomcat.getServer().await(); }
public static void launchService(int port, String indexPath) throws IOException, LifecycleException { Tomcat server = new Tomcat(); Context context = server.addContext("/", new File(".").getAbsolutePath()); System.setProperty(INDEX_PATH_PROP, indexPath); Wrapper servlet = context.createWrapper(); servlet.setName("CXFNonSpringJaxrs"); servlet.setServletClass(CXFNonSpringJaxrsServlet.class.getName()); servlet.addInitParameter("jaxrs.serviceClasses", SearchResource.class.getName() + " " + HealthCheckAPI.class.getName()); servlet.setLoadOnStartup(1); context.addChild(servlet); context.addServletMapping("/api/*", "CXFNonSpringJaxrs"); System.out.println("Starting Embedded Tomcat on port : " + port ); server.setPort(port); server.start(); server.getServer().await(); }
public void start () throws IOException { // create a servlet and context final Context rootCtx = fTomcat.addContext ( "", makeTmpDir ( "uiContext" ).getAbsolutePath () ); Tomcat.addServlet ( rootCtx, kServletName, fServlet ); rootCtx.addServletMapping ( "/*", kServletName ); // determine the port fTomcat.setPort ( fPort ); try { fTomcat.start (); fTomcat.getServer().await (); } catch ( Exception e ) { throw new RuntimeException ( e ); } }
private void createStaticContext( final Tomcat container, Context context, Host host ) { if ( staticContextDocbase != null ) { Context staticContext = container.addContext( staticContextPath, staticContextDocbase ); staticContext.setPrivileged( true ); Wrapper servlet = context.createWrapper(); servlet.setServletClass( DefaultServlet.class.getName() ); servlet.setName( "staticContent" ); staticContext.addChild( servlet ); staticContext.addServletMapping( "/", "staticContent" ); // see https://issues.apache.org/jira/browse/MTOMCAT-238 //host.addChild( staticContext ); } }
@Override public void addServletWithMapping( final String contextPath, final String servletClassName, final String servletMapping) { final Context context = getContext(contextPath); final Wrapper wrapper = context.createWrapper(); wrapper.setName(servletClassName); wrapper.setServletClass(servletClassName); context.addChild(wrapper); context.addServletMapping(contextPath + servletMapping, servletClassName); }
private void createStaticContext( final Embedded container, Context context, Host host ) { if ( staticContextDocbase != null ) { Context staticContext = container.createContext( staticContextPath, staticContextDocbase ); staticContext.setPrivileged( true ); Wrapper servlet = context.createWrapper(); servlet.setServletClass( DefaultServlet.class.getName() ); servlet.setName( "staticContent" ); staticContext.addChild( servlet ); staticContext.addServletMapping( "/", "staticContent" ); host.addChild( staticContext ); } }
private void createStaticContext( final Tomcat container, Context context, Host host ) { if ( staticContextDocbase != null ) { Context staticContext = container.addContext( staticContextPath, staticContextDocbase ); Tomcat.initWebappDefaults(staticContext); staticContext.setPrivileged( true ); Wrapper servlet = context.createWrapper(); servlet.setServletClass( DefaultServlet.class.getName() ); servlet.setName( "staticContent" ); staticContext.addChild( servlet ); staticContext.addServletMapping( "/", "staticContent" ); // see https://issues.apache.org/jira/browse/MTOMCAT-238 //host.addChild( staticContext ); } }
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(); }