Re: How to configure logging in embedded Tomcat?

2011-06-24 Thread Rüdiger Herrmann
In the meanwhile, I found a way to work around the problem. Just for the record:

Tomcat uses plain JDK logging, so one can obtain a logger with
Logger#getLogger() and change its settings before Tomcat obtains a
reference. As loggers are held in WeakReferences, you only need to
make sure that they are not GC'ed. (Note: I use embedded Tomcat in
tests and thus can affort to hold on some Logger instances, this is
probably not a good idea for production evironments)

The code could look like this:
  static final List loggerHolder = new LinkedList();

  Logger logger = Logger.getLogger( "name.of.Logger" );
  loggerHolder.add( logger );
  logger.setLevel( Level.SEVERE );

On Tue, Jun 14, 2011 at 18:15, Rüdiger Herrmann
 wrote:
> ups, sorry. I am using version 7.
>
> On Tue, Jun 14, 2011 at 18:03, Mark Thomas  wrote:
>> On 14/06/2011 16:24, Rüdiger Herrmann wrote:
>>> Hi all,
>>>
>>> I am running Tomcat embedded and just can't figure out how to
>>> programmatically configure the logging of the engine itself.
>>> Ideally I would redirect logging to a custom implementation, but
>>> changing the log level (to off) would already help.
>>> The LogFactory doesn't seem to offer such functionality (?) and
>>> manipulating the underlying java.util.logging.Logger didn't help
>>> either.
>>> Any insights?
>>
>> Without you telling us the Tomcat version you are using, insight is
>> unlikely.
>>
>> Mark
>>
>>
>>
>> -
>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>> For additional commands, e-mail: users-h...@tomcat.apache.org
>>
>>
>
>
>
> --
> --
> EclipseSource
> http://eclipsesource.com
> Tel: 0721 - 66 47 33 - 0
> Fax: 0721 - 66 47 33 29
>
> Innoopract Informationssysteme GmbH
> Stephanienstrasse 20, 76133 Karlsruhe, Germany
> General Manager: Jochen Krause
> Registered Office: Karlsruhe, Commercial Register Mannheim HRB 107883
>

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



Re: log4j logging works for webapps but not for server,

2011-06-24 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

To whom it may concern,

On 6/24/2011 12:18 PM, jjgtx wrote:
> Christopher Schultz-2 wrote:
>> Where did you put your log4j.properties file and what does it contain?
>> Can you just post the whole thing?
>
> [I put log4j.properties in] $CATALINA_HOME/lib
> 
> I hate to post the whole thing, its a bit long would it be better to send
> it?

I was mainly concerned with what you appender configuration looked like,
in case you misconfigured something there and therefore were getting no
logs due to that.

Is your configuration file similar to that described in
http://tomcat.apache.org/tomcat-6.0-doc/logging.html#Using_Log4j?

Given the output on startup:

> log4j: Handling log4j.additivity.org.apache.catalina=[null]
> log4j: Parsing for [org] with value=[WARN].
> log4j: Level token is [WARN].

I suspect that log4j is actually being loaded and configured, though :)

> One thing I was curious about is that should be the value of the
> $LOGGING_CONFIG property. I used the path to the log4j file. 

I don't believe you need to set LOGGING_CONFIG to anything: I believe
LOGGING_CONFIG is only used for the JULI configuration (which is
mutually exclusive to using log4j).

Try significantly simplifying your environment and configuration:

0. Shut-down Tomcat and delete all files from logs/
1. Don't deploy any webapps... just work with Tomcat itself for now
2. Remove all appenders except for a single FileAppender,
   point that to a writable file, set the log level to INFO
3. Make sure you have:

   log4j.rootCategory=INFO,[appendername]

Start up Tomcat and see if you get anything in your log file. There
should be a few INFO messages in there.

If that doesn't work, please post your whole (simplified as described
above) log file and a complete dump of:

1. logs/catalina.out
2. logs/*   (any other files that are created on startup,
   even if they are empty)

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

iEYEARECAAYFAk4Ewr0ACgkQ9CaO5/Lv0PC22gCfekanthUWmdkA6SLKeGbRjVgh
SgwAnA89L6+n2KbTnn8iUIg46Ywwpg9Z
=Pn/U
-END PGP SIGNATURE-

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



Re: TC 7.0.16 IllegalStateException thrown by pageContext.include

2011-06-24 Thread David Wall



On 6/24/2011 5:48 AM, Rainer Jung wrote:

On 24.06.2011 14:08, Tim Funk wrote:Looks like this is the root cause from 
DefaultServlet ...

While the ISE is caught ... since the mimetype for js was changed - it
doesn't match the fallback method 

 try {
 ostream = response.getOutputStream();
 } catch (IllegalStateException e) {
 // If it fails, we try to get a Writer instead if we're
 // trying to serve a text file
 if ( (contentType == null)
 || (contentType.startsWith("text"))
 || (contentType.endsWith("xml")) ) {
 writer = response.getWriter();
 // Cannot reliably serve partial content with a Writer
 ranges = FULL;
 } else {
 throw e;
 }
 }

So one patch is this (which will catch all javascript variants if multiple
exist)
 if ( (contentType == null)
 || (contentType.startsWith("text"))
 || (contentType.endsWith("xml"))
+|| (contentType.contains("/javascript")) ) {

Patch applied and credited to you in r1139280.

Thanks!

Rainer


Thanks you all for fixing this.  I think that makes good sense that TC 
7's DefaultServlet recognize javascript as a text type like 'text' and 
'xml'.


David


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



Re: log4j logging works for webapps but not for server,

2011-06-24 Thread jjgtx





Where did you put your log4j.properties file and what does it contain?
Can you just post the whole thing?

$CATALINA_HOME/lib

I hate to post the whole thing, its a bit long would it be better to send
it?

One thing I was curious about is that should be the value of the
$LOGGING_CONFIG property. I used the path to the log4j file. 


Christopher Schultz-2 wrote:
> 
> Also what exact version of TC 6.0 are you using? It probably doesn't
> matter but it doesn't hurt to know.
> 
> Server version: Apache Tomcat/6.0.18
> Server built:   Jul 22 2008 02:00:36
> Server number:  6.0.18.0
> OS Name:Linux
> OS Version: 2.6.18-164.11.1.el5PAE
> Architecture:   i386
> JVM Version:1.6.0_18-b07
> JVM Vendor: Sun Microsystems Inc.
>  
> 
> - -chris
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iEYEARECAAYFAk4En8sACgkQ9CaO5/Lv0PDkCgCeLvl177BjdNZzldBWGrOvH/TT
> DS8AnAuxWSWKKs5E9+AL0UmS1Q6qSGnD
> =aFg+
> -END PGP SIGNATURE-
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/log4j-logging-works-for-webapps-but-not-for-server%2C-tp31915060p31921142.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


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



Re: log4j logging works for webapps but not for server,

2011-06-24 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

To whom it may concern,

On 6/23/2011 5:44 PM, jjgtx wrote:
> Followed the
> instructions at http://tomcat.apache.org/tomcat-6.0-doc/logging.html
> replacing the tomcat-juli.jar file in $CATALINA_HOME/bin with the one from
> extras and placing the log4j.jar and tomcat-juli-adapters.jar in the lib
> directory. Running with log4j debug I can see the categories registered.

Where did you put your log4j.properties file and what does it contain?
Can you just post the whole thing?

Also what exact version of TC 6.0 are you using? It probably doesn't
matter but it doesn't hurt to know.

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

iEYEARECAAYFAk4En8sACgkQ9CaO5/Lv0PDkCgCeLvl177BjdNZzldBWGrOvH/TT
DS8AnAuxWSWKKs5E9+AL0UmS1Q6qSGnD
=aFg+
-END PGP SIGNATURE-

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



Re: getAllClusterSessions gives OptionalDataException

2011-06-24 Thread Ronald Klop

I double checked. The version of Tomcat and the versions of Java are all the 
same.

Ronald.


Op vrijdag, 24 juni 2011 03:25 schreef Filip Hanik - Dev Lists 
:


  
 are there other versions of Apache Tomcat running in the same cluster?

 Check the logs for what members are joining the cluster, then check what 
version they are
 
 best

 Filip
 
 On 6/23/2011 10:14 AM, Ronald Klop wrote:

 > Hi,
 >
 > I have an exception when one on my Tomcat nodes restarts. The session are not 
synced and user complain about being logged out. I was > running 6.0.32 and had the 
problem. Now I'm running a custom build of 6.0.33 from yesterday. I added a little code 
which prints ' SEVERE: > name=user'. The key on which the sync fails while reading 
the value.
 >
 > I looked into the java code in ObjectInputStream and it looks like some 
inconsistency in the ObjectStream.
 >
 > I have 4 nodes on Debian 5, sun-java6-jdk 6-22-0lenny1, seen the problem on 
Tomcat 6.0.29, 6.0.32 and a custom build 6.0.33. I can't > reproduce this (yet) on 
my test environment, so debugging it is difficult without upset customers.
 >
 > 
 >   resourceName="UserDatabase" />
 > 
 > 
 > 
 > 
 > 
 >  appBase="/data/webapps/crm-LIVE/deployed"
 > unpackWARs="true" autoDeploy="false"
 > xmlValidation="false" xmlNamespaceAware="true">
 > 
 > 
 >
 > Can I provide more information? Where should I look.
 >
 > NB: In some previous mails about another problem I thought that might be the 
reason for my logout problem, that is why I tried 6.0.33-dev.
 >
 > Ronald.
 >
 > Jun 23, 2011 5:49:47 PM org.apache.catalina.ha.session.DeltaManager 
getAllClusterSessions
 > WARNING: Manager [crm.realworks.nl#], requesting session state from 
org.apache.catalina.tribes.membership.MemberImpl[tcp://{10, 0, 10, > 110}:4000,{10, 
0, 10, 110},4000, alive=45370885,id={-34 112 102 -93 -87 -88 77 18 -113 -30 62 8 62 -65 
-112 -13 }, payload={}, command={}, > domain={}, ]. This operation will timeout if no 
session state has been received within 60 seconds.
 > Jun 23, 2011 5:49:47 PM org.apache.catalina.ha.session.DeltaManager 
waitForSendAllSessions
 > INFO: Manager [crm.realworks.nl#]; session state send at 6/23/11 5:49 PM 
received in 304 ms.
 > Jun 23, 2011 5:49:47 PM org.apache.catalina.ha.session.DeltaManager 
getAllClusterSessions
 > WARNING: Manager [crm.realworks.nl#]: Drop message SESSION-ACCESSED inside 
GET_ALL_SESSIONS sync phase start date 6/23/11 5:49 PM message > date 6/23/11 5:49 
PM
 > Jun 23, 2011 5:49:47 PM org.apache.catalina.ha.session.DeltaSession 
readObject
 > SEVERE: name=user.
 > Jun 23, 2011 5:49:47 PM org.apache.catalina.ha.session.DeltaManager 
deserializeSessions
 > SEVERE: IOException while loading persisted sessions: 
java.io.OptionalDataException
 > java.io.OptionalDataException
 > at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1348)
 > at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
 > at java.util.HashMap.readObject(HashMap.java:1029)
 > at sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
 > at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 > at java.lang.reflect.Method.invoke(Method.java:597)
 > at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
 > at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848)
 > at 
java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
 > at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
 > at 
java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
 > at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
 > at 
java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
 > at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
 > at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
 > at 
org.apache.catalina.ha.session.DeltaSession.readObject(DeltaSession.java:655)
 > at 
org.apache.catalina.ha.session.DeltaSession.readObjectData(DeltaSession.java:481)
 > at 
org.apache.catalina.ha.session.DeltaManager.deserializeSessions(DeltaManager.java:745)
 > at 
org.apache.catalina.ha.session.DeltaManager.handleALL_SESSION_DATA(DeltaManager.java:1583)
 > at 
org.apache.catalina.ha.session.DeltaManager.messageReceived(DeltaManager.java:1440)
 > at 
org.apache.catalina.ha.session.DeltaManager.messageDataReceived(DeltaManager.java:1173)
 > at 
org.apache.catalina.ha.session.ClusterSessionListener.messageReceived(ClusterSessionListener.java:92)
 > at 
org.apache.catalina.ha.tcp.SimpleTcpCluster.messageReceived(SimpleTcpCluster.java:901)
 > at 
org.apache.catalina.ha.tcp.SimpleTcpCluster.messageReceived(SimpleTcpCluster.java:882)
 > at 
org.apache.catalina.tribes.group.GroupChannel.messageReceived(GroupChannel.java:269)
 > a

Programatically setting web.xml in embedded Tomcat

2011-06-24 Thread Andrew Brock
Hi all,

I'm currently using Tomcat's embedded feature for unit testing of a web
service. This web service displays different behaviour depending on the
contents of the web.xml file. I therefore want to exercise different web.xml
configurations in my unit tests. Currently the setup code I'm using is as
follows:

Tomcat tomcat = new Tomcat();
tomcat.setBaseDir(catalinaHome);
tomcat.setPort(port);
tomcat.addWebapp("/ServiceTest", System.getProperty("user.dir") +
"build/web");
tomcat.setHostname("localhost");
tomcat.enableNaming();
tomcat.start();

As you can see, the webapp is currently sourced from the NetBeans build
directory.

What is the best way for me to test different web.xml files? Is there a way
I can set the webapp to the same directory as I am currently, but point at a
web.xml file that is somewhere else?

(I'm not too keen on altering the build/web directory just in case the test
fails and ends up breaking the real web.xml file.)

My fall-back position is to have my test cases make a temporary copy of the
build/web directory and then override the web.xml file with the one I want
to use in that specific test case, but I was wondering if there is a more
elegant solution.



My environment is:

Tomcat 7.0.11
NetBeans 7.0
Windows XP


Thanks,

Andrew


Re: TC 7.0.16 IllegalStateException thrown by pageContext.include

2011-06-24 Thread Rainer Jung
On 24.06.2011 14:08, Tim Funk wrote:
> Looks like this is the root cause from DefaultServlet ...
> 
> While the ISE is caught ... since the mimetype for js was changed - it
> doesn't match the fallback method 
> 
> try {
> ostream = response.getOutputStream();
> } catch (IllegalStateException e) {
> // If it fails, we try to get a Writer instead if we're
> // trying to serve a text file
> if ( (contentType == null)
> || (contentType.startsWith("text"))
> || (contentType.endsWith("xml")) ) {
> writer = response.getWriter();
> // Cannot reliably serve partial content with a Writer
> ranges = FULL;
> } else {
> throw e;
> }
> }
> 
> So one patch is this (which will catch all javascript variants if multiple
> exist)
> if ( (contentType == null)
> || (contentType.startsWith("text"))
> || (contentType.endsWith("xml"))
> +|| (contentType.contains("/javascript")) ) {

Patch applied and credited to you in r1139280.

Thanks!

Rainer

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



Re: TC 7.0.16 IllegalStateException thrown by pageContext.include

2011-06-24 Thread Tim Funk
Looks like this is the root cause from DefaultServlet ...

While the ISE is caught ... since the mimetype for js was changed - it
doesn't match the fallback method 

try {
ostream = response.getOutputStream();
} catch (IllegalStateException e) {
// If it fails, we try to get a Writer instead if we're
// trying to serve a text file
if ( (contentType == null)
|| (contentType.startsWith("text"))
|| (contentType.endsWith("xml")) ) {
writer = response.getWriter();
// Cannot reliably serve partial content with a Writer
ranges = FULL;
} else {
throw e;
}
}

So one patch is this (which will catch all javascript variants if multiple
exist)
if ( (contentType == null)
|| (contentType.startsWith("text"))
|| (contentType.endsWith("xml"))
+|| (contentType.contains("/javascript")) ) {


-Tim

On Thu, Jun 23, 2011 at 9:12 PM, David Wall  wrote:

> This was working under TC 6, but I have a tag that extends BodyTagSupport,
> and in my doStartTag() method I get my JspWRiter 'out' using
> pageContext.getOut().
>
> I have a bunch of out.write("") statements that all work fine.
>
> Then I have these:
>
> out.write("\n/* platform esf.css */\n");
> pageContext.include("/static/**esf/esf.css",true);
> pageContext.include(docPage.**context.**getDocumentStyleIncludeUrl(),**
> true);
> out.write("\n");
>
> out.write("\n");
> pageContext.include("/static/**esf/esf.js",true);
> out.write("\n");
>
> But the exception IllegalStateException is thrown on the include of the
> esf.js file.  The reason is null, so there's no more details.  I find it odd
> in that the two prior includes works okay, but that third one fails.  The
> file is definitely there (and has been working under TC 6.0 before).
>
> If I comment out that include, my tag works fine.  What might be causing
> this?
>
> Thanks,
> David
>
>
> --**--**-
> To unsubscribe, e-mail: 
> users-unsubscribe@tomcat.**apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>


Re: TC 7.0.16 IllegalStateException thrown by pageContext.include

2011-06-24 Thread Konstantin Kolinko
2011/6/24 David Wall :
>
>>
>>> out.write("\n");
>>> pageContext.include("/static/esf/esf.js",true);
>>> out.write("\n");
>>>
>>> But the exception IllegalStateException is thrown on the include of the
>>> esf.js file.  The reason is null, so there's no more details.  I find it odd
>>> in that the two prior includes works okay, but that third one fails.  The
>>> file is definitely there (and has been working under TC 6.0 before).
>>
>> When I change the code to use /static/esf/esf.javascript and rename the
>> file to have the same suffix, the exception is not thrown.
>>
>> Is there anything special about the .js suffix on a file for
>> pageContext.include()?
>
> Okay, I learned that this is because web.xml for TC 6 uses:
>
> 
> js
> text/javascript
> 
>
> But TC 7 uses:
>
> 
> js
> application/javascript
> 
>
> If I put the old TC 6 version in my app's web.xml, then it works again.
>

Is there stacktrace for the IllegalStateException that you were observing?


> Question: Is this to be expected?  Is TC 7 doing the "right thing" here?  Am
> I breaking something when I update my app's web.xml to say it's 'text'
> again?

I think (without further looking) that the problem is the following:

The static file (the .js) is served by DefaultServlet.  For
DefaultServlet the data are opaque, so it should be served using an
OutputStream.

In your case, 'out' is a Writer. Trying to open OutputStream after a
Writer has been opened is not allowed.


IIRC, there was some workaround in DefaultServlet for the mime types
that are text/*. I wonder maybe that can be made to work in your case.

The underlying problem though is that to include data from the file
into the writer, one has to convert bytes -> chars,  and for that one
has to know the textual encoding of the file.

Where one can get the encoding?

Best regards,
Konstantin Kolinko

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