Example #1
0
  protected boolean shouldExcludeProperty(String expr) {
    if (this.excludeProperties != null) {
      for (Pattern pattern : this.excludeProperties) {
        if (pattern.matcher(expr).matches()) {
          if (LOG.isDebugEnabled()) {
            LOG.debug("Ignoring property because of exclude rule: " + expr);
          }
          return true;
        }
      }
    }

    if (this.includeProperties != null) {
      for (Pattern pattern : this.includeProperties) {
        if (pattern.matcher(expr).matches()) {
          return false;
        }
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("Ignoring property because of include rule:  " + expr);
      }
      return true;
    }
    return false;
  }
Example #2
0
  protected Method findBaseAccessor(Class clazz, Method accessor) {
    Method baseAccessor = null;
    if (clazz.getName().contains("$$EnhancerByCGLIB$$")) {
      try {
        baseAccessor =
            Thread.currentThread()
                .getContextClassLoader()
                .loadClass(clazz.getName().substring(0, clazz.getName().indexOf("$$")))
                .getMethod(accessor.getName(), accessor.getParameterTypes());
      } catch (Exception ex) {
        LOG.debug(ex.getMessage(), ex);
      }
    } else if (clazz.getName().contains("$$_javassist")) {
      try {
        baseAccessor =
            Class.forName(clazz.getName().substring(0, clazz.getName().indexOf("_$$")))
                .getMethod(accessor.getName(), accessor.getParameterTypes());
      } catch (Exception ex) {
        LOG.debug(ex.getMessage(), ex);
      }

      // in hibernate4.3.7,because javassist3.18.1's class name generate rule is '_$$_jvst'+...
    } else if (clazz.getName().contains("$$_jvst")) {
      try {
        baseAccessor =
            Class.forName(clazz.getName().substring(0, clazz.getName().indexOf("_$$")))
                .getMethod(accessor.getName(), accessor.getParameterTypes());
      } catch (Exception ex) {
        LOG.debug(ex.getMessage(), ex);
      }
    } else {
      return accessor;
    }
    return baseAccessor;
  }
  /**
   * 判断是否合法的提交操作
   *
   * @param tokenName 为页面对应的name
   * @return
   */
  public boolean validToken(String tokenName) {
    String sessToken = (String) session.get(tokenName);
    String tokenValue = null;
    if (TOKEN_ID.equals(tokenName)) {
      tokenValue = tokenid;
    } else if (EX_TOKEN.equals(tokenName)) {
      tokenValue = extoken;
    } else {
      LOG.warn("the tokenName is not required ");
    }

    // 解决重启服务器,刷新报空指针问题
    if (tokenValue == null) {
      LOG.warn("the tokenValue  is null.");
      return false;
    }

    if (!tokenValue.equals(sessToken)) {
      LOG.warn("Form" + tokenName + "does not match the session" + tokenName + ".");
      return false;
    }
    // remove the token so it won't be used again
    session.remove(tokenName);
    return true;
  }
  /*
   * (non-Javadoc)
   *
   * @see org.apache.struts2.dispatcher.multipart.MultiPartRequest#getFile(java.lang.String)
   */
  public File[] getFile(String fieldName) {
    List<FileItem> items = files.get(fieldName);

    if (items == null) {
      return null;
    }

    List<File> fileList = new ArrayList<File>(items.size());
    for (FileItem fileItem : items) {
      File storeLocation = ((DiskFileItem) fileItem).getStoreLocation();
      if (fileItem.isInMemory() && storeLocation != null && !storeLocation.exists()) {
        try {
          storeLocation.createNewFile();
        } catch (IOException e) {
          if (LOG.isErrorEnabled()) {
            LOG.error(
                "Cannot write uploaded empty file to disk: " + storeLocation.getAbsolutePath(), e);
          }
        }
      }
      fileList.add(storeLocation);
    }

    return fileList.toArray(new File[fileList.size()]);
  }
  @Override
  public String doIntercept(ActionInvocation invocation) throws Exception {
    Object action = invocation.getAction();
    if (!(action instanceof NoParameters)) {
      ActionContext ac = invocation.getInvocationContext();
      final Map<String, Object> parameters = retrieveParameters(ac);

      if (LOG.isDebugEnabled()) {
        LOG.debug("Setting params " + getParameterLogMap(parameters));
      }

      if (parameters != null) {
        Map<String, Object> contextMap = ac.getContextMap();
        try {
          ReflectionContextState.setCreatingNullObjects(contextMap, true);
          ReflectionContextState.setDenyMethodExecution(contextMap, true);
          ReflectionContextState.setReportingConversionErrors(contextMap, true);

          ValueStack stack = ac.getValueStack();
          setParameters(action, stack, parameters);
        } finally {
          ReflectionContextState.setCreatingNullObjects(contextMap, false);
          ReflectionContextState.setDenyMethodExecution(contextMap, false);
          ReflectionContextState.setReportingConversionErrors(contextMap, false);
        }
      }
    }
    return invocation.invoke();
  }
 private void closeQuietly(InputStream is) {
   try {
     if (is != null) is.close();
   } catch (IOException e) {
     if (LOG.isErrorEnabled()) LOG.error("Unable to close input stream", e);
   }
 }
Example #7
0
 public int doEndTag() throws JspException {
   JspWriter writer = pageContext.getOut();
   if (label != null) {
     try {
       writer.write("<div class='control-group'><label class='control-label'>");
       writer.write(label);
       writer.write("</label><div class='controls'>");
     } catch (IOException e) {
       if (LOG.isInfoEnabled()) {
         LOG.info("Could not print out value '" + label + "'", e);
       }
     }
   }
   component.end(writer, getBody());
   if (label != null) {
     try {
       writer.write("</div></div>");
     } catch (IOException e) {
       if (LOG.isInfoEnabled()) {
         LOG.info("Could not print out value '" + label + "'", e);
       }
     }
   }
   component = null;
   return EVAL_PAGE;
 }
Example #8
0
  /**
   * Load configurations, including both XML and zero-configuration strategies, and update optional
   * settings, including whether to reload configurations and resource files.
   */
  public void init() {

    if (configurationManager == null) {
      configurationManager = createConfigurationManager(BeanSelectionProvider.DEFAULT_BEAN_NAME);
    }

    try {
      init_FileManager();
      init_DefaultProperties(); // [1]
      init_TraditionalXmlConfigurations(); // [2]
      init_LegacyStrutsProperties(); // [3]
      init_CustomConfigurationProviders(); // [5]
      init_FilterInitParameters(); // [6]
      init_AliasStandardObjects(); // [7]

      Container container = init_PreloadConfiguration();
      container.inject(this);
      init_CheckWebLogicWorkaround(container);

      if (!dispatcherListeners.isEmpty()) {
        for (DispatcherListener l : dispatcherListeners) {
          l.dispatcherInitialized(this);
        }
      }
    } catch (Exception ex) {
      if (LOG.isErrorEnabled()) LOG.error("Dispatcher initialization failed", ex);
      throw new StrutsException(ex);
    }
  }
Example #9
0
  /** Detect cyclic references */
  private void value(Object object, Method method) throws JSONException {
    if (object == null) {
      this.add("null");

      return;
    }

    if (this.stack.contains(object)) {
      Class clazz = object.getClass();

      // cyclic reference
      if (clazz.isPrimitive() || clazz.equals(String.class)) {
        this.process(object, method);
      } else {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Cyclic reference detected on " + object);
        }

        this.add("null");
      }

      return;
    }

    this.process(object, method);
  }
Example #10
0
 /** Cleans up a request of thread locals */
 public void cleanupRequest(HttpServletRequest request) {
   Integer counterVal = (Integer) request.getAttribute(CLEANUP_RECURSION_COUNTER);
   if (counterVal != null) {
     counterVal -= 1;
     request.setAttribute(CLEANUP_RECURSION_COUNTER, counterVal);
     if (counterVal > 0) {
       if (log.isDebugEnabled()) {
         log.debug("skipping cleanup counter=" + counterVal);
       }
       return;
     }
   }
   // always clean up the thread request, even if an action hasn't been executed
   try {
     dispatcher.cleanUpRequest(request);
   } catch (IOException e) {
     if (LOG.isWarnEnabled()) {
       LOG.warn(
           "Cannot clean up the request, some files can still remain in #0 after upload!",
           e,
           StrutsConstants.STRUTS_MULTIPART_SAVEDIR);
     }
   } finally {
     ActionContext.setContext(null);
     Dispatcher.setInstance(null);
   }
 }
Example #11
0
 private void init_FileManager() throws ClassNotFoundException {
   if (initParams.containsKey(StrutsConstants.STRUTS_FILE_MANAGER)) {
     final String fileManagerClassName = initParams.get(StrutsConstants.STRUTS_FILE_MANAGER);
     final Class<FileManager> fileManagerClass =
         (Class<FileManager>) Class.forName(fileManagerClassName);
     if (LOG.isInfoEnabled()) {
       LOG.info("Custom FileManager specified: #0", fileManagerClassName);
     }
     configurationManager.addContainerProvider(
         new FileManagerProvider(fileManagerClass, fileManagerClass.getSimpleName()));
   } else {
     // add any other Struts 2 provided implementations of FileManager
     configurationManager.addContainerProvider(
         new FileManagerProvider(JBossFileManager.class, "jboss"));
   }
   if (initParams.containsKey(StrutsConstants.STRUTS_FILE_MANAGER_FACTORY)) {
     final String fileManagerFactoryClassName =
         initParams.get(StrutsConstants.STRUTS_FILE_MANAGER_FACTORY);
     final Class<FileManagerFactory> fileManagerFactoryClass =
         (Class<FileManagerFactory>) Class.forName(fileManagerFactoryClassName);
     if (LOG.isInfoEnabled()) {
       LOG.info("Custom FileManagerFactory specified: #0", fileManagerFactoryClassName);
     }
     configurationManager.addContainerProvider(
         new FileManagerFactoryProvider(fileManagerFactoryClass));
   }
 }
Example #12
0
  /** Releases all instances bound to this dispatcher instance. */
  public void cleanup() {

    // clean up ObjectFactory
    ObjectFactory objectFactory = getContainer().getInstance(ObjectFactory.class);
    if (objectFactory == null) {
      if (LOG.isWarnEnabled()) {
        LOG.warn(
            "Object Factory is null, something is seriously wrong, no clean up will be performed");
      }
    }
    if (objectFactory instanceof ObjectFactoryDestroyable) {
      try {
        ((ObjectFactoryDestroyable) objectFactory).destroy();
      } catch (Exception e) {
        // catch any exception that may occurred during destroy() and log it
        LOG.error(
            "exception occurred while destroying ObjectFactory [#0]", e, objectFactory.toString());
      }
    }

    // clean up Dispatcher itself for this thread
    instance.set(null);

    // clean up DispatcherListeners
    if (!dispatcherListeners.isEmpty()) {
      for (DispatcherListener l : dispatcherListeners) {
        l.dispatcherDestroyed(this);
      }
    }

    // clean up all interceptors by calling their destroy() method
    Set<Interceptor> interceptors = new HashSet<Interceptor>();
    Collection<PackageConfig> packageConfigs =
        configurationManager.getConfiguration().getPackageConfigs().values();
    for (PackageConfig packageConfig : packageConfigs) {
      for (Object config : packageConfig.getAllInterceptorConfigs().values()) {
        if (config instanceof InterceptorStackConfig) {
          for (InterceptorMapping interceptorMapping :
              ((InterceptorStackConfig) config).getInterceptors()) {
            interceptors.add(interceptorMapping.getInterceptor());
          }
        }
      }
    }
    for (Interceptor interceptor : interceptors) {
      interceptor.destroy();
    }

    // Clear container holder when application is unloaded / server shutdown
    ContainerHolder.clear();

    // cleanup action context
    ActionContext.setContext(null);

    // clean up configuration
    configurationManager.destroyConfiguration();
    configurationManager = null;
  }
Example #13
0
 protected void enableAncestorFormCustomOnsubmit() {
   Form form = (Form) findAncestor(Form.class);
   if (form != null) {
     form.addParameter("customOnsubmitEnabled", Boolean.TRUE);
   } else {
     if (LOG.isWarnEnabled()) {
       LOG.warn("Cannot find an Ancestor form, custom onsubmit is NOT enabled");
     }
   }
 }
 /**
  * Creates a new request wrapper to handle multi-part data using methods adapted from Jason Pell's
  * multipart classes (see class description).
  *
  * @param saveDir the directory to save off the file
  * @param request the request containing the multipart
  * @throws java.io.IOException is thrown if encoding fails.
  */
 public void parse(HttpServletRequest request, String saveDir) throws IOException {
   try {
     processUpload(request, saveDir);
   } catch (FileUploadException e) {
     if (LOG.isWarnEnabled()) {
       LOG.warn("Unable to parse request", e);
     }
     errors.add(e.getMessage());
   }
 }
  @Override
  public void setProperty(Map context, Object target, Object name, Object value)
      throws OgnlException {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Entering setProperty(" + context + "," + target + "," + name + "," + value + ")");
    }

    Object key = getKey(context, name);
    Map map = (Map) target;
    map.put(key, getValue(context, value));
  }
  /**
   * Get a message from the first TextProvider encountered in the stack. If the first TextProvider
   * doesn't provide the message the default message is returned.
   *
   * <p>The search for a TextProvider is iterative from the root of the stack.
   *
   * <p>This method was refactored from {@link org.apache.struts2.components.Text} to use a
   * consistent implementation across UIBean components.
   *
   * @param key the message key in the resource bundle
   * @param defaultMessage the message to return if not found (evaluated for OGNL)
   * @param args an array args to be used in a {@link java.text.MessageFormat} message
   * @param stack the value stack to use for finding the text
   * @param searchStack search stack for the key
   * @return the message if found, otherwise the defaultMessage
   */
  public static String getText(
      String key, String defaultMessage, List<Object> args, ValueStack stack, boolean searchStack) {
    String msg = null;
    TextProvider tp = null;

    for (Object o : stack.getRoot()) {
      if (o instanceof TextProvider) {
        tp = (TextProvider) o;
        msg = tp.getText(key, null, args, stack);

        break;
      }
    }

    if (msg == null) {
      // evaluate the defaultMesage as an OGNL expression
      if (searchStack) msg = stack.findString(defaultMessage);

      if (msg == null) {
        // use the defaultMessage literal value
        msg = defaultMessage;
      }

      if (LOG.isWarnEnabled()) {
        if (tp != null) {
          LOG.warn(
              "The first TextProvider in the ValueStack ("
                  + tp.getClass().getName()
                  + ") could not locate the message resource with key '"
                  + key
                  + "'");
        } else {
          LOG.warn(
              "Could not locate the message resource '"
                  + key
                  + "' as there is no TextProvider in the ValueStack.");
        }
        if (defaultMessage.equals(msg)) {
          LOG.warn(
              "The default value expression '"
                  + defaultMessage
                  + "' was evaluated and did not match a property.  The literal value '"
                  + defaultMessage
                  + "' will be used.");
        } else {
          LOG.warn(
              "The default value expression '" + defaultMessage + "' evaluated to '" + msg + "'");
        }
      }
    }
    return msg;
  }
 private void processUpload(HttpServletRequest request, String saveDir)
     throws FileUploadException, UnsupportedEncodingException {
   for (FileItem item : parseRequest(request, saveDir)) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("Found item " + item.getFieldName());
     }
     if (item.isFormField()) {
       processNormalFormField(item, request.getCharacterEncoding());
     } else {
       processFileField(item);
     }
   }
 }
Example #18
0
  protected void mergeTemplate(Writer writer, Template template) throws Exception {
    final TemplateEngine engine = templateEngineManager.getTemplateEngine(template, templateSuffix);
    if (engine == null) {
      throw new ConfigurationException("Unable to find a TemplateEngine for template " + template);
    }

    if (LOG.isDebugEnabled()) {
      LOG.debug("Rendering template " + template);
    }

    final TemplateRenderingContext context =
        new TemplateRenderingContext(template, writer, getStack(), getParameters(), this);
    engine.renderTemplate(context);
  }
Example #19
0
 /**
  * Checks to see the render phase should be executed next. Mainly used for better debugging
  * messages.
  *
  * @param facesContext The current faces context
  * @param phase The phase id in execution
  * @param before Whether the phase has been executed or not
  * @return True if the response is complete
  */
 protected boolean shouldRenderResponse(FacesContext facesContext, String phase, boolean before) {
   boolean flag = false;
   if (facesContext.getRenderResponse()) {
     if (log.isDebugEnabled())
       log.debug(
           "exiting from lifecycle.execute in "
               + phase
               + " because getRenderResponse is true from one of the "
               + (before ? "before" : "after")
               + " listeners");
     flag = true;
   }
   return flag;
 }
  @Override
  public Object getProperty(Map context, Object target, Object name) throws OgnlException {

    if (LOG.isDebugEnabled()) {
      LOG.debug("Entering getProperty (" + context + "," + target + "," + name + ")");
    }

    ReflectionContextState.updateCurrentPropertyPath(context, name);
    // if this is one of the regular index access
    // properties then just let the superclass deal with the
    // get.
    if (name instanceof String && contains(INDEX_ACCESS_PROPS, (String) name)) {
      return super.getProperty(context, target, name);
    }

    Object result = null;

    try {
      result = super.getProperty(context, target, name);
    } catch (ClassCastException ex) {
    }

    if (result == null) {
      // find the key class and convert the name to that class
      Class lastClass = (Class) context.get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);

      String lastProperty = (String) context.get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED);
      if (lastClass == null || lastProperty == null) {
        return null;
      }
      Object key = getKey(context, name);
      Map map = (Map) target;
      result = map.get(key);

      if (result == null
          && context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null
          && objectTypeDeterminer.shouldCreateIfNew(lastClass, lastProperty, target, null, false)) {
        Class valueClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, key);

        try {
          result = objectFactory.buildBean(valueClass, context);
          map.put(key, result);
        } catch (Exception exc) {

        }
      }
    }
    return result;
  }
Example #21
0
  /** Add map to buffer */
  protected void map(Map map, Method method) throws JSONException {
    this.add("{");

    Iterator it = map.entrySet().iterator();

    boolean warnedNonString = false; // one report per map
    boolean hasData = false;
    while (it.hasNext()) {
      Map.Entry entry = (Map.Entry) it.next();
      if (excludeNullProperties && entry.getValue() == null) {
        continue;
      }

      Object key = entry.getKey();
      if (key == null) {
        LOG.error("Cannot build expression for null key in #0", exprStack);
        continue;
      }

      String expr = null;
      if (this.buildExpr) {
        expr = this.expandExpr(key.toString());
        if (this.shouldExcludeProperty(expr)) {
          continue;
        }
        expr = this.setExprStack(expr);
      }
      if (hasData) {
        this.add(',');
      }
      hasData = true;
      if (!warnedNonString && !(key instanceof String)) {
        if (LOG.isWarnEnabled()) {
          LOG.warn(
              "JavaScript doesn't support non-String keys, using toString() on #0",
              key.getClass().getName());
        }
        warnedNonString = true;
      }
      this.value(key.toString(), method);
      this.add(":");
      this.value(entry.getValue(), method);
      if (this.buildExpr) {
        this.setExprStack(expr);
      }
    }

    this.add("}");
  }
Example #22
0
  public boolean end(Writer writer, String body) {
    String page =
        findString(value, "value", "You must specify the URL to include. Example: /foo.jsp");
    StringBuilder urlBuf = new StringBuilder();

    // Add URL
    urlBuf.append(page);

    // Add request parameters
    if (parameters.size() > 0) {
      urlBuf.append('?');

      String concat = "";

      // Set parameters
      Iterator iter = parameters.entrySet().iterator();

      while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();
        Object name = entry.getKey();
        List values = (List) entry.getValue();

        for (int i = 0; i < values.size(); i++) {
          urlBuf.append(concat);
          urlBuf.append(name);
          urlBuf.append('=');

          try {
            urlBuf.append(URLEncoder.encode(values.get(i).toString(), "UTF-8"));
          } catch (Exception e) {
            LOG.warn("unable to url-encode " + values.get(i).toString() + ", it will be ignored");
          }

          concat = "&";
        }
      }
    }

    String result = urlBuf.toString();

    // Include
    try {
      include(result, writer, req, res);
    } catch (Exception e) {
      LOG.warn("Exception thrown during include of " + result, e);
    }

    return super.end(writer, body);
  }
 private void checkRoles(List<String> roles) {
   if (!areRolesValid(roles)) {
     LOG.fatal("An unknown Role was configured: #0", roles.toString());
     isProperlyConfigured = false;
     throw new IllegalArgumentException("An unknown role was configured: " + roles);
   }
 }
 /**
  * This method returns a {@link Method} in <code>action</code>. The method returned is found by
  * searching for method in <code>action</code> whose method name is equals to the result of
  * appending each <code>prefixes</code> to <code>methodName</code>. Only the first method found
  * will be returned, hence the order of <code>prefixes</code> is important. If none is found this
  * method will return null.
  *
  * @param prefixes the prefixes to prefix the <code>methodName</code>
  * @param methodName the method name to be prefixed with <code>prefixes</code>
  * @param action the action class of which the prefixed method is to be search for.
  * @return a {@link Method} if one is found, else <tt>null</tt>.
  */
 public static Method getPrefixedMethod(String[] prefixes, String methodName, Object action) {
   assert (prefixes != null);
   String capitalizedMethodName = capitalizeMethodName(methodName);
   for (String prefixe : prefixes) {
     String prefixedMethodName = prefixe + capitalizedMethodName;
     try {
       return action.getClass().getMethod(prefixedMethodName, EMPTY_CLASS_ARRAY);
     } catch (NoSuchMethodException e) {
       // hmm -- OK, try next prefix
       if (LOG.isDebugEnabled()) {
         LOG.debug("cannot find method [" + prefixedMethodName + "] in action [" + action + "]");
       }
     }
   }
   return null;
 }
Example #25
0
  /**
   * Prepare a request, including setting the encoding and locale.
   *
   * @param request The request
   * @param response The response
   */
  public void prepare(HttpServletRequest request, HttpServletResponse response) {
    String encoding = null;
    if (defaultEncoding != null) {
      encoding = defaultEncoding;
    }

    Locale locale = null;
    if (defaultLocale != null) {
      locale = LocalizedTextUtil.localeFromString(defaultLocale, request.getLocale());
    }

    if (encoding != null) {
      try {
        request.setCharacterEncoding(encoding);
      } catch (Exception e) {
        LOG.error("Error setting character encoding to '" + encoding + "' - ignoring.", e);
      }
    }

    if (locale != null) {
      response.setLocale(locale);
    }

    if (paramsWorkaroundEnabled) {
      request.getParameter(
          "foo"); // simply read any parameter (existing or not) to "prime" the request
    }
  }
Example #26
0
  public boolean start(Writer writer) {
    boolean result = super.start(writer);

    String actualValue = null;

    if (value == null) {
      value = "top";
    } else {
      value = stripExpressionIfAltSyntax(value);
    }

    // exception: don't call findString(), since we don't want the
    //            expression parsed in this one case. it really
    //            doesn't make sense, in fact.
    actualValue = (String) getStack().findValue(value, String.class, throwExceptionOnELFailure);

    try {
      if (actualValue != null) {
        writer.write(prepare(actualValue));
      } else if (defaultValue != null) {
        writer.write(prepare(defaultValue));
      }
    } catch (IOException e) {
      LOG.info("Could not print out value '" + value + "'", e);
    }

    return result;
  }
Example #27
0
  /**
   * Gracefully shut down this database, releasing any resources that were allocated at
   * initialization.
   *
   * @param event ServletContextEvent to process
   */
  public void contextDestroyed(ServletContextEvent event) {

    log.info("Finalizing memory database plug in");

    if (database != null) {
      try {
        database.close();
      } catch (Exception e) {
        log.error("Closing memory database", e);
      }
    }

    context.removeAttribute(DATABASE_KEY);
    context.removeAttribute(PROTOCOLS_KEY);
    database = null;
    context = null;
  }
Example #28
0
 private void init_CheckWebLogicWorkaround(Container container) {
   // test whether param-access workaround needs to be enabled
   if (servletContext != null
       && servletContext.getServerInfo() != null
       && servletContext.getServerInfo().contains("WebLogic")) {
     if (LOG.isInfoEnabled()) {
       LOG.info("WebLogic server detected. Enabling Struts parameter access work-around.");
     }
     paramsWorkaroundEnabled = true;
   } else {
     paramsWorkaroundEnabled =
         "true"
             .equals(
                 container.getInstance(
                     String.class, StrutsConstants.STRUTS_DISPATCHER_PARAMETERSWORKAROUND));
   }
 }
  protected void process(
      InputStream is, String path, HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    if (is != null) {
      Calendar cal = Calendar.getInstance();

      // check for if-modified-since, prior to any other headers
      long ifModifiedSince = 0;
      try {
        ifModifiedSince = request.getDateHeader("If-Modified-Since");
      } catch (Exception e) {
        log.warn(
            "Invalid If-Modified-Since header value: '"
                + request.getHeader("If-Modified-Since")
                + "', ignoring");
      }
      long lastModifiedMillis = lastModifiedCal.getTimeInMillis();
      long now = cal.getTimeInMillis();
      cal.add(Calendar.DAY_OF_MONTH, 1);
      long expires = cal.getTimeInMillis();

      if (ifModifiedSince > 0 && ifModifiedSince <= lastModifiedMillis) {
        // not modified, content is not sent - only basic
        // headers and status SC_NOT_MODIFIED
        response.setDateHeader("Expires", expires);
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        is.close();
        return;
      }

      // set the content-type header
      String contentType = getContentType(path);
      if (contentType != null) {
        response.setContentType(contentType);
      }

      if (serveStaticBrowserCache) {
        // set heading information for caching static content
        response.setDateHeader("Date", now);
        response.setDateHeader("Expires", expires);
        response.setDateHeader("Retry-After", expires);
        response.setHeader("Cache-Control", "public");
        response.setDateHeader("Last-Modified", lastModifiedMillis);
      } else {
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Expires", "-1");
      }

      try {
        copy(is, response.getOutputStream());
      } finally {
        is.close();
      }
      return;
    }
  }
 /**
  * Persist the User object, including subscriptions, to the database.
  *
  * @throws java.lang.Exception on database error
  */
 public void saveUser() throws Exception {
   try {
     getDatabase().save();
   } catch (Exception e) {
     String message = Constants.LOG_DATABASE_SAVE_ERROR + getUser().getUsername();
     log.error(message, e);
     throw new Exception(message, e);
   }
 }