File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setAttribute: Non-serializable attribute

 
Marcelo Heitor
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are the classes referencing a non-serializable object?
IE: a database connection or logger file handle?
 
Marcelo Heitor
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 294
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to add transient.
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic