You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Stephen Bacon <sb...@13x.com> on 2002/08/14 01:19:40 UTC

Writing files from a class

Hello,
  I'm trying to migrate from Tomcat 3 to Catalina (under Linux) and I've
hit a snag. Several of my custom classes which I use from JSPs (e.g.
ConnectionPool) print messages to debug files which I access via:
  <snip>
  pwDebug = new PrintWriter(new FileOutputStream(m_sDebugFileName,
true));
  pwDebug.println(m_sdf.format(new java.util.Date()) + " " + sparMsg);
  <snip>

Previously, it would create / append to the file in the location that
Tomcat was started from (so I had made sure it was always done from a
logs directory - a kludge yes, but it worked)

Well, Tomcat 4 seems to have added security which is blocking this. I
made a modification to pull the debug file name from the web.xml file
and made sure the target directory specified
(/var/tomcat4/webapps/<appname>/logs) was owned by the user "tomcat4",
and had the write flags turned on.

No go - still no debug file (it writes an init message so there should
be something)

This of course is a big problem because my classes have now all become
black boxes and I'm unable to debug problems.

Is this something to do with security under T4? Is there a "proper"
means by which messages should be logged? Have I configured something
wrong?

The app seems to be running OK, but I have no way to be sure without the
ability to print debug messages.

Any ideas?

thanks,
  -Steve



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Writing files from a class

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On 14 Aug 2002, Stephen Bacon wrote:

> Date: 14 Aug 2002 11:09:16 -0400
> From: Stephen Bacon <sb...@13x.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: RE: Writing files from a class
>
> Thanks for the reply,
>
> I see that the spec mentions "private temporary directory" - I need a
> permananent directory - by temporary I take it to mean that I can't
> count on the files "sticking around". Is my understanding here flawed?
>

No, you've got it right.  There is no current portable mechanism for
per-webapp persistent file storage.  Options include:
* Pass the pathname to a directory in an init parameter
* Store stuff in a database/directory server instead
* On JDK 1.4, consider using the new Preferences API
  (java.util.prefs) for storing stuff.

> Also, I'd like to be able to specify the name and location.
> I had seen the javax.servlet.ServletContext.log() methods, but they seem
> to offer no control over where the output is placed. I'd rather have a
> debug file per class than have all messages sent to a single file.
>

Mapping of ServletContext.log() calls to particular destinations is
specific to the server you are using.  For Tomcat 4, you can use <Logger>
elements to have log files per-webapp, per-host, or per-server, but not
per-caller (which makes sense -- how is the log() method supposed to know
who the caller is)?

For finer grained debugging-type logging, I'd suggest looking at things
like Log4J or the JDK 1.4 logging methods.

> And finally, I have servlets that take data from a db and place it in a
> (text) file for the user to download - so once again a file creation
> issue where I need a general file i/o solution.
>

Is there a particular reason that you make it a file instead of just
grabbing the data from the database every time?  Or, for performance,
caching it in memory at app startup and just serving the characters out of
a saved String or something?

After all, the client has no way of knowing whether a request URL like
"/foo/bar/baz.html" was really a static resource or not.

> thanks,
> -Steve

Craig


>
> On Tue, 2002-08-13 at 20:15, Sexton, George wrote:
> > >From the servlet 2.3 Specification:
> >
> > SRV.3.7.1 Temporary Working Directories
> >
> > A temporary storage directory is required for each servlet context. Servlet
> > containers must provide a private temporary directory per servlet context,
> > and make
> > it available via the javax.servlet.context.tempdir context attribute. The
> > objects
> > associated with the attribute must be of type java.io.File.
> >
> >
> > -----Original Message-----
> > From: Stephen Bacon [mailto:sbacon@13x.com]
> > Sent: 13 August, 2002 5:20 PM
> > To: tomcat-user@jakarta.apache.org
> > Subject: Writing files from a class
> >
> >
> > Hello,
> >   I'm trying to migrate from Tomcat 3 to Catalina (under Linux) and I've
> > hit a snag. Several of my custom classes which I use from JSPs (e.g.
> > ConnectionPool) print messages to debug files which I access via:
>
> <snip>
>
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Writing files from a class

Posted by Stephen Bacon <sb...@13x.com>.
Thanks for the reply,

I see that the spec mentions "private temporary directory" - I need a
permananent directory - by temporary I take it to mean that I can't
count on the files "sticking around". Is my understanding here flawed?

Also, I'd like to be able to specify the name and location.
I had seen the javax.servlet.ServletContext.log() methods, but they seem
to offer no control over where the output is placed. I'd rather have a
debug file per class than have all messages sent to a single file.

And finally, I have servlets that take data from a db and place it in a
(text) file for the user to download - so once again a file creation
issue where I need a general file i/o solution.

thanks,
-Steve

On Tue, 2002-08-13 at 20:15, Sexton, George wrote:
> >From the servlet 2.3 Specification:
> 
> SRV.3.7.1 Temporary Working Directories
> 
> A temporary storage directory is required for each servlet context. Servlet
> containers must provide a private temporary directory per servlet context,
> and make
> it available via the javax.servlet.context.tempdir context attribute. The
> objects
> associated with the attribute must be of type java.io.File.
> 
> 
> -----Original Message-----
> From: Stephen Bacon [mailto:sbacon@13x.com]
> Sent: 13 August, 2002 5:20 PM
> To: tomcat-user@jakarta.apache.org
> Subject: Writing files from a class
> 
> 
> Hello,
>   I'm trying to migrate from Tomcat 3 to Catalina (under Linux) and I've
> hit a snag. Several of my custom classes which I use from JSPs (e.g.
> ConnectionPool) print messages to debug files which I access via:

<snip>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Writing files from a class

Posted by "Sexton, George" <gs...@mhsoftware.com>.
>From the servlet 2.3 Specification:

SRV.3.7.1 Temporary Working Directories

A temporary storage directory is required for each servlet context. Servlet
containers must provide a private temporary directory per servlet context,
and make
it available via the javax.servlet.context.tempdir context attribute. The
objects
associated with the attribute must be of type java.io.File.


-----Original Message-----
From: Stephen Bacon [mailto:sbacon@13x.com]
Sent: 13 August, 2002 5:20 PM
To: tomcat-user@jakarta.apache.org
Subject: Writing files from a class


Hello,
  I'm trying to migrate from Tomcat 3 to Catalina (under Linux) and I've
hit a snag. Several of my custom classes which I use from JSPs (e.g.
ConnectionPool) print messages to debug files which I access via:
  <snip>
  pwDebug = new PrintWriter(new FileOutputStream(m_sDebugFileName,
true));
  pwDebug.println(m_sdf.format(new java.util.Date()) + " " + sparMsg);
  <snip>

Previously, it would create / append to the file in the location that
Tomcat was started from (so I had made sure it was always done from a
logs directory - a kludge yes, but it worked)

Well, Tomcat 4 seems to have added security which is blocking this. I
made a modification to pull the debug file name from the web.xml file
and made sure the target directory specified
(/var/tomcat4/webapps/<appname>/logs) was owned by the user "tomcat4",
and had the write flags turned on.

No go - still no debug file (it writes an init message so there should
be something)

This of course is a big problem because my classes have now all become
black boxes and I'm unable to debug problems.

Is this something to do with security under T4? Is there a "proper"
means by which messages should be logged? Have I configured something
wrong?

The app seems to be running OK, but I have no way to be sure without the
ability to print debug messages.

Any ideas?

thanks,
  -Steve



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>