@Override
  protected void service(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    ApplicationContext applicationContext = ApplicationContext.getInstance();

    try {
      HttpContext httpContext = this.read(req);
      httpContext =
          this.filter.process(
              httpContext, applicationContext.getModel(), applicationContext.getConfiguration());
      this.write(resp, httpContext);

    } catch (FilterException e) {
      this.error(e, resp);
    }
  }
 @Override
 public void declareRoles(String... roleNames) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     doPrivileged("declareRoles", roleNames);
   } else {
     context.declareRoles(roleNames);
   }
 }
 @Override
 public String getContextPath() {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return (String) doPrivileged("getContextPath", null);
   } else {
     return context.getContextPath();
   }
 }
 @Override
 public Object getAttribute(String name) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return doPrivileged("getAttribute", new Object[] {name});
   } else {
     return context.getAttribute(name);
   }
 }
 /**
  * Sets the session tracking modes that are to become effective for this <tt>ServletContext</tt>.
  */
 @Override
 public void setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     doPrivileged("setSessionTrackingModes", new Object[] {sessionTrackingModes});
   } else {
     context.setSessionTrackingModes(sessionTrackingModes);
   }
 }
 @Override
 public void log(String msg) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     doPrivileged("log", new Object[] {msg});
   } else {
     context.log(msg);
   }
 }
 /** Adds the listener with the given class name to this ServletContext. */
 @Override
 public void addListener(String className) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     doPrivileged("addListener", new Object[] {className});
   } else {
     context.addListener(className);
   }
 }
 @Override
 public void setAttribute(String name, Object object) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     doPrivileged("setAttribute", new Object[] {name, object});
   } else {
     context.setAttribute(name, object);
   }
 }
 @Override
 public void removeAttribute(String name) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     doPrivileged("removeAttribute", new Object[] {name});
   } else {
     context.removeAttribute(name);
   }
 }
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 public Enumeration<String> getAttributeNames() {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return (Enumeration<String>) doPrivileged("getAttributeNames", null);
   } else {
     return context.getAttributeNames();
   }
 }
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 public String getInitParameter(String name) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return (String) doPrivileged("getInitParameter", new Object[] {name});
   } else {
     return context.getInitParameter(name);
   }
 }
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 public String getRealPath(String path) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return (String) doPrivileged("getRealPath", new Object[] {path});
   } else {
     return context.getRealPath(path);
   }
 }
 @Override
 public void log(String message, Throwable throwable) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     doPrivileged(
         "log", new Class[] {String.class, Throwable.class}, new Object[] {message, throwable});
   } else {
     context.log(message, throwable);
   }
 }
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 public RequestDispatcher getNamedDispatcher(String name) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return (RequestDispatcher) doPrivileged("getNamedDispatcher", new Object[] {name});
   } else {
     return context.getNamedDispatcher(name);
   }
 }
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 public String getServletContextName() {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return (String) doPrivileged("getServletContextName", null);
   } else {
     return context.getServletContextName();
   }
 }
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 public ClassLoader getClassLoader() {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return (ClassLoader) doPrivileged("getClassLoader", null);
   } else {
     return context.getClassLoader();
   }
 }
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 public String getMimeType(String file) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return (String) doPrivileged("getMimeType", new Object[] {file});
   } else {
     return context.getMimeType(file);
   }
 }
 /**
  * Instantiates the given EventListener class and performs any required resource injection into
  * the new EventListener instance before returning it.
  */
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 public <T extends EventListener> T createListener(Class<T> clazz) throws ServletException {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return (T) doPrivileged("createListener", new Object[] {clazz});
   } else {
     return context.createListener(clazz);
   }
 }
 /**
  * Gets the <code>&lt;jsp-config&gt;</code> related configuration that was aggregated from the
  * <code>web.xml</code> and <code>web-fragment.xml</code> descriptor files of the web application
  * represented by this ServletContext.
  */
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 public JspConfigDescriptor getJspConfigDescriptor() {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return (JspConfigDescriptor) doPrivileged("getJspConfigDescriptor", null);
   } else {
     return context.getJspConfigDescriptor();
   }
 }
 /** Adds the given listener to this ServletContext. */
 @Override
 public <T extends EventListener> void addListener(T t) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     doPrivileged(
         "addListener", new Class[] {EventListener.class}, new Object[] {t.getClass().getName()});
   } else {
     context.addListener(t);
   }
 }
 /** Adds a listener of the given class type to this ServletContext. */
 @Override
 public void addListener(Class<? extends EventListener> listenerClass) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     doPrivileged(
         "addListener", new Class[] {Class.class}, new Object[] {listenerClass.getName()});
   } else {
     context.addListener(listenerClass);
   }
 }
 /**
  * Gets the session tracking modes that are in effect for this <tt>ServletContext</tt>.
  *
  * @return set of the session tracking modes in effect for this <tt>ServletContext</tt>
  */
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 public Set<SessionTrackingMode> getEffectiveSessionTrackingModes() {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return (Set<SessionTrackingMode>) doPrivileged("getEffectiveSessionTrackingModes", null);
   } else {
     return context.getEffectiveSessionTrackingModes();
   }
 }
 /**
  * Gets the <tt>SessionCookieConfig</tt> object through which various properties of the session
  * tracking cookies created on behalf of this <tt>ServletContext</tt> may be configured.
  */
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 public SessionCookieConfig getSessionCookieConfig() {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return (SessionCookieConfig) doPrivileged("getSessionCookieConfig", null);
   } else {
     return context.getSessionCookieConfig();
   }
 }
 /**
  * Gets a Map of the FilterRegistration objects corresponding to all currently registered filters.
  */
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 public Map<String, ? extends FilterRegistration> getFilterRegistrations() {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return (Map<String, FilterRegistration>) doPrivileged("getFilterRegistrations", null);
   } else {
     return context.getFilterRegistrations();
   }
 }
 /** Gets the FilterRegistration corresponding to the filter with the given <tt>filterName</tt>. */
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 public FilterRegistration getFilterRegistration(String filterName) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return (FilterRegistration) doPrivileged("getFilterRegistration", new Object[] {filterName});
   } else {
     return context.getFilterRegistration(filterName);
   }
 }
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 public InputStream getResourceAsStream(String path) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return (InputStream) doPrivileged("getResourceAsStream", new Object[] {path});
   } else {
     return context.getResourceAsStream(path);
   }
 }
 /** @deprecated As of Java Servlet API 2.1, with no direct replacement. */
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 @Deprecated
 public Enumeration<Servlet> getServlets() {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return (Enumeration<Servlet>) doPrivileged("getServlets", null);
   } else {
     return context.getServlets();
   }
 }
 /** @deprecated As of Java Servlet API 2.1, use <code>log(String, Throwable)</code> instead */
 @Override
 @Deprecated
 public void log(Exception exception, String msg) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     doPrivileged(
         "log", new Class[] {Exception.class, String.class}, new Object[] {exception, msg});
   } else {
     context.log(exception, msg);
   }
 }
 /** Adds the filter with the given name and class name to this servlet context. */
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 public FilterRegistration.Dynamic addFilter(String filterName, String className) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return (FilterRegistration.Dynamic)
         doPrivileged("addFilter", new Object[] {filterName, className});
   } else {
     return context.addFilter(filterName, className);
   }
 }
 /**
  * @return true if the context initialization parameter with the given name and value was set
  *     successfully on this ServletContext, and false if it was not set because this
  *     ServletContext already contains a context initialization parameter with a matching name
  */
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 public boolean setInitParameter(String name, String value) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     return ((Boolean) doPrivileged("setInitParameter", new Object[] {name, value}))
         .booleanValue();
   } else {
     return context.setInitParameter(name, value);
   }
 }