dev@javaserverfaces.java.net

Re: Seeking Review: Resource Cache problem

From: Ken Paulsen <Ken.Paulsen_at_Sun.COM>
Date: Wed, 16 Dec 2009 01:29:18 -0800

Hi Ed,

Your observations do not make sense to me, unless initialTime was
incorrect (since that is the only significant change you're making). In
the old code, "initialTime" should have worked if the resource was never
requested (no if-modified-since header would have been sent) or if the
resource was changed (although it then should have sent a 200 response
EVERY request following a change since initialTime stays the same).
FWIW, using Chrome (on Ubuntu), I see the correct behavior from the
browser re: the If-Modified-Since header. That said comparing the
browser's if modified since header (vs. the server's initial time) makes
more sense to me, so I agree with your change.

Nit: In your code below, you do nothing on a parse error, I think a
warning should be output -- otherwise a client w/ an illegal format will
go unnoticed and will be hard to debug.

Related issue: I see that the expires header is set for the
Date.getTime() + maxAge. maxAge has a default value of 604800
milliseconds, which is 10.08 minutes. I believe this was intended to
be: 7 days * 24 hours * 60 min * 60 sec = 604800 *seconds*. If so,
DefaultResourceMaxAge in
jsf-ri/src/com/sun/faces/config/WebConfiguration.java needs 3 more 0's
added to the end of its value.

Thanks,

Ken





Ed Burns wrote:
> Issue: WebKit based browsers don't get resources correctly in
> Development mode
>
>
> I'm pretty sure there is some history around this so I'm mailing it to
> the list before filing an issue. I *do* know that the following
> happens.
>
> I have a simple JSF View with a CSS that lives in a resource library.
> When I browse the view in Firefox, I see the CSS is applied. When I
> browse it in a WebKit based browser (Chrome and Safari), it is not.
>
> Further inspection reveals that WebKit gets sent the 304 always in
> response to the request to the CSS stylesheet, whereas Firefox does not.
> I observed some strange behavior in trying to clear out my browser's
> cache in Firefox and Safari. Sometimes, Firefox would not send an
> If-Modified-Since header at all, other times it would.
>
> I also know that I no longer observe this problem after applying the
> patch here.
>
> Ryan or someone else, is this a real bug? Can I file it and check in
> this fix?
>
>
>
>
> SECTION: Modified Files
> ----------------------------
> M jsf-ri/src/com/sun/faces/application/resource/ResourceImpl.java
>
>
> SECTION: Diffs
> ----------------------------
> Index: jsf-ri/src/com/sun/faces/application/resource/ResourceImpl.java
> ===================================================================
> --- jsf-ri/src/com/sun/faces/application/resource/ResourceImpl.java
> (revision 8233)
> +++ jsf-ri/src/com/sun/faces/application/resource/ResourceImpl.java
> (working copy)
> @@ -43,6 +43,7 @@
> import java.io.ObjectInput;
> import java.net.URL;
> import java.net.URLConnection;
> +import java.text.ParseException;
> import java.text.SimpleDateFormat;
> import java.util.Date;
> import java.util.HashMap;
> @@ -50,6 +51,8 @@
> import java.util.Map;
> import java.util.TimeZone;
> import java.util.Collections;
> +import java.util.logging.Level;
> +import java.util.logging.Logger;
>
> import javax.faces.application.Resource;
> import javax.faces.context.FacesContext;
> @@ -315,12 +318,38 @@
> */
> public boolean userAgentNeedsUpdate(FacesContext context) {
>
> + // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
> + // 14.25 If-Modified-Since
> +
> + // if the requested variant has not been modified since the time
> + // specified in this field, an entity will not be returned
> from the
> + // server; instead, a 304 (not modified) response will be
> returned
> + // without any message-body.
> +
> + // A date which is later than the server's current time is
> + // invalid.
> +
> Map<String,String> requestHeaders =
> context.getExternalContext().getRequestHeaderMap();
> - return ((!requestHeaders.containsKey("If-Modified-Since"))
> - || (resourceInfo.getHelper()
> - .getLastModified(resourceInfo, context) >
> initialTime));
> + boolean result = true;
>
> + if (requestHeaders.containsKey("If-Modified-Since")) {
> + SimpleDateFormat format =
> + new SimpleDateFormat(RFC1123_DATE_PATTERN, Locale.US);
> + Date ifModifiedSinceDate = null;
> + try {
> + ifModifiedSinceDate = format.parse(requestHeaders.
> + get("If-Modified-Since"));
> + long lastModified = resourceInfo.getHelper()
> + .getLastModified(resourceInfo, context);
> + result = lastModified > ifModifiedSinceDate.getTime();
> + } catch (ParseException ex) {
> +
> + }
> +
> + }
> + return result;
> +
> }
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_javaserverfaces.dev.java.net
> For additional commands, e-mail: dev-help_at_javaserverfaces.dev.java.net
>