You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Givler, Eric" <eg...@state.pa.us> on 2008/12/05 16:13:49 UTC

S1: Nocache and SSL

I'm using Struts 1.3.5.

I've run into a snag lately that my struts-config.xml controller nocache setting is causing IE to not download/display a PDF from one of my actions (see http://support.microsoft.com/?kbid=323308).  I thought I could selectively turn off the nocache attribute for the single action that displays the PDF (like recipe 3.18 in Struts Cookbook where they read an ActionMapping which sets a flag).  The issue is that the recipe is for earlier versions of Struts without the ComposableRequestProcessor.

I modified my code to create a command ConfigurableNoCache to replace org.apache.struts.chain.commands.servlet.RequestNoCache.  However, I needed to read the ActionMapping which contains the setting for this action (disabling the cache) and the nocache command appears prior to the lookup of the action config so the context.getActionConfig() returns null.  If I want to put this in place, is there any issue modifying the chain-config like this (moving the nocache command):

  <!-- Set (if needed) no cache HTTP response headers -->
      <!-- <command className="org.apache.struts.chain.commands.servlet.RequestNoCache"/> -->


      <!-- Set (if needed) the HTTP response content type -->
      <command
          className="org.apache.struts.chain.commands.servlet.SetContentType"/>


      <!-- Identify the ActionConfig for this request -->
      <command
          className="org.apache.struts.chain.commands.servlet.SelectAction"/>

      <!-- Need to check no-cache AFTER we have access to the ActionConfig! -->
      <command className="dep.common.struts.ConfigurableNoCache" />


Thanks for any input/assistance on this matter.  I really appreciate it!

Eric Givler






RE: S1: Nocache and SSL

Posted by "Givler, Eric" <eg...@state.pa.us>.
Yes.  I was just wondering if it's an issue to move the location of the nocache handler since I really need access to the ActionMapping which isn't populated until a later step?

Here's what I have in struts-config.xml:

      <action path="/DisplayPDF"
         className="dep.common.struts.NoCacheActionMapping"
              type="view.struts.actions.DisplayPDF_Action"
              scope="request">
         <set-property property="nocache" value="false" />
         <exception type="java.lang.Exception"
                    handler="dep.exception.ExceptionHandler"
                    path="/PDF_Display_Error.do"
                    key="exception.LOG"
                    scope="request" />
      </action>
...
      <controller nocache="true" />

Web.xml points to the updated chain-config.xml which was extracted from the struts-core jar via the chainConfig parameter.

The ActionMapping was taken right out of the book.

The revised command is similar to the book's code:

package dep.common.struts;

import org.apache.struts.action.ActionMapping;
import org.apache.struts.chain.commands.AbstractRequestNoCache;
import org.apache.struts.chain.contexts.ActionContext;
import org.apache.struts.chain.contexts.ServletActionContext;

import javax.servlet.http.HttpServletResponse;
import org.apache.struts.config.ActionConfig;

/**
 * <p>Check to see if the controller is configured to prevent caching, and if
 * so, set the no cache HTTP response headers.</p>
 */
public class ConfigurableNoCache extends AbstractRequestNoCache {
    // ------------------------------------------------------- Protected Methods
    protected void requestNoCache(ActionContext context)
    {
        boolean nocache = true; // default to nocache

        ActionConfig mapping = context.getActionConfig();
        if (mapping != null ) {
           if ( mapping instanceof NoCacheActionMapping ) {
              NoCacheActionMapping customMapping = (NoCacheActionMapping) mapping;
              nocache = customMapping.isNocacheEnabled();
           }
        }

        if ( nocache )
        {  // Standard struts code follows...
           ServletActionContext sacontext = (ServletActionContext) context;
           HttpServletResponse response = sacontext.getResponse();
           response.setHeader("Pragma", "No-cache");
           response.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
           response.setDateHeader("Expires", 1);
        }
    } // requestNoCache

}



-----Original Message-----
From: paulus.benedictus@gmail.com [mailto:paulus.benedictus@gmail.com] On Behalf Of Paul Benedict
Sent: Thursday, December 18, 2008 11:14 PM
To: Struts Users Mailing List
Subject: Re: S1: Nocache and SSL


Sounds like an interesting idea. Are you using <set-property> within the action config to turn caching off only where you need it?

On Fri, Dec 5, 2008 at 9:13 AM, Givler, Eric <eg...@state.pa.us> wrote:
> I'm using Struts 1.3.5.
>
> I've run into a snag lately that my struts-config.xml controller
> nocache setting is causing IE to not download/display a PDF from one
> of my actions (see http://support.microsoft.com/?kbid=323308).  I
> thought I could selectively turn off the nocache attribute for the
> single action that displays the PDF (like recipe 3.18 in Struts
> Cookbook where they read an ActionMapping which sets a flag).  The
> issue is that the recipe is for earlier versions of Struts without the
> ComposableRequestProcessor.
>
> I modified my code to create a command ConfigurableNoCache to replace
> org.apache.struts.chain.commands.servlet.RequestNoCache.  However, I
> needed to read the ActionMapping which contains the setting for this
> action (disabling the cache) and the nocache command appears prior to
> the lookup of the action config so the context.getActionConfig()
> returns null.  If I want to put this in place, is there any issue
> modifying the chain-config like this (moving the nocache command):
>
>  <!-- Set (if needed) no cache HTTP response headers -->
>      <!-- <command
> className="org.apache.struts.chain.commands.servlet.RequestNoCache"/>
> -->
>
>
>      <!-- Set (if needed) the HTTP response content type -->
>      <command
>
> className="org.apache.struts.chain.commands.servlet.SetContentType"/>
>
>
>      <!-- Identify the ActionConfig for this request -->
>      <command
>
> className="org.apache.struts.chain.commands.servlet.SelectAction"/>
>
>      <!-- Need to check no-cache AFTER we have access to the ActionConfig! -->
>      <command className="dep.common.struts.ConfigurableNoCache" />
>
>
> Thanks for any input/assistance on this matter.  I really appreciate
> it!
>
> Eric Givler
>
>
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: S1: Nocache and SSL

Posted by Paul Benedict <pb...@apache.org>.
Sounds like an interesting idea. Are you using <set-property> within
the action config to turn caching off only where you need it?

On Fri, Dec 5, 2008 at 9:13 AM, Givler, Eric <eg...@state.pa.us> wrote:
> I'm using Struts 1.3.5.
>
> I've run into a snag lately that my struts-config.xml controller nocache setting is causing IE to not download/display a PDF from one of my actions (see http://support.microsoft.com/?kbid=323308).  I thought I could selectively turn off the nocache attribute for the single action that displays the PDF (like recipe 3.18 in Struts Cookbook where they read an ActionMapping which sets a flag).  The issue is that the recipe is for earlier versions of Struts without the ComposableRequestProcessor.
>
> I modified my code to create a command ConfigurableNoCache to replace org.apache.struts.chain.commands.servlet.RequestNoCache.  However, I needed to read the ActionMapping which contains the setting for this action (disabling the cache) and the nocache command appears prior to the lookup of the action config so the context.getActionConfig() returns null.  If I want to put this in place, is there any issue modifying the chain-config like this (moving the nocache command):
>
>  <!-- Set (if needed) no cache HTTP response headers -->
>      <!-- <command className="org.apache.struts.chain.commands.servlet.RequestNoCache"/> -->
>
>
>      <!-- Set (if needed) the HTTP response content type -->
>      <command
>          className="org.apache.struts.chain.commands.servlet.SetContentType"/>
>
>
>      <!-- Identify the ActionConfig for this request -->
>      <command
>          className="org.apache.struts.chain.commands.servlet.SelectAction"/>
>
>      <!-- Need to check no-cache AFTER we have access to the ActionConfig! -->
>      <command className="dep.common.struts.ConfigurableNoCache" />
>
>
> Thanks for any input/assistance on this matter.  I really appreciate it!
>
> Eric Givler
>
>
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org