public boolean setInitParameter(String name, String value) { if (restricted) { throw new UnsupportedOperationException(sm.getString("applicationContext.restricted")); } if (!context.isStarting()) { throw new IllegalStateException(sm.getString("applicationContext.alreadyInitialized", getContextPath())); } mergeParameters(); if (parameters.get(name) != null) { return false; } else { parameters.put(name, value); return true; } }
public boolean setInitParameter(String name, String value) { if (restricted) { throw MESSAGES.restrictedListenerCannotCallMethod(); } if (!context.isStarting()) { throw MESSAGES.contextAlreadyInitialized(getContextPath()); } mergeParameters(); if (parameters.get(name) != null) { return false; } else { parameters.put(name, value); return true; } }
public void declareRoles(String... roleNames) { if (restricted) { throw new UnsupportedOperationException(sm.getString("applicationContext.restricted")); } if (!context.isStarting()) { throw new IllegalStateException(sm.getString("applicationContext.alreadyInitialized", getContextPath())); } for (String role: roleNames) { if (role == null || "".equals(role)) { throw new IllegalArgumentException(sm.getString("applicationContext.emptyRole", getContextPath())); } context.addSecurityRole(role); } }
public <T extends EventListener> void addListener(T listener) { if (restricted) { throw new UnsupportedOperationException(sm.getString("applicationContext.restricted")); } if (!context.isStarting()) { throw new IllegalStateException(sm.getString("applicationContext.alreadyInitialized", getContextPath())); } checkListenerType(listener); if (context.getApplicationLifecycleListeners() != null && listener instanceof ServletContextListener) { throw new IllegalArgumentException(sm.getString("applicationContext.badListenerClass", listener.getClass().getName(), getContextPath())); } context.addApplicationListenerInstance(listener); }
public void setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes) { if (restricted) { throw new UnsupportedOperationException(sm.getString("applicationContext.restricted")); } if (!context.isStarting()) { throw new IllegalStateException(sm.getString("applicationContext.alreadyInitialized", getContextPath())); } // Check that only supported tracking modes have been requested for (SessionTrackingMode sessionTrackingMode : sessionTrackingModes) { if (!getDefaultSessionTrackingModes().contains(sessionTrackingMode)) { throw new IllegalArgumentException(sm.getString( "applicationContext.setSessionTracking.iae", sessionTrackingMode.toString(), getContextPath())); } } // If SSL is specified, it should be the only one used if (sessionTrackingModes.contains(SessionTrackingMode.SSL) && sessionTrackingModes.size() > 1) { throw new IllegalArgumentException(sm.getString( "applicationContext.setSessionTracking.ssl", getContextPath())); } context.setSessionTrackingModes(sessionTrackingModes); }
public <T extends EventListener> T createListener(Class<T> clazz) throws ServletException { if (restricted) { throw new UnsupportedOperationException(sm.getString("applicationContext.restricted")); } if (!context.isStarting()) { throw new IllegalStateException(sm.getString("applicationContext.alreadyInitialized", getContextPath())); } T listenerInstance = null; try { listenerInstance = (T) context.getInstanceManager().newInstance(clazz); } catch (Throwable t) { throw new ServletException(sm.getString("applicationContext.create"), t); } checkListenerType(listenerInstance); return listenerInstance; }
public void declareRoles(String... roleNames) { if (restricted) { throw MESSAGES.restrictedListenerCannotCallMethod(); } if (!context.isStarting()) { throw MESSAGES.contextAlreadyInitialized(getContextPath()); } for (String role: roleNames) { if (role == null || "".equals(role)) { throw MESSAGES.invalidEmptyRole(getContextPath()); } context.addSecurityRole(role); } }
public <T extends EventListener> void addListener(T listener) { if (restricted) { throw MESSAGES.restrictedListenerCannotCallMethod(); } if (!context.isStarting()) { throw MESSAGES.contextAlreadyInitialized(getContextPath()); } checkListenerType(listener); if (context.getApplicationLifecycleListeners() != null && listener instanceof ServletContextListener) { throw MESSAGES.invalidContextListener(listener.getClass().getName(), getContextPath()); } context.addApplicationListenerInstance(listener); }
public void addListener(Class<? extends EventListener> listenerClass) { if (restricted) { throw new UnsupportedOperationException(sm.getString("applicationContext.restricted")); } if (!context.isStarting()) { throw new IllegalStateException(sm.getString("applicationContext.alreadyInitialized", getContextPath())); } EventListener listenerInstance = null; try { listenerInstance = (EventListener) context.getInstanceManager().newInstance(listenerClass); } catch (Exception e) { throw new IllegalArgumentException(sm.getString("applicationContext.badListenerClass", listenerClass.getName(), getContextPath()), e); } checkListenerType(listenerInstance); if (context.getApplicationLifecycleListeners() != null && listenerInstance instanceof ServletContextListener) { throw new IllegalArgumentException(sm.getString("applicationContext.badListenerClass", listenerClass.getName(), getContextPath())); } context.addApplicationListenerInstance(listenerInstance); }
public void setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes) { if (restricted) { throw MESSAGES.restrictedListenerCannotCallMethod(); } if (!context.isStarting()) { throw MESSAGES.contextAlreadyInitialized(getContextPath()); } // Check that only supported tracking modes have been requested for (SessionTrackingMode sessionTrackingMode : sessionTrackingModes) { if (!getDefaultSessionTrackingModes().contains(sessionTrackingMode)) { throw MESSAGES.unsupportedSessionTrackingMode(sessionTrackingMode.toString(), getContextPath()); } } // If SSL is specified, it should be the only one used if (sessionTrackingModes.contains(SessionTrackingMode.SSL) && sessionTrackingModes.size() > 1) { throw MESSAGES.sslSessionTrackingModeIsExclusive(getContextPath()); } context.setSessionTrackingModes(sessionTrackingModes); }
public <T extends EventListener> T createListener(Class<T> clazz) throws ServletException { if (restricted) { throw MESSAGES.restrictedListenerCannotCallMethod(); } if (!context.isStarting()) { throw MESSAGES.contextAlreadyInitialized(getContextPath()); } T listenerInstance = null; try { listenerInstance = (T) context.getInstanceManager().newInstance(clazz); } catch (Throwable t) { throw new ServletException(MESSAGES.contextObjectCreationError(), t); } checkListenerType(listenerInstance); return listenerInstance; }
public void addListener(String className) { if (restricted) { throw new UnsupportedOperationException(sm.getString("applicationContext.restricted")); } if (!context.isStarting()) { throw new IllegalStateException(sm.getString("applicationContext.alreadyInitialized", getContextPath())); } EventListener listenerInstance = null; try { Class<?> clazz = context.getLoader().getClassLoader().loadClass(className); listenerInstance = (EventListener) context.getInstanceManager().newInstance(clazz); } catch (Throwable t) { throw new IllegalArgumentException(sm.getString("applicationContext.badListenerClass", className, getContextPath()), t); } checkListenerType(listenerInstance); if (context.getApplicationLifecycleListeners() != null && listenerInstance instanceof ServletContextListener) { throw new IllegalArgumentException(sm.getString("applicationContext.badListenerClass", className, getContextPath())); } context.addApplicationListenerInstance(listenerInstance); }
public ServletRegistration.Dynamic addServlet(String servletName, String className) throws IllegalArgumentException, IllegalStateException { if (restricted) { throw new UnsupportedOperationException(sm.getString("applicationContext.restricted")); } if (!context.isStarting()) { throw new IllegalStateException(sm.getString("applicationContext.alreadyInitialized", getContextPath())); } if (context.findChild(servletName) != null) { return null; } Wrapper wrapper = context.createWrapper(); wrapper.setDynamic(true); wrapper.setName(servletName); wrapper.setServletClass(className); context.addChild(wrapper); return (ServletRegistration.Dynamic) wrapper.getFacade(); }
public void addListener(Class<? extends EventListener> listenerClass) { if (restricted) { throw MESSAGES.restrictedListenerCannotCallMethod(); } if (!context.isStarting()) { throw MESSAGES.contextAlreadyInitialized(getContextPath()); } EventListener listenerInstance = null; try { listenerInstance = (EventListener) context.getInstanceManager().newInstance(listenerClass); } catch (Exception e) { throw MESSAGES.invalidContextListenerWithException(listenerClass.getName(), getContextPath(), e); } checkListenerType(listenerInstance); if (context.getApplicationLifecycleListeners() != null && listenerInstance instanceof ServletContextListener) { throw MESSAGES.invalidContextListener(listenerClass.getName(), getContextPath()); } context.addApplicationListenerInstance(listenerInstance); }
public ServletRegistration.Dynamic addServlet(String servletName, Servlet servlet) { if (restricted) { throw new UnsupportedOperationException(sm.getString("applicationContext.restricted")); } if (!context.isStarting()) { throw new IllegalStateException(sm.getString("applicationContext.alreadyInitialized", getContextPath())); } if (context.findChild(servletName) != null) { return null; } // Servlet instance unicity for (Container container : context.getParent().findChildren()) { for (Container wrapper : container.findChildren()) { if (((Wrapper) wrapper).getServlet() == servlet) { return null; } } } Wrapper wrapper = context.createWrapper(); wrapper.setDynamic(true); wrapper.setName(servletName); wrapper.setServletClass(servlet.getClass().getName()); wrapper.setServlet(servlet); context.addChild(wrapper); return (ServletRegistration.Dynamic) wrapper.getFacade(); }
public FilterRegistration.Dynamic addFilter(String filterName, String className) throws IllegalArgumentException, IllegalStateException { if (restricted) { throw new UnsupportedOperationException(sm.getString("applicationContext.restricted")); } if (!context.isStarting()) { throw new IllegalStateException(sm.getString("applicationContext.alreadyInitialized", getContextPath())); } if (context.findFilterDef(filterName) != null) { return null; } FilterDef filterDef = new FilterDef(); filterDef.setFilterName(filterName); filterDef.setFilterClass(className); context.addFilterDef(filterDef); ApplicationFilterConfig filterConfig = new ApplicationFilterConfig(context, filterDef); filterConfig.setDynamic(true); context.addApplicationFilterConfig(filterConfig); return (FilterRegistration.Dynamic) filterConfig.getFacade(); }
public void addListener(String className) { if (restricted) { throw MESSAGES.restrictedListenerCannotCallMethod(); } if (!context.isStarting()) { throw MESSAGES.contextAlreadyInitialized(getContextPath()); } EventListener listenerInstance = null; try { Class<?> clazz = context.getLoader().getClassLoader().loadClass(className); listenerInstance = (EventListener) context.getInstanceManager().newInstance(clazz); } catch (Throwable t) { throw MESSAGES.invalidContextListenerWithException(className, getContextPath(), t); } checkListenerType(listenerInstance); if (context.getApplicationLifecycleListeners() != null && listenerInstance instanceof ServletContextListener) { throw MESSAGES.invalidContextListener(className, getContextPath()); } context.addApplicationListenerInstance(listenerInstance); }
public FilterRegistration.Dynamic addFilter(String filterName, Filter filter) { if (restricted) { throw MESSAGES.restrictedListenerCannotCallMethod(); } if (!context.isStarting()) { throw MESSAGES.contextAlreadyInitialized(getContextPath()); } if (context.findFilterDef(filterName) != null) { return null; } // Filter instance unicity for (Container container : context.getParent().findChildren()) { if (container instanceof StandardContext) { for (ApplicationFilterConfig filterConfig : ((StandardContext) container).findApplicationFilterConfigs()) { if (filterConfig.getFilterInstance() == filter) { return null; } } } } FilterDef filterDef = new FilterDef(); filterDef.setFilterName(filterName); filterDef.setFilterClass(filter.getClass().getName()); context.addFilterDef(filterDef); ApplicationFilterConfig filterConfig = new ApplicationFilterConfig(context, filterDef); filterConfig.setDynamic(true); filterConfig.setFilter(filter); context.addApplicationFilterConfig(filterConfig); return (FilterRegistration.Dynamic) filterConfig.getFacade(); }
public FilterRegistration.Dynamic addFilter(String filterName, String className) throws IllegalArgumentException, IllegalStateException { if (restricted) { throw MESSAGES.restrictedListenerCannotCallMethod(); } if (!context.isStarting()) { throw MESSAGES.contextAlreadyInitialized(getContextPath()); } if (context.findFilterDef(filterName) != null) { return null; } FilterDef filterDef = new FilterDef(); filterDef.setFilterName(filterName); filterDef.setFilterClass(className); context.addFilterDef(filterDef); ApplicationFilterConfig filterConfig = new ApplicationFilterConfig(context, filterDef); filterConfig.setDynamic(true); context.addApplicationFilterConfig(filterConfig); return (FilterRegistration.Dynamic) filterConfig.getFacade(); }
public ServletRegistration.Dynamic addServlet(String servletName, String className) throws IllegalArgumentException, IllegalStateException { if (restricted) { throw MESSAGES.restrictedListenerCannotCallMethod(); } if (!context.isStarting()) { throw MESSAGES.contextAlreadyInitialized(getContextPath()); } Wrapper existingWrapper = (Wrapper)context.findChild(servletName); if (existingWrapper != null) { if (existingWrapper.isOverridable()) { existingWrapper.setOverridable(false); } else { return null; } } Wrapper wrapper = context.createWrapper(); wrapper.setDynamic(true); wrapper.setName(servletName); wrapper.setServletClass(className); context.addChild(wrapper); return (ServletRegistration.Dynamic) wrapper.getFacade(); }