[ 
https://issues.apache.org/jira/browse/SCB-406?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16414872#comment-16414872
 ] 

ASF GitHub Bot commented on SCB-406:
------------------------------------

wujimin commented on a change in pull request #607: [SCB-406] Chassis must 
support standard parameter validation handler
URL: 
https://github.com/apache/incubator-servicecomb-java-chassis/pull/607#discussion_r177283452
 
 

 ##########
 File path: 
handlers/handler-validator/src/main/java/org/apache/servicecomb/validator/ParamValidateHandler.java
 ##########
 @@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.validator;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+
+import org.apache.servicecomb.core.Handler;
+import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.swagger.invocation.AsyncResponse;
+import org.apache.servicecomb.swagger.invocation.Response;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ParamValidateHandler
+ * Handler to validate the input request parameters 
+ *
+ */
+public class ParamValidateHandler implements Handler {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(ParamValidateHandler.class);
+
+  private static Validator validator = 
Validation.buildDefaultValidatorFactory().getValidator();
+
+  @Override
+  public void handle(Invocation invocation, AsyncResponse asyncResp) throws 
Exception {
+    Object[] args = invocation.getArgs();
+    boolean invalid = false;
+    List<Object> errList = new ArrayList<>();
+    if (null != args) {
+      for (Object arg : args) {
+        Set<ConstraintViolation<Object>> violations = validator.validate(arg);
 
 Review comment:
   do not hard code response for validate failed, just throw some validation 
exception(maybe you can reference spring mechanism)
   by 
org.apache.servicecomb.swagger.invocation.exception.ExceptionToResponseConverters,we
 provide a default validation exception converter
   add a method: int getOrder() in ExceptionToResponseConverter, so that 
customers can override our default converter.

----------------------------------------------------------------
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:
us...@infra.apache.org


> Chassis must support standard parameter validation handler
> ----------------------------------------------------------
>
>                 Key: SCB-406
>                 URL: https://issues.apache.org/jira/browse/SCB-406
>             Project: Apache ServiceComb
>          Issue Type: New Feature
>          Components: Java-Chassis
>            Reporter: sukesh
>            Assignee: sukesh
>            Priority: Major
>             Fix For: java-chassis-1.0.0-m2
>
>
> JSR 380 is Java API specification for bean validation to validate the 
> properties of a bean using various annotations. Chassis must support the 
> validation handler for parameter validation using the hibernate-validator. 
> Provide the support to the custom error messages, error codes by users.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to