GWT violation check on server side throws SerializationException

心已入冬 提交于 2019-12-25 09:47:59

问题


I followed the gwt 2.4 validation sample and implemented the whole stuff into my own App. The client side works great.

    private void verifyRegistrationData(final RegistrationTO registration) throws ConstraintViolationException {
        final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
        final Set<ConstraintViolation<RegistrationTO>> violations = validator.validate(registration);

        if (violations.size() > 0) {
            final Set<ConstraintViolation<?>> temp = new HashSet<ConstraintViolation<?>>(violations);
            throw new ConstraintViolationException(temp);
        ...

but if I do the same on the server side:

    public void update(final RegistrationTO registration) throws IllegalArgumentException, ConstraintViolationException, TestException {
    final Set<ConstraintViolation<RegistrationTO>> violations = validator.validate(registration);
    if (!violations.isEmpty()) {
        final Set<ConstraintViolation<?>> temp = new HashSet<ConstraintViolation<?>>(violations);
        throw new ConstraintViolationException(temp);
    }
    ...

the whole thing crashes with the following exception:
javax.servlet.ServletContext log: Exception while dispatching incoming RPC call com.google.gwt.user.client.rpc.SerializationException: Type 'org.hibernate.validator.engine.PathImpl' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.

That's how PathImpl looks like hibernate-validator-4.1.0.Final-sources.jar

public class PathImpl implements Path, Serializable {
    private static final long serialVersionUID = 7564511574909882392L;
    ...

looks OK (at least to me)

I am using GWT 2.4, validation-api-1.0.0.GA, hibernate-validator-4.1.0.Final, gwt-servlet-deps ...

Thanks in advance!


回答1:


Is there an explicitly defined a default constructor? i.e., public PathImpl() { } ? This is required by GWT's serialization mechanism; if it isn't in the source, serializing an RPC response will fail.




回答2:


A custom serializer does exist for PathImpl, it's just that unless that class is explicitly referenced in your service API, it's not going to be added to the serialization policy.

The current work around is to add a dummy PathImpl field somewhere in your service API. The ValidationSupport class exists to group this and other such classes together to make this a bit easier.




回答3:


I change the whole thing to RequestFactory as Thomas Broyer recommended. It was by far not so easy as GWT-RPC. This was the reason for me to collect all kind of informations and to build a sample program.

For those who are interested - here you can find a sample with documentation and source. (Single line client logger is also implemented) (Documentation is in German but logging-output aso. is in English...)



来源:https://stackoverflow.com/questions/7861640/gwt-violation-check-on-server-side-throws-serializationexception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!