You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by James Finnall <Ja...@Finnall.net> on 2018/07/17 14:19:43 UTC

best practice for temporary file

Hello all,

What is the best practice under Tomcat to create a data file and then
allow the client to download it?

So far all my attempts have failed.  If the Java app can write it then
the client can not download, if client can download then the Java app
can not write it.

Does Tomcat have a provision to create a directory that be shared by
both the app and the client?


Thank you for your consideration,
James


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


Re: best practice for temporary file

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

Chris,

On 7/17/18 10:36 AM, Chris Cheshire wrote:
> James, this can be done using something like the following 
> configuration in your META-INF/context.xml (I use tomcat 8.5)
> 
> <Resources> <PreResources
> className="org.apache.catalina.webresources.DirResourceSet" 
> base="${catalina.base}/cdn/ROOT/images" webAppMount="/images" /> 
> </Resources>
> 
> I use this to serve files at /images because they are dynamic
> content and not part of the war itself. Make sure the directory
> specified by "base" has read and write permission by the tomcat
> user at the OS level and then you can serve files with a uri
> starting with /images/.

Just be careful about doing this kind of thing because Tomcat will
cache resources it finds there, or at least the metadata about those
files. So if you get a cache miss on a file that doesn't exist, Tomcat
may "remember" that the resource doesn't exist when you write a file
to that directory and then the cache will be stale.

You must arrange for the first access of the file by the client to
occur after the file has been written to the disk, otherwise you risk
these kinds of problems.

Also, things can get weird when the file is subsequently removed.

Just be careful.

- -chris

> On Tue, Jul 17, 2018 at 10:21 AM James Finnall <Ja...@finnall.net>
> wrote:
>> 
>> Hello all,
>> 
>> What is the best practice under Tomcat to create a data file and
>> then allow the client to download it?
>> 
>> So far all my attempts have failed.  If the Java app can write it
>> then the client can not download, if client can download then the
>> Java app can not write it.
>> 
>> Does Tomcat have a provision to create a directory that be shared
>> by both the app and the client?
>> 
>> 
>> Thank you for your consideration, James
>> 
>> 
>> ---------------------------------------------------------------------
>>
>> 
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>> 
> 
> ---------------------------------------------------------------------
>
> 
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAltR9LgACgkQHPApP6U8
pFg2TRAAng/d0PPz5CWwTEgyGvr39+eJ8kFB62f4301s9hVhNbgVZfx0RYn0BOe4
shTqsJ7SHJnQJKf9dfOuEcxm6waMsm8BNir+CeAuDGDGjqTLHurhBCYn1K18IOt2
vb/AqPC/R6uFahipAZ2Rquzl/ee4b+/1ikJmDFa+0psmS/aSLpwGEFUyT2yjgzQF
mP5jQY47nsCikDpXTPhTTRGI1wLM5WsHvxRBeSDWTutK5MSZcscJStEuU+P//KLz
AJYNrGoGv1wGZuAhOizKeR5BKZRp+63TA5xITGGKWNJWhV/q2J1n0u4QESE/4d84
b7k3PvEpb7JQ9uji/U9Ocpm3a7QgoFrMRStvtFiJ8/bRRtpyvgvMvMPB4YQ/Jk41
wvpL8WR6xsXFB27RZU3iqzOPUjARgSOSJXrpQJGbpYZrg/z0Rc4CbIfPiMDafcdr
FScZi5Zp7hpwK6tIq+Apo1KftiQOaiF6pMIizYChp3e4/uVZDgg2GuHQByxeq1LZ
+JeiuTzYG1VJSum3dEYY80CcKtzKol9J6yEa4/9ItetA2vc76TzF/V/4PYtMVRX8
nUePOeICJaaczNIs+P9CjD1mQfcCwn+ZqsKM7nj2jE+XhLfwEClafkVkYE33nI/q
jdzMWjh6VIUFzy2vUhxzW0QHVjEvQNF+vCMUDskHuUxbddswmHs=
=tF8U
-----END PGP SIGNATURE-----

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


Re: best practice for temporary file

Posted by James Finnall <Ja...@Finnall.net>.
Thank you!

Had some problems but I was able to research the issues and find a
solution to what I was doing wrong.  I did not have a "/cdn/ROOT"
directory, mine is "/webapps/ROOT".  The Resource section needs to be
with-in the Context section and not after it.  My original context.xml
file only had two lines.  I had to use two different file paths, since
the application path (/opt/tomcat/..." is different from the client
path (/temp/...).

Once I had the issues corrected it worked great.  Thank you, again.
James

On Tue, 2018-07-17 at 10:36 -0400, Chris Cheshire wrote:
> 
> James, this can be done using something like the following
> configuration in your META-INF/context.xml (I use tomcat 8.5)
> 
> <Resources>
>   <PreResources
> className="org.apache.catalina.webresources.DirResourceSet"
>                 base="${catalina.base}/cdn/ROOT/images"
>                 webAppMount="/images" />
> </Resources>
> 
> I use this to serve files at /images because they are dynamic content
> and not part of the war itself. Make sure the directory specified by
> "base" has read and write permission by the tomcat user at the OS
> level and then you can serve files with a uri starting with /images/.
> 
> HTH
> 
> Chris
> 
> On Tue, Jul 17, 2018 at 10:21 AM James Finnall <Ja...@finnall.net>
> wrote:
> > 
> > 
> > 
> > Hello all,
> > 
> > What is the best practice under Tomcat to create a data file and
> > then
> > allow the client to download it?
> > 
> > So far all my attempts have failed.  If the Java app can write it
> > then
> > the client can not download, if client can download then the Java
> > app
> > can not write it.
> > 
> > Does Tomcat have a provision to create a directory that be shared
> > by
> > both the app and the client?
> > 
> > 
> > Thank you for your consideration,
> > James
> > 
> > 
> > -----------------------------------------------------------------
> > ----
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> > 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org

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


Re: best practice for temporary file

Posted by Chris Cheshire <ya...@gmail.com>.
James, this can be done using something like the following
configuration in your META-INF/context.xml (I use tomcat 8.5)

<Resources>
  <PreResources className="org.apache.catalina.webresources.DirResourceSet"
                base="${catalina.base}/cdn/ROOT/images"
                webAppMount="/images" />
</Resources>

I use this to serve files at /images because they are dynamic content
and not part of the war itself. Make sure the directory specified by
"base" has read and write permission by the tomcat user at the OS
level and then you can serve files with a uri starting with /images/.

HTH

Chris

On Tue, Jul 17, 2018 at 10:21 AM James Finnall <Ja...@finnall.net> wrote:
>
> Hello all,
>
> What is the best practice under Tomcat to create a data file and then
> allow the client to download it?
>
> So far all my attempts have failed.  If the Java app can write it then
> the client can not download, if client can download then the Java app
> can not write it.
>
> Does Tomcat have a provision to create a directory that be shared by
> both the app and the client?
>
>
> Thank you for your consideration,
> James
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

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