NotSerializableException FacesMessage$Severity

I see that calssjavax.faces.application.FacesMessage implements Serializable interface but its nested classjavax.faces.application.FacesMessage.Severity does

NOT implement Serializable interface. Which throws the following error in my application when the server wants to serialize the session that contains FacesMessage class.

Is that a bug? or FacesMessage is not meant to be in a session? I am at a loss!!

Exception:

null

[EXCEPTION]

com.sap.engine.services.failover.exceptions.PersistentStorageException: Unexpected exception during serialization of the HTTP session with

ID (server_ESP_00)ID2622750DB820712460250578161End in application purchaseonline.

at com.sap.engine.services.failover.storage.FilePersistentStorage.serializeSession(FilePersistentStorage.java:111)

at com.sap.engine.services.failover.storage.FilePersistentStorage.serializeSession(FilePersistentStorage.java:129)

at com.sap.engine.services.servlets_jsp.server.runtime.context.SessionServletContext.serializeSession(SessionServletContext.java:512)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:412)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:264)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:347)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:325)

at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:887)

at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:241)

at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)

at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148)

at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)

at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)

at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)

at java.security.AccessController.doPrivileged(Native Method)

at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:95)

at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:159)

Caused by: java.io.NotSerializableException: javax.faces.application.FacesMessage$Severity

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)

at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)

at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)

at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)

at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)

at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)

at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)

at com.sap.engine.lib.util.HashMapObjectObject.writeObject(HashMapObjectObject.java:748)

at sun.reflect.GeneratedMethodAccessor1467.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:324)

at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:809)

at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1296)

at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)

at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)

at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)

at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)

at com.sap.engine.services.failover.serialization.ObjectSerializator.serializeObjectGraph(ObjectSerializator.java:47)

at com.sap.engine.services.failover.storage.FilePersistentStorage.serializeSession(FilePersistentStorage.java:95)

... 16 more

[4766 byte] By [jaguar2010a] at [2007-11-26 15:25:30]
# 1
Why do you want to put FacesMessage in session? In your jsp, you can just use <h:message for="componentId"> to display the message.Maybe, i am missing the context you are using this into..
RJohara at 2007-7-8 21:41:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
I am using FacesMessage in session, mainly to transfer messages from one page to the other.
jaguar2010a at 2007-7-8 21:41:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

I think that easy & better way to pass on the messages would be to use FacesContext. Here is an example:

FacesContext fc = FacesContext.getCurrentInstance();

FacesMessage message = new FacesMessage("Your message");

fc.addMessage("myClientid", message);

and then use

fc.getMessages()

or

fc.getMessages("myClientId")

to retrieve & display those messages

RJohara at 2007-7-8 21:41:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
But FacesContext is different for every request. i.e. FacesMessages in one page won't be available in the other pages.
jaguar2010a at 2007-7-8 21:41:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Sorry for pointing in the direction which is not relevant to you problem.

But now, i am just wondering why you are not able to set FacesMessage in session. I just did a test run by setting a FacesMessage in session & then retrieved from session on some other page. It didn't give me any problem.

Here is the working code from my test. As you will see, i am not doing anything other than calling session's set/getAttribute methods:

setting in session:

FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Test Msg", "test msg");

HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);

session.setAttribute("mymsg", msg);

System.out.println("mymsg set in session = " + msg.getSummary());

retrieveing frm session:

HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);

if (session.getAttribute("mymsg") != null)

{

FacesMessage msg = (FacesMessage) session.getAttribute("mymsg");

System.out.println("msg: " + msg.getSummary());

}

I am sorry i couldn't be of any help BUT pls. do share when you find the cause & solution.

Message was edited by:

RJohar

RJohara at 2007-7-8 21:41:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Hi,Really, you should avoid to store FacesMessages in session:https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=111
trevorijonesa at 2007-7-8 21:41:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
Thanks Trevor. I don't like the fact that they won't fix it.Johar, you can put FacesMessage in the session and it works fine too but if your server is set to serialize the session then it will raise an exception.
jaguar2010a at 2007-7-8 21:41:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...