No this would be very minor.  It may not even be worth making the change I 
outlined below if you're not comfortable.  It certainly would save several ms 
when running however - lots of unnecessary exceptions are being thrown, and 
each one by itself is expensive enough.

I'm not sure yet if its ever running when it's not supposed to.  I'll keep a 
breakpoint around and if I can pin down a way it runs through that unexpectedly 
I'll revive the thread.  And if that happens you'd probably have to make a 
change at a higher stack frame than the one I noted below =)

From: Ben Gunter [mailto:gunter...@gmail.com]
Sent: Thursday, January 13, 2011 12:55 PM
To: Stripes Users List
Subject: Re: [Stripes-users] Disabling the flash scope feature?

Probably the better thing to do would be to parse the string in 
getDateHeader(..) instead. When I did it the way I did it, I just figured I'd 
let the container handle the parsing ahead of time so I'd have less chance of 
screwing it up. Since Stripes and Tomcat have the same license, I can just lift 
the code directly from Tomcat.

Out of curiosity, is this really that much of a problem? It should only execute 
if you're intentionally (whether directly or indirectly) using flash scope, so 
it should be infrequent. If this is executing at a time when you're not 
explicitly putting something in flash and you're not adding messages then 
redirecting, then that's a problem that needs to be investigated.

-Ben
On Thu, Jan 13, 2011 at 12:23 PM, Newman, John W 
<john.new...@viaoncology.com<mailto:john.new...@viaoncology.com>> wrote:
" Stripes uses the flash scope implicitly"
Right, I was thinking that might be the case.  So even if I'm not deliberately 
using it, I am actually using it and can't disable it.  That's fine - so 
nevermind about the disable feature.

But this doesn't look very good, see the FlashRequest constructor:

  /**
    * Creates a new FlashRequest by copying all appropriate attributes from the 
prototype
    * request supplied.
    *
    * @param prototype the HttpServletRequest to create a disconnected copy of
    */
   @SuppressWarnings({ "unchecked", "deprecation" })
   public FlashRequest(HttpServletRequest prototype) {
 .....  snip .....
       // copy headers
       for (String key : Collections.list((Enumeration<String>) 
prototype.getHeaderNames())) {
           headers.put(key, Collections.list(prototype.getHeaders(key)));
           try {
               dateHeaders.put(key, prototype.getDateHeader(key));
           }   catch (Exception e) {
           }
       }
       // copy locales
       locales = Collections.list(prototype.getLocales());
       // copy parameters
       parameters.putAll(prototype.getParameterMap());
   }

Maybe we can do better there.  Can we add a specific set of header names that 
can be converted to dates, instead of blindly trying to convert every single 
header to a date which results in many many exceptions occurring and being 
suprressed.  If you can prevent an exception with a simple if check, it is far 
less expensive to do that first instead of letting it occur and catching it.  
Right?

-------------------- patch
private static final Set<String> possibleDateHeaders = new HashSet<String>();
static  {
  possibleDateHeaders.add("Date");
  possibleDateHeaders.add("If-Modified-Since");
 ...  see http://en.wikipedia.org/wiki/List_of_HTTP_header_fields
}

... if (possibleDateHeaders.contains(key))  {
       try  {
          dateHeaders.put(key, prototype.getDateHeader(key));
       } catch (IllegalArgumentException e)  {
                        // should no longer occur since we only call when it 
will succeed.  Right?
       }
}

That would eliminate the issue I saw this morning, all this extra failed date 
parsing on things like the content-type header etc.

-J

-----Original Message-----
From: Freddy Daoud [mailto:xf2...@fastmail.fm<mailto:xf2...@fastmail.fm>]
Sent: Thursday, January 13, 2011 11:54 AM
To: Stripes Users List
Subject: Re: [Stripes-users] Disabling the flash scope feature?

Hi John,

> Should I
> look at using flash scope because I'm missing how powerful it is?  (I
> haven't seen a need for it yet).

Well, it's not so much that you would use the flash scope directly, but it is 
used implicitly in some useful ways. One common example that comes to mind is 
when you submit a form that saves some data to the database. Afterwards, you 
want to do a redirect (to avoid resubmitting the form on a browser refresh) and 
you want to show some kind of "the data has been saved" message on the page. 
You would use a Stripes message and <stripes:messages/> for that.
Stripes uses the flash scope implicitly to make the messages survive the 
additional request done by the redirect.

Cheers,
Freddy

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks Learn about various 
malware tactics and how to avoid them. Understand malware threats, the impact 
they can have on your business, and how you can protect your company and 
customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net<mailto:Stripes-users@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/stripes-users
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net<mailto:Stripes-users@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to