Or check your pages for references to your entities at the end of the request:
private void testDetachedObjects(final Page page)
{
Page responsePage = getResponsePage();
if (page == null || page.isErrorPage()
|| (responsePage != null && responsePage.isErrorPage()))
{
return;
}
try
{
NotSerializableException exception = new
NotSerializableException();
EntityAndSerializableChecker checker = new
EntityAndSerializableChecker(exception);
checker.writeObject(page);
}
catch (Exception ex)
{
log.error("Couldn't test/serialize the Page: " + page +
", error: " + ex);
}
}
Copy the SerializableChecker code (included in Wicket) and modify it
to discover your entities.
Here's a patch (against 1.4) that our app uses to perform the check:
@@ -330,21 +410,40 @@
writeObjectMethodCache.clear();
}
+ @SuppressWarnings("all")
private void check(Object obj)
{
- if (obj == null)
+ if (obj == null ||
obj.getClass().isAnnotationPresent(Deprecated.class)
+ || obj.getClass().isAnnotationPresent(SkipClass.class))
{
return;
}
- Class<?> cls = obj.getClass();
+ Class cls = obj.getClass();
nameStack.add(simpleName);
traceStack.add(new TraceSlot(obj, fieldDescription));
if (!(obj instanceof Serializable) &&
(!Proxy.isProxyClass(cls)))
{
- throw new WicketNotSerializableException(
- toPrettyPrintedStack(obj.getClass().getName()),
exception);
+ throw new
WicketNotSerializableException(toPrettyPrintedStack(obj.getClass().getName())
+ .toString(), exception);
+ }
+ if (obj instanceof IdObject)
+ {
+ Serializable id = ((IdObject)
obj).getIdAsSerializable();
+ if (id != null && !(id instanceof Long && ((Long) id)
<= 0))
+ {
+ throw new
WicketContainsEntityException(toPrettyPrintedStack(
+ obj.getClass().getName()).toString(),
exception);
+ }
+ // Deze uitgezet aangezien objecten die nieuw zijn
*wel* gewoon in de sessie
+ // mogen komen.
+ // else
+ // {
+ // log.info("New Id Object ("
+ // + obj.getClass().getSimpleName() + ") Found '" + obj
+ // + "' found: " + stack);
+ // }
}
ObjectStreamClass desc;
On Thu, Aug 27, 2009 at 10:09 AM, Eelco
Hillenius<[email protected]> wrote:
> One 'hack' of a way to check whether you have stuff in your session
> that shouldn't be, is to make sure that the objects you don't want
> sticking around are not serializable, and you'll see stacktraces soon
> enough. If that's an options, it's a useful hack...
>
> Eelco
>
> On Wed, Aug 26, 2009 at 12:29 PM, Bas Gooren<[email protected]> wrote:
>> Hi all,
>>
>> My problem is as follows: I use LoadableDetachableModels throughout my
>> application, and have made sure I never use a model without it being
>> attached to a component to prevent models which never get their detach()
>> method called.
>> Nonetheless, after hitting two fairly simple pages which list some database
>> data in my application, I get a 100kb session which is filled with literal
>> strings from model objects.
>>
>> I've fired up my (Eclipse) debugger and have stepped through all models on
>> one of the pages after setting a breakpoint on the pages onDetach() method.
>> I see all LoadableDetachableModels are detached, so I have no idea what's
>> causing this.
>>
>> What would be a good strategy for finding the source of this problem?
>>
>> Bas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
--
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.4 increases type safety for web applications
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.0
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]