Sunday, February 20, 2011

Apache Wicket WicketNotSerializableException: Unable to serialize clas

This is a typical Wicket problem which occurs on clicking browser back button and clicking any stale link on the page.

DEBUG - Rendering raw markup
DEBUG - Rendered [Page class = com..web.appointments.page.AppointmentSchedulerPage, id = 3, version = 0]
DEBUG - End render [Page class = com.project.web.appointments.page.AppointmentSchedulerPage, id = 3, version = 0]
DEBUG - ending request for page [Page class = com.project.web.appointments.page.AppointmentSchedulerPage, id = 3, version = 0], request [method = GET, protocol = HTTP/1.1, requestURL = http://localhost:8080/project-1.0/appointmentScheduler, contentType = null, contentLength = -1, contextPath = /project-1.0, pathInfo = null, requestURI = /project-1.0/appointmentScheduler, servletPath = /appointmentScheduler, pathTranslated = null]
DEBUG - ending request for page [Page class = com.project.web.appointments.page.AppointmentSchedulerPage, id = 3, version = 0], request [method = GET, protocol = HTTP/1.1, requestURL = http://localhost:8080/project-1.0/appointmentScheduler, contentType = null, contentLength = -1, contextPath = /project-1.0, pathInfo = null, requestURI = /project-1.0/appointmentScheduler, servletPath = /appointmentScheduler, pathTranslated = null]
ERROR - Error serializing object class com.project.web.appointments.page.AppointmentSchedulerPage [object=[Page class = com.project.web.appointments.page.AppointmentSchedulerPage, id = 3, version = 0]]
org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException: Unable to serialize class: com.project.service.appointments.dataobject.projectAppointment
Field hierarchy is:
3 [class=com.project.web.appointments.page.AppointmentSchedulerPage, path=3]
private java.lang.Object org.apache.wicket.MarkupContainer.children [class=com.project.web.appointments.panel.projectAppointmentSchedulerPanel, path=3:projectAppointmentSchedulerPanel]
private java.lang.Object org.apache.wicket.MarkupContainer.children [class=com.project.web.appointments.form.AppointmentSchedulerForm, path=3:projectAppointmentSchedulerPanel:appointmentSchedulerForm]
java.lang.Object org.apache.wicket.Component.data [class=org.apache.wicket.model.CompoundPropertyModel]
private java.lang.Object org.apache.wicket.model.CompoundPropertyModel.target [class=com.project.service.appointments.dataobject.projectAppointment] <----- data-blogger-escaped-br="" data-blogger-escaped-field="" data-blogger-escaped-is="" data-blogger-escaped-not="" data-blogger-escaped-serializable="" data-blogger-escaped-that=""> at org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:346)
at org.apache.wicket.util.io.SerializableChecker.checkFields(SerializableChecker.java:615)
at org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:538)
at org.apache.wicket.util.io.SerializableChecker.checkFields(SerializableChecker.java:615)
at org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:538)
at org.apache.wicket.util.io.SerializableChecker.checkFields(SerializableChecker.java:615)
at org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:538)
at org.apache.wicket.util.io.SerializableChecker.checkFields(SerializableChecker.java:615)
at org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:538)
at org.apache.wicket.util.io.SerializableChecker.writeObjectOverride(SerializableChecker.java:684)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:322)
at org.apache.wicket.util.io.IObjectStreamFactory$DefaultObjectStreamFactory$2.writeObjectOverride(IObjectStreamFactory.java:129)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:322)
at org.apache.wicket.util.lang.Objects.objectToByteArray(Objects.java:1120)
at org.apache.wicket.protocol.http.pagestore.AbstractPageStore.serializePage(AbstractPageStore.java:203)
at org.apache.wicket.protocol.http.pagestore.DiskPageStore.storePage(DiskPageStore.java:840)
at org.apache.wicket.protocol.http.SecondLevelCacheSessionStore$SecondLevelCachePageMap.put(SecondLevelCacheSessionStore.java:332)
at org.apache.wicket.Session.requestDetached(Session.java:1404)
at org.apache.wicket.RequestCycle.detach(RequestCycle.java:1176)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1454)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:468)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:301)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:637)
Caused by: java.io.NotSerializableException: com.project.service.appointments.dataobject.projectAppointment
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:416)
at org.apache.wicket.Component.writeObject(Component.java:4447)
at sun.reflect.GeneratedMethodAccessor30.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
at org.apache.wicket.util.io.IObjectStreamFactory$DefaultObjectStreamFactory$2.writeObjectOverride(IObjectStreamFactory.java:121)
... 23 more
DEBUG - Getting page [path = 2:projectProfilePanel:AptmntCalendarPanel:sAppointmentList:1:sAppointmentTimeFrameList:4:sAppointmentLink, versionNumber = 0]
DEBUG - setting request target to [BookmarkablePageRequestTarget@-371790702 pageClass=org.apache.wicket.markup.html.pages.PageExpiredErrorPage]
DEBUG - update: Session not dirty.
DEBUG - Redirecting to ?wicket:bookmarkablePage=:org.apache.wicket.markup.html.pages.PageExpiredErrorPage
DEBUG - Add homePageLink to [Page class = org.apache.wicket.markup.html.pages.PageExpiredErrorPage, id = 4, version = 0]
DEBUG - Begin render [Page class = org.apache.wicket.markup.html.pages.PageExpiredErrorPage, id = 4, version = 0]


=========================================
Solution

Override the following method in your page class. It would surely resolve the problem :

/**
* Confgured to clear the cache and re-render the page every time user request for it.
* This is used to overcome the browser back button problem.
*/
@Override
protected void configureResponse() {
super.configureResponse();

final WebResponse response = getWebRequestCycle().getWebResponse();
response.setHeader("Cache-Control", "no-cache, max-age=0, must-revalidate, no-store");
}

No comments:

Post a Comment