You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Yoryos <va...@gmail.com> on 2008/09/03 13:14:11 UTC

Etags vs Week Etags

Hi all,
I don't know if I should be postting the the dev list but let's try from
here.

I'm trying to understand how the etag are being applying to the static
resources. My problem is that I would like to get rid of the week etags,
that tomcat is applying. After a little bit of searching I ended up to the
org.apache.naming.resources.ResourceAttributes class where I found the
getETag(boolean strong) method. It's a very small method but I didn't
understand a small thing. Well the method is the above:


    public String getETag(boolean strong) {
        String result = null;
        if (attributes != null) {
            Attribute attribute = attributes.get(ETAG);
            if (attribute != null) {
                try {
                    result = attribute.get().toString();
                } catch (NamingException e) {
                    ; // No value for the attribute
                }
            }
        }
        if (strong) {
            // The strong ETag must always be calculated by the resources
            result = strongETag;
        } else {
            // The weakETag is contentLenght + lastModified
            if (weakETag == null) {
                weakETag = "W/\"" + getContentLength() + "-"
                    + getLastModified() + "\"";
            }
            result = weakETag;
        }
        return result;
    }


And my question is what the first if condition stand's for. Even if we'll
get an etag value (result = attribute.get().toString();), exatly after the
first if block, we get if / else blocks witch results to overriding the
previous result value to a strongETag or a weekETag!

What made me trying to find what is going on is that I always get week etags
for my static resources, witch is something I whould like to overcome as
some browsers doesn't handle them really well.

Thank you!

Re: Etags vs Week Etags

Posted by Robert Koberg <ro...@koberg.com>.
On Sep 11, 2008, at 11:44 AM, Christopher Schultz wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Robert,
>
> Robert Koberg wrote:
>> On Sep 11, 2008, at 10:36 AM, Christopher Schultz wrote:
>>
>>> Huh? The DefaultServlet handles XSLT? Which version of TC is that  
>>> in?
>>
>> There is XSL for directory listings by default.
>
> Okay, that makes WAY more sense. Otherwise, I've been wasting a / 
> lot/ of
> time with Cocoon! ;)

Otherwise? :)



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Etags vs Week Etags

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Robert,

Robert Koberg wrote:
> On Sep 11, 2008, at 10:36 AM, Christopher Schultz wrote:
>
>> Huh? The DefaultServlet handles XSLT? Which version of TC is that in?
> 
> There is XSL for directory listings by default.

Okay, that makes WAY more sense. Otherwise, I've been wasting a /lot/ of
time with Cocoon! ;)

(Just kidding, Cocoon totally rocks)

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkjJPM4ACgkQ9CaO5/Lv0PCgOACgsQqurWAYbuGIEKumqK7PjryZ
Zp0An2w6302qRonjzi1ICYJLeVSNjZfL
=Wsrj
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Etags vs Week Etags

Posted by Robert Koberg <ro...@koberg.com>.
On Sep 11, 2008, at 10:36 AM, Christopher Schultz wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Johnny,
>
> Johnny Kewl wrote:
>> For example if you want XSLT in tomcat, first impression is its  
>> xerces

(Jumping without reading previous posts)

You first impression is wrong :) Xerces is an XML parser. Xalan (and  
better, Saxon) is an XSL processor. Xalan is built into the JDK, so  
you get that by default unless you change the JAXP system property.


>>
>> and a complex servlet and lots of pain... you actually think tomcat  
>> cant
>> do it, but then you look at the default servlet and "Obama!" its  
>> there
>> ;) I call it TC's hidden gold mine ;)


Saxon (preferably v 9x, so XSL 2.0) has a nice, simple servlet example  
for XSL/XML transformations.

(On another thread in this list, someone was talking about disabling  
everything but taglibs in JSP. Well, if you used well-formed JSP, you  
could stick an XSL filter before the JSP and use an identity transform  
to strip out the things you don't want.)


>>
>
> Huh? The DefaultServlet handles XSLT? Which version of TC is that in?


There is XSL for directory listings by default.

best,
-Rob

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Etags vs Week Etags

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Johnny,

Johnny Kewl wrote:
> For example if you want XSLT in tomcat, first impression is its xerces
> and a complex servlet and lots of pain... you actually think tomcat cant
> do it, but then you look at the default servlet and "Obama!" its there
> ;) I call it TC's hidden gold mine ;)

Huh? The DefaultServlet handles XSLT? Which version of TC is that in?

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkjJLQUACgkQ9CaO5/Lv0PCsMACePMBUKaiBBNSa4Pas1rAWHMrs
+AMAniYceggtNMymZBnKe28WfKaTt8vc
=6X5C
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Etags vs Week Etags

Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
----- Original Message ----- 
From: "Yoryos" <va...@gmail.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Wednesday, September 03, 2008 8:57 PM
Subject: Re: Etags vs Week Etags


> On Wed, Sep 3, 2008 at 8:12 PM, Johnny Kewl <jo...@kewlstuff.co.za> wrote:
>
>>
>> Flipping good question... and I have a feeling that there is some
>> philosophy in the answer... reasons for the way it done...
>> The short answer is that you cant (I think)... the default servlet makes 
>> em
>> weak (thats the philamamasomamy)...
>> That first section (strong) does nothing... the reason is that the 
>> setEtag
>> method is there but as far as i can tell, never ever called by anything 
>> in
>> Tomcat.
>> Its a hook...
>>
>> But stay calm... there are ways...
>>
>> This clever guy did this...
>>
>> http://blog.bcarlso.net/articles/2007/10/19/tomcat-weak-etags-and-javascript-css-caching
>>
>> He is basically overriding the default servlet stuff to get things 
>> done....
>> its smart, he knows his tomcat, but personally I dont like it...
>>
>> I think the generic problem is that a static resource cant control its
>> Etag... its a dumb image, and secondly no matter what a web server does,
>> another web server is going to do it different, so strong loses its 
>> meaning
>> (more philamamasomamy)... or more simply, you just got to do it 
>> yourself...
>>
>> I would prefer (or try, I havnt giving this a go)... make a little 
>> servlet,
>> set the Etag headers yourself, map it to all the static resources you 
>> want
>> to control...
>> And then do what you have to
>>
>> getContentLength() + "-" + getLastModified() + IncludeFiles() +
>> IncludedImages() + WhateEver() "\"";
>>
>> etc... I think thats easiest...
>>
>> The philamamasomamy on why TC chose to make it weak would be interesting 
>> to
>> hear, but I do think that any serious scheme... on its way to some kind 
>> of
>> private RSS system... will be doing its own thing.
>>
>> Have fun... nice question
>>
>>
> Well a quick solution is to extend the DefaultServlet to apply a "good"
> etag. But then I should also check for this etag in case I have a request
> with headers If-None-Match. This means that I should also extend the
> org.apache.naming.resources.ResourceAttributes
> class in order to be giving me a "good" etag.
> I don't really care about the philosophy of using week etags. I'm sure 
> there
> is one but as I can see there isn't any easy way of letting the user 
> decide
> the default headers of static content except from reinventing the wheel
> (creating a custom DefaultServlet) and I think this is a problem as the
> implementation of a new DefaultServlet isn't as easy as it seems to be.

I would try front end servlet, or a filter before massaging default 
servlet...
but I agree, there is a lot of functionality in that deafult servlet that 
could be brought out...
As options and as extended tools in normal servlets.

Probably has a lot to do with following Suns specs to the letter, which is a 
good thing I guess.
For example if you want XSLT in tomcat, first impression is its xerces and a 
complex servlet and lots of pain... you actually think tomcat cant do it, 
but then you look at the default servlet and "Obama!" its there ;) I call it 
TC's hidden gold mine ;)

---------------------------------------------------------------------------
HARBOR : http://www.kewlstuff.co.za/index.htm
The most powerful application server on earth.
The only real POJO Application Server.
See it in Action : http://www.kewlstuff.co.za/cd_tut_swf/whatisejb1.htm
--------------------------------------------------------------------------- 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Etags vs Week Etags

Posted by Yoryos <va...@gmail.com>.
On Wed, Sep 3, 2008 at 8:12 PM, Johnny Kewl <jo...@kewlstuff.co.za> wrote:

>
> Flipping good question... and I have a feeling that there is some
> philosophy in the answer... reasons for the way it done...
> The short answer is that you cant (I think)... the default servlet makes em
> weak (thats the philamamasomamy)...
> That first section (strong) does nothing... the reason is that the setEtag
> method is there but as far as i can tell, never ever called by anything in
> Tomcat.
> Its a hook...
>
> But stay calm... there are ways...
>
> This clever guy did this...
>
> http://blog.bcarlso.net/articles/2007/10/19/tomcat-weak-etags-and-javascript-css-caching
>
> He is basically overriding the default servlet stuff to get things done....
> its smart, he knows his tomcat, but personally I dont like it...
>
> I think the generic problem is that a static resource cant control its
> Etag... its a dumb image, and secondly no matter what a web server does,
> another web server is going to do it different, so strong loses its meaning
> (more philamamasomamy)... or more simply, you just got to do it yourself...
>
> I would prefer (or try, I havnt giving this a go)... make a little servlet,
> set the Etag headers yourself, map it to all the static resources you want
> to control...
> And then do what you have to
>
> getContentLength() + "-" + getLastModified() + IncludeFiles() +
> IncludedImages() + WhateEver() "\"";
>
> etc... I think thats easiest...
>
> The philamamasomamy on why TC chose to make it weak would be interesting to
> hear, but I do think that any serious scheme... on its way to some kind of
> private RSS system... will be doing its own thing.
>
> Have fun... nice question
>
>
Well a quick solution is to extend the DefaultServlet to apply a "good"
etag. But then I should also check for this etag in case I have a request
with headers If-None-Match. This means that I should also extend the
org.apache.naming.resources.ResourceAttributes
class in order to be giving me a "good" etag.
I don't really care about the philosophy of using week etags. I'm sure there
is one but as I can see there isn't any easy way of letting the user decide
the default headers of static content except from reinventing the wheel
(creating a custom DefaultServlet) and I think this is a problem as the
implementation of a new DefaultServlet isn't as easy as it seems to be.

Re: Etags vs Week Etags

Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
----- Original Message ----- 
From: "Yoryos" <va...@gmail.com>
To: <us...@tomcat.apache.org>
Sent: Wednesday, September 03, 2008 1:14 PM
Subject: Etags vs Week Etags


> Hi all,
> I don't know if I should be postting the the dev list but let's try from
> here.
>
> I'm trying to understand how the etag are being applying to the static
> resources. My problem is that I would like to get rid of the week etags,
> that tomcat is applying. After a little bit of searching I ended up to the
> org.apache.naming.resources.ResourceAttributes class where I found the
> getETag(boolean strong) method. It's a very small method but I didn't
> understand a small thing. Well the method is the above:
>
>
>    public String getETag(boolean strong) {
>        String result = null;
>        if (attributes != null) {
>            Attribute attribute = attributes.get(ETAG);
>            if (attribute != null) {
>                try {
>                    result = attribute.get().toString();
>                } catch (NamingException e) {
>                    ; // No value for the attribute
>                }
>            }
>        }
>        if (strong) {
>            // The strong ETag must always be calculated by the resources
>            result = strongETag;
>        } else {
>            // The weakETag is contentLenght + lastModified
>            if (weakETag == null) {
>                weakETag = "W/\"" + getContentLength() + "-"
>                    + getLastModified() + "\"";
>            }
>            result = weakETag;
>        }
>        return result;
>    }
>
>
> And my question is what the first if condition stand's for. Even if we'll
> get an etag value (result = attribute.get().toString();), exatly after the
> first if block, we get if / else blocks witch results to overriding the
> previous result value to a strongETag or a weekETag!
>
> What made me trying to find what is going on is that I always get week 
> etags
> for my static resources, witch is something I whould like to overcome as
> some browsers doesn't handle them really well.
>
> Thank you!

Flipping good question... and I have a feeling that there is some philosophy 
in the answer... reasons for the way it done...
The short answer is that you cant (I think)... the default servlet makes em 
weak (thats the philamamasomamy)...
That first section (strong) does nothing... the reason is that the setEtag 
method is there but as far as i can tell, never ever called by anything in 
Tomcat.
Its a hook...

But stay calm... there are ways...

This clever guy did this...
http://blog.bcarlso.net/articles/2007/10/19/tomcat-weak-etags-and-javascript-css-caching

He is basically overriding the default servlet stuff to get things done.... 
its smart, he knows his tomcat, but personally I dont like it...

I think the generic problem is that a static resource cant control its 
Etag... its a dumb image, and secondly no matter what a web server does, 
another web server is going to do it different, so strong loses its meaning 
(more philamamasomamy)... or more simply, you just got to do it yourself...

I would prefer (or try, I havnt giving this a go)... make a little servlet, 
set the Etag headers yourself, map it to all the static resources you want 
to control...
And then do what you have to

getContentLength() + "-" + getLastModified() + IncludeFiles() + 
IncludedImages() + WhateEver() "\"";

etc... I think thats easiest...

The philamamasomamy on why TC chose to make it weak would be interesting to 
hear, but I do think that any serious scheme... on its way to some kind of 
private RSS system... will be doing its own thing.

Have fun... nice question

---------------------------------------------------------------------------
HARBOR : http://www.kewlstuff.co.za/index.htm
The most powerful application server on earth.
The only real POJO Application Server.
See it in Action : http://www.kewlstuff.co.za/cd_tut_swf/whatisejb1.htm
---------------------------------------------------------------------------






---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org