@Override public Map<String, ? extends FilterRegistration> getFilterRegistrations() { ensureNotProgramaticListener(); final Map<String, FilterRegistration> ret = new HashMap<String, FilterRegistration>(); for (Map.Entry<String, FilterInfo> entry : deploymentInfo.getFilters().entrySet()) { ret.put(entry.getKey(), new FilterRegistrationImpl(entry.getValue(), deployment)); } return ret; }
@Override public ServletRegistration getServletRegistration(final String servletName) { ensureNotProgramaticListener(); final ServletInfo servlet = deploymentInfo.getServlets().get(servletName); if (servlet == null) { return null; } return new ServletRegistrationImpl(servlet, deployment); }
@Override public FilterRegistration getFilterRegistration(final String filterName) { ensureNotProgramaticListener(); final FilterInfo filterInfo = deploymentInfo.getFilters().get(filterName); if (filterInfo == null) { return null; } return new FilterRegistrationImpl(filterInfo, deployment); }
@Override public void setSessionTrackingModes(final Set<SessionTrackingMode> sessionTrackingModes) { ensureNotProgramaticListener(); ensureNotInitialized(); if (sessionTrackingModes.size() > 1 && sessionTrackingModes.contains(SessionTrackingMode.SSL)) { throw UndertowServletMessages.MESSAGES.sslCannotBeCombinedWithAnyOtherMethod(); } this.sessionTrackingModes = new HashSet<SessionTrackingMode>(sessionTrackingModes); // TODO: actually make this work }
@Override public <T extends EventListener> void addListener(final T t) { ensureNotInitialized(); ensureNotProgramaticListener(); if (ApplicationListeners.listenerState() != NO_LISTENER && ServletContextListener.class.isAssignableFrom(t.getClass())) { throw UndertowServletMessages.MESSAGES.cannotAddServletContextListener(); } ListenerInfo listener = new ListenerInfo(t.getClass(), new ImmediateInstanceFactory<EventListener>(t)); deploymentInfo.addListener(listener); deployment.getApplicationListeners().addListener(new ManagedListener(listener, true)); }
@Override public <T extends Filter> T createFilter(final Class<T> clazz) throws ServletException { ensureNotProgramaticListener(); try { return deploymentInfo .getClassIntrospecter() .createInstanceFactory(clazz) .createInstance() .getInstance(); } catch (Exception e) { throw UndertowServletMessages.MESSAGES.couldNotInstantiateComponent(clazz.getName(), e); } }
@Override public FilterRegistration.Dynamic addFilter( final String filterName, final Class<? extends Filter> filterClass) { ensureNotProgramaticListener(); ensureNotInitialized(); if (deploymentInfo.getFilters().containsKey(filterName)) { return null; } FilterInfo filter = new FilterInfo(filterName, filterClass); deploymentInfo.addFilter(filter); deployment.getFilters().addFilter(filter); return new FilterRegistrationImpl(filter, deployment); }
@Override public ServletRegistration.Dynamic addServlet( final String servletName, final Class<? extends Servlet> servletClass) { ensureNotProgramaticListener(); ensureNotInitialized(); if (deploymentInfo.getServlets().containsKey(servletName)) { return null; } ServletInfo servlet = new ServletInfo(servletName, servletClass); deploymentInfo.addServlet(servlet); deployment.getServlets().addServlet(servlet); return new ServletRegistrationImpl(servlet, deployment); }
@Override public FilterRegistration.Dynamic addFilter(final String filterName, final Filter filter) { ensureNotProgramaticListener(); ensureNotInitialized(); if (deploymentInfo.getFilters().containsKey(filterName)) { return null; } FilterInfo f = new FilterInfo(filterName, filter.getClass(), new ImmediateInstanceFactory<Filter>(filter)); deploymentInfo.addFilter(f); deployment.getFilters().addFilter(f); return new FilterRegistrationImpl(f, deployment); }
@Override public ServletRegistration.Dynamic addServlet(final String servletName, final Servlet servlet) { ensureNotProgramaticListener(); ensureNotInitialized(); if (deploymentInfo.getServlets().containsKey(servletName)) { return null; } ServletInfo s = new ServletInfo( servletName, servlet.getClass(), new ImmediateInstanceFactory<Servlet>(servlet)); deploymentInfo.addServlet(s); deployment.getServlets().addServlet(s); return new ServletRegistrationImpl(s, deployment); }
@Override public void addListener(final Class<? extends EventListener> listenerClass) { ensureNotInitialized(); ensureNotProgramaticListener(); if (ApplicationListeners.listenerState() != NO_LISTENER && ServletContextListener.class.isAssignableFrom(listenerClass)) { throw UndertowServletMessages.MESSAGES.cannotAddServletContextListener(); } InstanceFactory<? extends EventListener> factory = null; try { factory = deploymentInfo.getClassIntrospecter().createInstanceFactory(listenerClass); } catch (Exception e) { throw new IllegalArgumentException(e); } final ListenerInfo listener = new ListenerInfo(listenerClass, factory); deploymentInfo.addListener(listener); deployment.getApplicationListeners().addListener(new ManagedListener(listener, true)); }
@Override public FilterRegistration.Dynamic addFilter(final String filterName, final String className) { ensureNotProgramaticListener(); ensureNotInitialized(); if (deploymentInfo.getFilters().containsKey(filterName)) { return null; } try { FilterInfo filter = new FilterInfo( filterName, (Class<? extends Filter>) deploymentInfo.getClassLoader().loadClass(className)); deploymentInfo.addFilter(filter); deployment.getFilters().addFilter(filter); return new FilterRegistrationImpl(filter, deployment); } catch (ClassNotFoundException e) { throw UndertowServletMessages.MESSAGES.cannotLoadClass(className, e); } }
@Override public ServletRegistration.Dynamic addServlet(final String servletName, final String className) { ensureNotProgramaticListener(); ensureNotInitialized(); try { if (deploymentInfo.getServlets().containsKey(servletName)) { return null; } ServletInfo servlet = new ServletInfo( servletName, (Class<? extends Servlet>) deploymentInfo.getClassLoader().loadClass(className)); deploymentInfo.addServlet(servlet); deployment.getServlets().addServlet(servlet); return new ServletRegistrationImpl(servlet, deployment); } catch (ClassNotFoundException e) { throw UndertowServletMessages.MESSAGES.cannotLoadClass(className, e); } }
@Override public Set<SessionTrackingMode> getEffectiveSessionTrackingModes() { ensureNotProgramaticListener(); return Collections.unmodifiableSet(sessionTrackingModes); }
@Override public Set<SessionTrackingMode> getDefaultSessionTrackingModes() { ensureNotProgramaticListener(); return defaultSessionTrackingModes; }
@Override public SessionCookieConfigImpl getSessionCookieConfig() { ensureNotProgramaticListener(); return sessionCookieConfig; }