Sunday, December 23, 2012

why some of the Checked RPC Exception fields arrive as nulls?

package org.foo.client.service;

import org.foo.shared.model.FooModel;
import org.foo.shared.service.FooModelValidationException;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

@RemoteServiceRelativePath("gwt/validationService")
public interface ValidationService extends RemoteService {
void validate(FooModel fooModel) throws FooModelValidationException;
}
package org.foo.shared.model;

import java.io.Serializable;

import javax.validation.constraints.Min;
import javax.validation.constraints.Size;

import org.foo.shared.validation.OnServer;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;

public class FooModel implements Serializable {

private static final long serialVersionUID = 6346094855641270950L;

@Min(value=1,message="{FooModel.socialId.Min}")
private Integer socialId;

@NotEmpty (message="{FooModel.name.NotEmpty}")
@Size(min=2,max=25,message="{FooModel.name.Size}")
private String name;

@Email(message="{FooModel.email.Email}", groups=OnServer.class)
private String email;

public Integer getSocialId() {
return socialId;
}

public void setSocialId(Integer socialId) {
this.socialId = socialId;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

}
package org.foo.shared.service;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.validation.ConstraintViolation;

import org.foo.shared.model.FooModel;
import org.hibernate.validator.engine.ValidationSupport;

public class FooModelValidationException extends Exception implements Serializable {
private static final long serialVersionUID = 806793826016622713L;

private FooModel fooModel;

private HashSet<ConstraintViolation<FooModel>> violations = new HashSet<ConstraintViolation<FooModel>>();

private ValidationSupport validationSupport;// useless dummy field needed to allow serverside validation, otherwise u will receive PathImpl is not serializable

// needed for gwt
private FooModelValidationException() {
}

public FooModelValidationException(Set<ConstraintViolation<FooModel>> violations, FooModel fooModel) {
this.violations.addAll(violations);
}

public Set<ConstraintViolation<FooModel>> getViolations() {
return new HashSet<ConstraintViolation<FooModel>>(violations);
}

public FooModel getFooModel() {
return fooModel;
}

}
Hello,

I have a checked exception FooModelValidationException which is declared in interface of an RPC service ValidationService
FooModelValidationException is thrown if a server side validation fails.

The Exception contains two fields:
FooModel fooModel;
HashSet<ConstraintViolation<FooModel>> violations = new HashSet<ConstraintViolation<FooModel>>();

When the exception arrives to client fooModel is ALWAYS null, despite the fact that the object was not null when the exception was thrown on server.
violations is not null, but  ConstraintViolation(s) inside has null instead of FooModel object in getRootBean, getLeafBean() properties(again both are not null when i send them from server), but getPropertyPath() is NOT null

No exceptions or warnings in a server log.

The question, why fields of checked RPC exception are replaced with nulls?!

I attach FooModel declaration as whell as ValidationService interface decoration here.

Thanks in advance,
Vitaliy

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/gdc3TMP8Df8J.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment