You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Bruce Miller <br...@nist.gov> on 2006/05/06 15:38:54 UTC

Resource vs. RealPath

Hi Tomcatters;
  A seemingly naive question:
I've got various configuration data, tucked away
under /WEB-INF/.

If I use context.getRealPath(datapath), I can check the
timestamp, so that I know if it needs to be re-read.
However, this fails if we're serving from a .war file
(in which case, presumably it won't need re-reading?)

OTOH, context.getResourceAsStream(datapath) gives no
means to check the timestamp, but will work from .war.

An obvious solution is to use getRealPath to check the
timestamp and getResourceAsStream to read it.
But this seems to mix modes of thinking (A Resource being
something more abstract?).  Experience tells me this
can often lead to problems down the line...

So the question is: Am I missing something?
Is there some other Best Practices approach to this
rather simple situation?

Thanks in advance;
-- 
bruce.miller@nist.gov
http://math.nist.gov/~BMiller/

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


Re: Resource vs. RealPath

Posted by Tim Funk <fu...@joedog.org>.
Its not as expensive as you think. The connection is NOT an HttpConnection. 
Its a connection to a custom resource loader.

-Tim

Bruce Miller wrote:

> Tim Funk wrote:
> 
>> You'll need to clean the following up but you can use this:
>>
>> Date lastModified =
>>   new Date(servletContext
>>              .getResource()
>>              .openConnection()
>>              .getLastModified());
> 
> 
> Ah! I did miss that...  However...
> Openning a connection seems potentially
> more expensive than "merely" getting the timestamp on a file.
> (I was planning on checking this at the beginning of every request,
> and by the time this application is finished, there could
> end up several levels of resources that might occasionally
> get updated).
> Is this likely to be an issue?



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


Re: Resource vs. RealPath

Posted by Bruce Miller <br...@nist.gov>.
Tim Funk wrote:
> You'll need to clean the following up but you can use this:
> 
> Date lastModified =
>   new Date(servletContext
>              .getResource()
>              .openConnection()
>              .getLastModified());

Ah! I did miss that...  However...
Openning a connection seems potentially
more expensive than "merely" getting the timestamp on a file.
(I was planning on checking this at the beginning of every request,
and by the time this application is finished, there could
end up several levels of resources that might occasionally
get updated).
Is this likely to be an issue?

Thanks, in any case, though.

> -Tim
> 
> Bruce Miller wrote:
> 
>> Hi Tomcatters;
>>  A seemingly naive question:
>> I've got various configuration data, tucked away
>> under /WEB-INF/.
>>
>> If I use context.getRealPath(datapath), I can check the
>> timestamp, so that I know if it needs to be re-read.
>> However, this fails if we're serving from a .war file
>> (in which case, presumably it won't need re-reading?)
>>
>> OTOH, context.getResourceAsStream(datapath) gives no
>> means to check the timestamp, but will work from .war.
>>
>> An obvious solution is to use getRealPath to check the
>> timestamp and getResourceAsStream to read it.
>> But this seems to mix modes of thinking (A Resource being
>> something more abstract?).  Experience tells me this
>> can often lead to problems down the line...
>>
>> So the question is: Am I missing something?
>> Is there some other Best Practices approach to this
>> rather simple situation?
>>
>> Thanks in advance;
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 


-- 
bruce.miller@nist.gov
http://math.nist.gov/~BMiller/

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


Re: Resource vs. RealPath

Posted by Tim Funk <fu...@joedog.org>.
You'll need to clean the following up but you can use this:

Date lastModified =
   new Date(servletContext
              .getResource()
              .openConnection()
              .getLastModified());

-Tim

Bruce Miller wrote:
> Hi Tomcatters;
>  A seemingly naive question:
> I've got various configuration data, tucked away
> under /WEB-INF/.
> 
> If I use context.getRealPath(datapath), I can check the
> timestamp, so that I know if it needs to be re-read.
> However, this fails if we're serving from a .war file
> (in which case, presumably it won't need re-reading?)
> 
> OTOH, context.getResourceAsStream(datapath) gives no
> means to check the timestamp, but will work from .war.
> 
> An obvious solution is to use getRealPath to check the
> timestamp and getResourceAsStream to read it.
> But this seems to mix modes of thinking (A Resource being
> something more abstract?).  Experience tells me this
> can often lead to problems down the line...
> 
> So the question is: Am I missing something?
> Is there some other Best Practices approach to this
> rather simple situation?
> 
> Thanks in advance;

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