Restlet + GWT ConstraintViolation

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Restlet + GWT ConstraintViolation

Guillaume Pelletier
I'm trying to implement a scheme to have the Editor framework on the GWT client used properly with lists of ConstraintViolations but to be frank I doubt my approach makes any sense at this point.

Initially I thought about doing it by providing my own StatusService and populate the response entity with a serialized set of ConstraintViolation, but that doesn't quite work obviously and I couldn't unserialize them on the client anyway.

So my questions are:

Are there any plans to support this in a near future? Something like RequestFactory does with an onConstraintViolation method would be great.

How would someone solve this on his own end if there are no plans for it? Maybe I can make some patch for it.

My solution right now is to hack something up with a string of key/pairs and just use ConstraintViolationImpl from a Builder of GWT directly.... It... sucks.. ;)

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3071373
Reply | Threaded
Open this post in threaded view
|

RE: Restlet + GWT ConstraintViolation

koma
Hi Guillaume

Generally speaking, in GWT you would like to have the constraint violations thrown the Editor framework on the client side. But there are of course some constraint violations that can only be checked server-side, e.g. unique violations that need a query to check the validity.

For these cases, I do exactly what you are suggesting. My server-side classes throw a custom  ConstraintViolationException which I intercept in my StatusService. When the StatusService sees a ConstraintViolationException, I return a Status.CLIENT_ERROR_BAD_REQUEST to the client and I serialize the actual violation in the payload. Here's a snippet of my StatusService :

if (cause instanceof ConstraintViolationsException) {
 ConstraintViolationsException e = (ConstraintViolationsException) cause;
 String msg = "";
 for (ConstraintViolation<DomainResource> violation : e.getViolations()) {
   msg += violation.getMessageTemplate();
   msg += ";";
 }
 getContext().getAttributes().put(STRING_REPRESENTATION, msg);
 ret = new Status(Status.CLIENT_ERROR_BAD_REQUEST, cause, msg);
} + "> at resource <" + resource.getReference() + ">");



In my GWT client, the onFailure checks the response code and when it sees CLIENT_ERROR_BAD_REQUEST, it deserializes the payload into constraint violations and emits them on the event bus. Any interested widget can then respond by displaying the error.

Hope this helps.

Koen

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3071375
Reply | Threaded
Open this post in threaded view
|

RE: Restlet + GWT ConstraintViolation

koma
In reply to this post by Guillaume Pelletier
PS: deserialization on the client is not an issue. Every constraint violation is identified by a unique constant.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3071376
Reply | Threaded
Open this post in threaded view
|

RE: Restlet + GWT ConstraintViolation

Guillaume Pelletier
It's not an issue if you accept this format for all clients. I don't want to do that. I would need the ConverterService & ultimately GwtConverter & JsonConverter for a json client, etc... to be responsible for serialization otherwise when I use the same server code with a different client, then swapping the converter on the classpath isn't going to be the full story and will come with some additional leg work to do on the various clients I'll need.

I want a better solution. It shouldn't be out of reach for Restlet & its GWT port to handle these exceptions and serialize them in some capacity.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3071399