private void addJspServlet(Context context) { Wrapper jspServlet = context.createWrapper(); jspServlet.setName("jsp"); jspServlet.setServletClass(getJsp().getClassName()); jspServlet.addInitParameter("fork", "false"); getJsp().getInitParameters().forEach(jspServlet::addInitParameter); jspServlet.setLoadOnStartup(3); context.addChild(jspServlet); context.addServletMappingDecoded("*.jsp", "jsp"); context.addServletMappingDecoded("*.jspx", "jsp"); }
private void addDefaultServlet(Context context) { Wrapper defaultServlet = context.createWrapper(); defaultServlet.setName("default"); defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet"); defaultServlet.addInitParameter("debug", "0"); defaultServlet.addInitParameter("listings", "false"); defaultServlet.setLoadOnStartup(1); // Otherwise the default location of a Spring DispatcherServlet cannot be set defaultServlet.setOverridable(true); context.addChild(defaultServlet); context.addServletMappingDecoded("/", "default"); }
@Override protected void initInternal() throws LifecycleException { super.initInternal(); final Wrapper servlet = createWrapper(); servlet.setName(ServerServlet.class.getSimpleName()); servlet.setServletClass(ServerServlet.class.getName()); addChild(servlet); addServletMappingDecoded(MAPPING, ServerServlet.class.getSimpleName()); } }
private void ensureMyFacesDontLooseFacesContext(final StandardContext standardContext) { for (final Container w : standardContext.findChildren()) { if (!Wrapper.class.isInstance(w)) { continue; } final Wrapper wrapper = Wrapper.class.cast(w); if ("FacesServlet".equals(wrapper.getName()) && "javax.faces.webapp.FacesServlet".equals(wrapper.getServletClass())) { final ClassLoader loader = standardContext.getLoader().getClassLoader(); try { if (Files.toFile(loader.getResource("javax/faces/webapp/FacesServlet.class")).getName().startsWith("myfaces")) { loader.loadClass("org.apache.tomee.myfaces.TomEEWorkaroundFacesServlet"); wrapper.setServletClass("org.apache.tomee.myfaces.TomEEWorkaroundFacesServlet"); break; } } catch (final Throwable t) { // not there, not a big deal in most of cases } } } }
@Override protected void initInternal() throws LifecycleException { super.initInternal(); {// fake/not really desired "/*" servlet to ensure in context valve we match the request and got to WS filter final Wrapper servlet = createWrapper(); servlet.setName(DefaultServlet.class.getSimpleName()); servlet.setServletClass(DefaultServlet.class.getName()); addChild(servlet); addServletMappingDecoded("/*", DefaultServlet.class.getSimpleName()); } {// the js injected in the page final Wrapper servlet = createWrapper(); servlet.setName(LiveReloadJs.class.getSimpleName()); servlet.setServletClass(LiveReloadJs.class.getName()); addChild(servlet); addServletMappingDecoded("/livereload.js", LiveReloadJs.class.getSimpleName()); } }
/** * Static version of {@link #addServlet(String, String, String)} * @param ctx Context to add Servlet to * @param servletName Servlet name (used in mappings) * @param servletClass The class to be used for the Servlet * @return The wrapper for the servlet */ public static Wrapper addServlet(Context ctx, String servletName, String servletClass) { // will do class for name and set init params Wrapper sw = ctx.createWrapper(); sw.setServletClass(servletClass); sw.setName(servletName); ctx.addChild(sw); return sw; }
/** * Static version of {@link #addServlet(String, String, String)} * @param ctx Context to add Servlet to * @param servletName Servlet name (used in mappings) * @param servletClass The class to be used for the Servlet * @return The wrapper for the servlet */ public static Wrapper addServlet(Context ctx, String servletName, String servletClass) { // will do class for name and set init params Wrapper sw = ctx.createWrapper(); sw.setServletClass(servletClass); sw.setName(servletName); ctx.addChild(sw); return sw; }
/** * Static version of {@link #addServlet(String, String, String)} * @param ctx Context to add Servlet to * @param servletName Servlet name (used in mappings) * @param servletClass The class to be used for the Servlet * @return The wrapper for the servlet */ public static Wrapper addServlet(Context ctx, String servletName, String servletClass) { // will do class for name and set init params Wrapper sw = ctx.createWrapper(); sw.setServletClass(servletClass); sw.setName(servletName); ctx.addChild(sw); return sw; }
/** * Static version of {@link #addServlet(String, String, String)} * @param ctx Context to add Servlet to * @param servletName Servlet name (used in mappings) * @param servletClass The class to be used for the Servlet * @return The wrapper for the servlet */ public static Wrapper addServlet(Context ctx, String servletName, String servletClass) { // will do class for name and set init params Wrapper sw = ctx.createWrapper(); sw.setServletClass(servletClass); sw.setName(servletName); ctx.addChild(sw); return sw; }
/** * Static version of {@link #addServlet(String, String, String)} * @param ctx Context to add Servlet to * @param servletName Servlet name (used in mappings) * @param servletClass The class to be used for the Servlet * @return The wrapper for the servlet */ public static Wrapper addServlet(Context ctx, String servletName, String servletClass) { // will do class for name and set init params Wrapper sw = ctx.createWrapper(); sw.setServletClass(servletClass); sw.setName(servletName); ctx.addChild(sw); return sw; }
/** * Static version of {@link #addServlet(String, String, String)} * @param ctx Context to add Servlet to * @param servletName Servlet name (used in mappings) * @param servletClass The class to be used for the Servlet * @return The wrapper for the servlet */ public static Wrapper addServlet(Context ctx, String servletName, String servletClass) { // will do class for name and set init params Wrapper sw = ctx.createWrapper(); sw.setServletClass(servletClass); sw.setName(servletName); ctx.addChild(sw); return sw; }
/** * Static version of {@link #addServlet(String, String, String)} * @param ctx Context to add Servlet to * @param servletName Servlet name (used in mappings) * @param servletClass The class to be used for the Servlet * @return The wrapper for the servlet */ public static Wrapper addServlet(Context ctx, String servletName, String servletClass) { // will do class for name and set init params Wrapper sw = ctx.createWrapper(); sw.setServletClass(servletClass); sw.setName(servletName); ctx.addChild(sw); return sw; }
/** * Static version of {@link #addServlet(String, String, String)} * @param ctx Context to add Servlet to * @param servletName Servlet name (used in mappings) * @param servletClass The class to be used for the Servlet * @return The wrapper for the servlet */ public static Wrapper addServlet(Context ctx, String servletName, String servletClass) { // will do class for name and set init params Wrapper sw = ctx.createWrapper(); sw.setServletClass(servletClass); sw.setName(servletName); ctx.addChild(sw); return sw; }
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(); }
@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 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 ); } }
public ProgrammaticContext addServlet(final String name, final Class<?> type, final String mapping, final String... initParams) { final Wrapper wrapper = createWrapper(); wrapper.setServletClass(type.getName()); wrapper.setName(name); if (initParams != null && initParams.length > 0) { for (int i = 0; i < initParams.length; i+=2) { wrapper.addInitParameter(initParams[i], initParams[i+1]); } } wrapper.setLoadOnStartup(1); // otherwise we would miss reposgitry integration at least addChild(wrapper); addServletMapping(mapping, wrapper.getName(), false); return this; }
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 ); } }
private void addDefaultServlet() { Wrapper defaultServlet = this.tomcatContext.createWrapper(); defaultServlet.setName("default"); defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet"); defaultServlet.addInitParameter("debug", "0"); defaultServlet.addInitParameter("listings", "false"); defaultServlet.setLoadOnStartup(1); defaultServlet.setOverridable(true); this.tomcatContext.addChild(defaultServlet); addServletMapping("/", "default"); }