stefli opened a new issue #1637: Issue about the provider side parameter 
validation
URL: https://github.com/apache/incubator-dubbo/issues/1637
 
 
   **Background**
   We use JSR303 validation protocol, and use hibernate as implementation of 
JSR303 protocol.
    
   **Problem Description**
   Recently, we want to use the validation on the provider side(No issue on the 
consumer side). But we can't get the validation errors on the consumer side 
after configured the validation="true" to the service on the provider side. We 
try to use the ExceptionHandler to parse the exception returned,but we can't 
get the validation errors. The exception returned is RpcException with 
RemotingException clause, but we need RpcException with 
ConstraintViolationException clause. Because we can get the failed property 
name and the validation error from ConstraintViolationException directly.
   
   We have analysised the ValidationFilter, it throws new RpcException when 
validation failed. And the exception will be wrapped with RemotingException 
when result status is not equal to OK and SERVER_TIMEOUT in another class. The 
recent version of ValidationFilter has been upgrade to return RpcResult, but it 
seems not completely.
   
   **Candidate Solution**
   To fix this issue, we add two more files to wrap the property name and 
validation error from the hibernate validator, and return to client. 
   
   The code snippet:
   
   `
   Set<CustomConstraintViolation> set = 
rewriteFromConstraintViolationException();
   return new RpcResult(new RpcException(new 
CustomConstraintViolationException(set)));
   
   // Replace javax.validation.ConstraintViolation with 
CustomConstraintViolation
   // Replace javax.validation.ConstraintViolationException with 
CustomConstraintViolationException
   `
   
   We have tried to return javax.validation.ConstraintViolationException 
directly, but failed with ConstraintDescriptorImpl deserialization. Because the 
ConstraintDescriptorImpl has no empty constructor and can't be instantiated 
when deserialization. So create above two custom classes to rewrite the 
exception.
   
   Then the ExceptionHandler can handle the RpcException, and retrieve the 
property name & validation error from CustomConstraintViolationException.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to