http://issues.jabsorb.org/show_bug.cgi?id=42
Summary: Ability to customize serialization of checked exceptions
Product: jabsorb
Version: trunk
Status: NEW
Severity: patch
Priority: medium
Component: serializer
AssignedTo: [email protected]
ReportedBy: [EMAIL PROTECTED]
CC: [email protected]
Created an attachment (id=10)
--> (http://issues.jabsorb.org/attachment.cgi?id=10)
patch
I am looking for a way to customize the display/serialization of
checked exceptions thrown by my code. These checked exception contain
additional properties that should be accessible from javascript on the
client side. In the current default behavior, when my java code raises
an exception, these properties get lost and only the StackTrace and
the Exception.message are available to the client.
I was searching the source to find a way to change this default
behavior, but did not find a solution so far. Instead, I have found
the following inconsistency:
The method org.jabsorb.ExceptionTransformer.transform(Throwable)
returns Object, so this seems to be a suitable extension point to
assemble a json object from my exception. One could implement this
interface and pass the transformer to
org.jabsorb.JSONRPCBridge.setExceptionTransformer(ExceptionTransformer),
and the bridge would use this one instead of the default dummy
transformer when invoking
org.jabsorb.serializer.AccessibleObjectResolver.invokeAccessibleObject(...).
The transformer gets invoked only in the case of an exception unknown
to jabsorb, so this seems to be the most natural way to customize the
serialization of my own exceptions.
However, in org.jabsorb.JSONRPCResult.toString(), when the error code
is CODE_REMOTE_EXCEPTION, a cast to Throwable is issued and the the message and
stackstrace are extracted and serialized.
The cast is not consistent with the ability of
org.jabsorb.ExceptionTransformer.transform(Throwable) to return
Object, this would lead to a ClassCastException if I added my custom
transformer that could return something other than Throwable. I would
find it rather natural to be able to return a some custom object from
org.jabsorb.ExceptionTransformer.transform(Throwable).
Here is a patch that allows one to return any type of object from the
exceptionTransformer, it works as outlined below.
The exceptionTransformer gets invoked if - and only if - the called java method
raises a native exception. It transformes the exception to a generic object -
aka anything. It this object is a Throwable, it is serialized by JSONRPCResult
the same way it gets serialized now. However, if the object is something else,
then the bridge tries to transform it into JSON and pass the result to
JSONRPCResult, which will include it unmodified in the error field of the
reply. In the doubly exceptional case when an exception is thrown during
serialization of this error object, then this exception is passed to
JSONRPCResult.
If no custom ExeptionTransformer is used that returns non-throwable objects
then this patch does not modify the behavior of jabsorb.
--
Configure bugmail: http://issues.jabsorb.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
You are the assignee for the bug.
_______________________________________________
Jabsorb-dev mailing list
[email protected]
http://lists.jabsorb.org/mailman/listinfo/jabsorb-dev