Serializable Exception in Java

2011-07-23 21:07:21 +0200

When  you use Wicket as webfrontend framework to build your application, sooner or later you'll encounter the NotSerializableException. This is because Wicket will want to serialize any state you have into a HTTPSession. In Wicket, the first three pages are usually in memory too, so you could ignore the exception for a while, but of course this will fail immediately in case use want to use your webapplication in a clustered configuration. Not to mention you should never ignore Exceptions anyway.

The problem in solving such a Serializable exception is finding the field that is not Serializable. The stacktrace of java doesn't help much. Fortunatelly, after some searching I've found the solution, in the comment of blog posting: add the option -Dsun.io.serialization.extendedDebugInfo=true to the JVM startup parameters.
Now the stacktrace gives you the exact fieldname or expression that is causing the problems, as you can see in the example below:

2011-07-23 21:44:50,362 ERROR [http-8080-1] [] org.apache.wicket.util.lang.Objects - Error serializing object class nl.gerbrandict.forum.AdminPage [object=[Page class = nl.gerbrandict.forum.AdminPage, id = 2, version = 0]]
java.io.NotSerializableException: org.springframework.beans.factory.support.DefaultListableBeanFactory
- field (class "org.springframework.orm.hibernate3.HibernateTransactionManager", name: "beanFactory", type: "interface org.springframework.beans.factory.BeanFactory")
- object (class "org.springframework.orm.hibernate3.HibernateTransactionManager", org.springframework.orm.hibernate3.HibernateTransactionManager@10fd8ce3)
- custom writeObject data (class "org.springframework.transaction.interceptor.TransactionInterceptor")
- object (class "org.springframework.transaction.interceptor.TransactionInterceptor", org.springframework.transaction.interceptor.TransactionInterceptor@2c96cb51)
- field (class "org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor", name: "transactionInterceptor", type: "class org.springframework.transaction.interceptor.TransactionInterceptor")
..
        - field (class "nl.gerbrandict.forum.AdminModel", name: "person", type: "class nl.gerbrandict.forum.Person")

(note: not publishing the entire stack trace and using some sample dummy field/classnames).
Although I haven't tried, enabling this option in production is most likely a bad idea, because Serialization is already a pretty inefficient process without any debugging information enabled. In my case, I was using a PropertyModel somewhere, using non model as target object.

Read more

OpenID from my website

2011-06-23 09:07:03 +0200

A lot of websites now provide a way to authenticate yourself via OpenID. That way, you don't have to remember a separate username and password to login to such a website, while still being secure.
The only challenge in using openid is remembering your openid URL, because there are quite a few possible openid providers. I currently can choose from (amongst others) Google, Yahoo, mijnopenid.nl, hyves.nl and quite a few others. Instead of remembering the username/password you have to remember which openid provider you've used for what account - which I think is the reason other authentication mechanism as facebook's connect are becoming more popular. I'll write about that later, in this page I just want to explain how I made my homepage, www.gerbrand-ict.nl an openid provider.
Very simple:

  • My homepage is running Wordpress, a popular open source weblog.
  • There are a lot of plugins for Wordpress, of which one is the openid plugin. By going to the administration screen and then to the section plugins, you can install the openid plugin easily by entering openid in the search box.
  • After installation, setup a default account.
  • Now I can authenticate myself to any site that uses openid, by just entering www.gerbrand-ict.nl !

Read more

Archive

subscribe via RSS