@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()); } }
@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); } }
context.addApplicationListener(ModelManagerListener.class.getName());
context.addApplicationListener(PippoServletContextListener.class.getName()); listeners.forEach(listener -> context.addApplicationListener(listener.getName()));
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"); }
@Override public void registerSessionListener(Class<? extends HttpSessionListener> listener) { context.addApplicationListener(listener.getName()); } });
@Override public void registerSessionListener(Class<? extends HttpSessionListener> listener) { context.addApplicationListener(listener.getName()); } });
@Override public void registerSessionListener(Class<? extends HttpSessionListener> listener) { context.addApplicationListener(listener.getName()); } });
private void processCache(File tldCache ) throws IOException { // read the cache and return; try { FileInputStream in=new FileInputStream(tldCache); ObjectInputStream ois=new ObjectInputStream( in ); String list[]=(String [])ois.readObject(); if( log.isDebugEnabled() ) log.debug("Reusing tldCache " + tldCache + " " + list.length); for( int i=0; list!=null && i<list.length; i++ ) { context.addApplicationListener(list[i]); } ois.close(); } catch( ClassNotFoundException ex ) { ex.printStackTrace(); } }
@Override public void addLifecycleListener(ServletContextListenerDescriptor descriptor) { Context context = getContextForPath(descriptor.getContext()); context.addApplicationListener(descriptor.getClazz().getName()); }
public class Main { public static void main(String[] args) throws ServletException, LifecycleException { Tomcat tomcat = new Tomcat(); Context ctx = tomcat.addContext("/", new File("src/main/resources").getAbsolutePath()); Tomcat.addServlet(ctx, "hello", HelloWorldServlet.class.getName()); ctx.addServletMapping("/*", "hello"); ctx.addApplicationListener(Listener.class.getName()); tomcat.start(); tomcat.getServer().await(); } public static class HelloWorldServlet extends HttpServlet { @Inject private BeanManager manager; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/plain"); resp.getWriter().append("Hello from " + manager); } } }
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 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(); }
final ServletContainerInitializer instance = (ServletContainerInitializer) myfacesInitializer.newInstance(); context.addServletContainerInitializer(instance, getJsfClasses(context)); context.addApplicationListener(TOMEE_MYFACES_CONTEXT_LISTENER); // cleanup listener } catch (final Exception | NoClassDefFoundError ignored) {
context.addApplicationListener(list[i]);
context.addApplicationListener(list[i]);
context.addApplicationListener(list[i]);
private void registerBeanManager(Context appContext, String jndiObjectFactory, String servletListener) { ContextResource resource = new ContextResource(); resource.setAuth("Container"); resource.setName(BEAN_MANAGER_NAME); resource.setType(BEAN_MANAGER_TYPE); resource.setProperty("factory", jndiObjectFactory); appContext.getNamingResources().addResource(resource); ContextResourceEnvRef resourceRef = new ContextResourceEnvRef(); resourceRef.setName(BEAN_MANAGER_NAME); resourceRef.setType(BEAN_MANAGER_TYPE); appContext.getNamingResources().addResourceEnvRef(resourceRef); appContext.addApplicationListener(servletListener); }