You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by "Ian F.Darwin" <ia...@darwinsys.com> on 2004/10/12 02:01:45 UTC

Re: [Bug 31655] - org.apache.catalina.cluster.session.DeltaManager requestCompleted, SEVERE: Unable to serialize delta request, java.io.NotSerializableException:

The original user was having trouble figuring out which class(es) in  
their application were causing NotSerializableExceptions.
And, in fact, I was starting to think about the Serializable issue for  
a client...

And then Tim wrote:

> ------- Additional Comments From funkman@joedog.org  2004-10-11 22:36  
> -------
> You can determine which attributes are not serializable by writing  
> your own
> HttpSessionAttributeListener and checking if the attribute implements  
> serializable.
>
> http://jakarta.apache.org/tomcat/tomcat-5.0-doc/servletapi/javax/ 
> servlet/http/HttpSessionAttributeListener.html

This is actually a good idea, Tim :-) So I've written one and will  
polish it up a bit (it goes recursively, first complaining if the  
object is not serializable, then testing if the object being added is a  
Collection...).

Since a number of Tomcat users are not Java programmers, I would like  
to commit this for general use.

But there doesn't seem a good place for it. What would y'all think of  
creating a package called, say, o.a.c.userdiagnostic or  
o.a.tomcat.util.userdiagnostic to serve as a place to store diagnostic  
tools for end-users?  Or is there a good place already?

To be maximally useful it wants to be part of what gets shipped with  
TC, so we can just tell people something like:

	You can do this with an HttpSessionAttributeListener; to use Tomcat's  
default "serializable attributes" diagnostic  
	HttpSessionAttributeListener just add these lines in your web.xml,  
immediately before the first <servlet> tag:

	<listener>
		<!-- Used to warn about non-Serializable objects being put in the  
session. -->
   
		<listener- 
class>org.apache.catalina.userdiagnostic.SerializableCheckAttributeListe 
ner
		</listener-class>
	</listener>

Ian

Re: [Bug 31655] - org.apache.catalina.cluster.session.DeltaManager requestCompleted, SEVERE: Unable to serialize delta request, java.io.NotSerializableException:

Posted by Tim Funk <fu...@joedog.org>.
Don't bother. Here is it for the archives.

package x;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionAttributeListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
     Listener that complains if you try to put nonserializable elements
     into your session.
*/
public class SessionListener implements HttpSessionAttributeListener  {
     private static Log log = LogFactory.getLog(SessionListener.class);

     public SessionListener() {
     }

     public void attributeAdded(HttpSessionBindingEvent se) {
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         try {
             ObjectOutputStream objStream = new ObjectOutputStream(os);
             objStream.writeObject(se.getValue());
         } catch(IOException e) {
             log.warn("Can't serialize attribute[" + se.getName() + "]", e);
         }
     }

     public void attributeRemoved(HttpSessionBindingEvent se) {
     }

     public void attributeReplaced(HttpSessionBindingEvent se) {
     }
}

-Tim


Ian F.Darwin wrote:

> The original user was having trouble figuring out which class(es) in  
> their application were causing NotSerializableExceptions.
> And, in fact, I was starting to think about the Serializable issue for  
> a client...
> 
> And then Tim wrote:
> 
>> ------- Additional Comments From funkman@joedog.org  2004-10-11 22:36  
>> -------
>> You can determine which attributes are not serializable by writing  
>> your own
>> HttpSessionAttributeListener and checking if the attribute implements  
>> serializable.
>>
>> http://jakarta.apache.org/tomcat/tomcat-5.0-doc/servletapi/javax/ 
>> servlet/http/HttpSessionAttributeListener.html
> 
> 
> This is actually a good idea, Tim :-) So I've written one and will  
> polish it up a bit (it goes recursively, first complaining if the  
> object is not serializable, then testing if the object being added is a  
> Collection...).
> 
> Since a number of Tomcat users are not Java programmers, I would like  
> to commit this for general use.
> 
> But there doesn't seem a good place for it. What would y'all think of  
> creating a package called, say, o.a.c.userdiagnostic or  
> o.a.tomcat.util.userdiagnostic to serve as a place to store diagnostic  
> tools for end-users?  Or is there a good place already?
> 
> To be maximally useful it wants to be part of what gets shipped with  
> TC, so we can just tell people something like:
> 
>     You can do this with an HttpSessionAttributeListener; to use 
> Tomcat's  default "serializable attributes" diagnostic  
>     HttpSessionAttributeListener just add these lines in your web.xml,  
> immediately before the first <servlet> tag:
> 
>     <listener>
>         <!-- Used to warn about non-Serializable objects being put in 
> the  session. -->
>           <listener- 
> class>org.apache.catalina.userdiagnostic.SerializableCheckAttributeListe 
> ner
>         </listener-class>
>     </listener>
> 
> Ian
> 

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