• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

setAttribute: Non-serializable attribute

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to add transient.
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic