aspose file tools*
The moose likes Servlets and the fly likes setAttribute: Non-serializable attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "setAttribute: Non-serializable attribute" Watch "setAttribute: Non-serializable attribute" New topic
Author

setAttribute: Non-serializable attribute

Marcelo Heitor
Greenhorn

Joined: Aug 20, 2005
Posts: 14
Hello folks, I have the problem.

all the class implement serializable and exactly thus it continues this problem.

I am using SecurityFilter.

somebody can help me?


exception

javax.servlet.ServletException: Error matching patterns
org.securityfilter.filter.SecurityFilter.doFilter(SecurityFilter.java:148)


root cause

java.lang.IllegalArgumentException: setAttribute: Non-serializable attribute
org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:1233)
org.apache.catalina.session.StandardSessionFacade.setAttribute(StandardSessionFacade.java:129)
org.securityfilter.filter.SecurityRequestWrapper.setUserPrincipal(SecurityRequestWrapper.java:234)
org.securityfilter.authenticator.FormAuthenticator.processLogin(FormAuthenticator.java:200)
org.securityfilter.filter.SecurityFilter.doFilter(SecurityFilter.java:138)
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Are the classes referencing a non-serializable object?
IE: a database connection or logger file handle?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Marcelo Heitor
Greenhorn

Joined: Aug 20, 2005
Posts: 14
yes, for example...

import java.sql.Types;
import java.util.Vector;

import javax.naming.InitialContext;
import javax.sql.DataSource;

import br.df.gov.caesb.seguranca.RegistrarLog;

/**
* Descri��o: Classe que cont�m os resultados de uma pesquisa realizada no Banco
* de Dados
*/
public class Container implements Serializable {

/**
* Indica a listagem de conex�es ativas
*/
private static Vector listaConexao = new Vector();

/**
* Indica o objeto que reter� o pool de conex�es
*/
private static DataSource ds;

/**
* Indica o objeto Statement
*/
private static Statement sttm;

/**
* Indica o nome do recurso JNDI recuperado pelo Listener
*
*/
private static String fonteDados;

/**
*
*/
public Container() {
}

/**
* M�todo utilizado para realizar uma pesquisa no Banco de Dados abrindo: um
* canal de conex�o e um espa�o destinado ao resultado da consulta. Throws
* SQLException
*
* @param sql
* String
* @result ResultSet
* @see java.sql.ResultSet *
* @see java.sql.Connection
* @see java.sql.Statement
* @see java.sql.ResultSet
*/
public static Connection getConnection() throws SQLException {
try {
InitialContext initialcontext = new InitialContext();
ds = (DataSource) initialcontext.lookup(Container.getFonteDados());
Connection conn = ds.getConnection();
conn.setAutoCommit(false);
return conn;

} catch (javax.naming.NamingException e) {
RegistrarLog.log(RegistrarLog.ERRO,
"Um problema ocorreu ao recuperar o objeto DataSource.\n"
+ e.toString());

return null;
}
}
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

An object can't be serialized if it contains a non-serializable component.
In order to do a deep copy, every part of that object (and all the objects it references) must be serializable.
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
Try to add transient.


Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


Try to add transient.


Yes, while that would probably make the error go away, it would hardly help.

I cant understand why you need to store an object of the class you have posted as a session attribute. That's a class containing static methods to retrieve Connections from a datasource.

I would suggest you take another look at the objects going into session.

cheers,
ram.
 
 
subject: setAttribute: Non-serializable attribute