[jboss-user] [Clustering/JBoss] - Re: NotSerializableException in JBossCache with Log4J Level

realstaple do-not-reply at jboss.com
Wed Mar 14 11:00:18 EDT 2007


Any further word on this?  

I created a listener that implements both HttpSessionAttributeListener and ServletContextAttributeListener (code below).  It exposed a few other classes we were putting into the session.  

However, I continue to get the log4j NonSerializable exceptions without any indication from the listener that something has been added that contains org.apache.log4j.Level.

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextAttributeEvent;
import java.io.ObjectOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class FindNonSerializableSessionAttributesListener implements HttpSessionAttributeListener, ServletContextAttributeListener {
    private static final Log logger = LogFactory.getLog(FindNonSerializableSessionAttributesListener.class);

    public void attributeAdded(HttpSessionBindingEvent httpSessionBindingEvent) {
        checkSerailizable(httpSessionBindingEvent.getName(), httpSessionBindingEvent.getValue());
    }

    public void attributeRemoved(HttpSessionBindingEvent httpSessionBindingEvent) {}

    public void attributeReplaced(HttpSessionBindingEvent httpSessionBindingEvent) {
        checkSerailizable(httpSessionBindingEvent.getName(), httpSessionBindingEvent.getValue());
    }

    private void checkSerailizable(String name, Object value) {
        if (logger.isDebugEnabled()) {
            try {
                ObjectOutputStream out = new ObjectOutputStream(new ByteArrayOutputStream());
                out.writeObject(value);
                out.close();
                out.flush();
            } catch (IOException e) {
                logger.info("Error serialiazing when setting session attribute " + name + "::" + value, e);
            }
        }
    }

    public void attributeAdded(ServletContextAttributeEvent servletContextAttributeEvent) {
        checkSerailizable(servletContextAttributeEvent.getName(), servletContextAttributeEvent.getValue());
    }

    public void attributeRemoved(ServletContextAttributeEvent servletContextAttributeEvent) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public void attributeReplaced(ServletContextAttributeEvent servletContextAttributeEvent) {
        checkSerailizable(servletContextAttributeEvent.getName(), servletContextAttributeEvent.getValue());
    }
}




View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4027961#4027961

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4027961



More information about the jboss-user mailing list