You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/04/16 09:36:47 UTC

[incubator-servicecomb-java-chassis] branch master updated (646313e -> 01c377c)

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git.


    from 646313e  [SCB-456]Provider a way to input configuration from a Map
     new ae70b49  [SCB-292] chassis support standard parameter validation
     new 29f6819  [SCB-292] chassis support standard parameter validation
     new 0bfdcac  [SCB-292] chassis support standard parameter validation
     new 9fbba49  Update ExceptionToResponseConverter.java
     new a9388f0  [SCB-292] chassis support standard parameter validation
     new 91958ff  Update ExceptionToResponseConverter.java
     new 8319ac9  [SCB-292] chassis support standard parameter validation
     new c1d265e  [SCB-292] chassis support standard parameter validation
     new ad72bd7  [SCB-292] chassis support standard parameter validation
     new ca933c1  [SCB-292] chassis support standard parameter validation
     new 430e81e  [SCB-292] chassis support standard parameter validation
     new 3594166  [SCB-292] chassis support standard parameter validation
     new 01c377c  [SCB-292] chassis support standard parameter validation

The 13 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../client/CustomLoadbalanceExtensionsFactory.java |   9 ++
 .../servicecomb/demo/jaxrs/client/JaxrsClient.java | 103 ++++++++++++++++
 demo/demo-jaxrs/jaxrs-server/pom.xml               | 129 +++++++++++----------
 .../servicecomb/demo/jaxrs/server/Validator.java   |  47 ++++----
 .../Person.java => validator/Student.java}         |  26 ++++-
 demo/pom.xml                                       |   1 -
 java-chassis-dependencies/pom.xml                  |   5 +
 java-chassis-distribution/pom.xml                  |   4 +
 swagger/swagger-invocation/invocation-core/pom.xml |   2 +-
 .../swagger/engine/SwaggerProducerOperation.java   |  12 ++
 .../exception/ExceptionToResponseConverter.java    |   4 +
 .../exception/ExceptionToResponseConverters.java   |   2 +-
 .../extension/ProducerInvokeExtension.java}        |  24 ++--
 ...vocation.exception.ExceptionToResponseConverter |   2 +-
 .../TestExceptionToResponseConverters.java         |   2 +-
 .../invocation-validator}/pom.xml                  |  23 ++--
 ...raintViolationExceptionToResponseConverter.java |  35 +++---
 .../invocation/validator/ParameterValidator.java   |  65 +++++++++++
 ...vocation.exception.ExceptionToResponseConverter |  36 +++---
 ...er.invocation.extension.ProducerInvokeExtension |   4 +-
 swagger/swagger-invocation/pom.xml                 |   1 +
 21 files changed, 379 insertions(+), 157 deletions(-)
 copy samples/jaxrs-sample/jaxrs-provider/src/main/java/org/apache/servicecomb/samples/jaxrs/provider/JaxrsHelloImpl.java => demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/Validator.java (53%)
 copy demo/demo-schema/src/main/java/org/apache/servicecomb/demo/{compute/Person.java => validator/Student.java} (71%)
 copy swagger/swagger-invocation/invocation-core/src/{test/java/org/apache/servicecomb/swagger/invocation/exception/ErrorToResponseConverter.java => main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java} (60%)
 copy {handlers/handler-fault-injection => swagger/swagger-invocation/invocation-validator}/pom.xml (78%)
 mode change 100755 => 100644
 copy handlers/handler-bizkeeper/src/main/java/org/apache/servicecomb/bizkeeper/ProviderBizkeeperCommand.java => swagger/swagger-invocation/invocation-validator/src/main/java/org/apache/servicecomb/swagger/invocation/validator/ConstraintViolationExceptionToResponseConverter.java (56%)
 create mode 100644 swagger/swagger-invocation/invocation-validator/src/main/java/org/apache/servicecomb/swagger/invocation/validator/ParameterValidator.java
 copy swagger/swagger-invocation/{invocation-core/src/test => invocation-validator/src/main}/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter (88%)
 copy common/common-rest/src/test/resources/config/test.properties => swagger/swagger-invocation/invocation-validator/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension (91%)

-- 
To stop receiving notification emails like this one, please contact
liubao@apache.org.

[incubator-servicecomb-java-chassis] 04/13: Update ExceptionToResponseConverter.java

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 9fbba49c4a04dd7678623ecb8bdbdd42b3186d15
Author: acsukesh <su...@huawei.com>
AuthorDate: Fri Mar 30 19:10:38 2018 +0530

    Update ExceptionToResponseConverter.java
---
 .../swagger/invocation/exception/ExceptionToResponseConverter.java      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java
index 4c14ad8..1d6e6e8 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java
@@ -23,7 +23,7 @@ public interface ExceptionToResponseConverter<T extends Throwable> {
   Class<T> getExceptionClass();
 
   default int getOrder() {
-    return 0;
+    return 100;
   }
 
   Response convert(SwaggerInvocation swaggerInvocation, T e);

-- 
To stop receiving notification emails like this one, please contact
liubao@apache.org.

[incubator-servicecomb-java-chassis] 11/13: [SCB-292] chassis support standard parameter validation

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 430e81ee1532916204a4f84c5e7ca46e1e90ff03
Author: acsukesh <su...@huawei.com>
AuthorDate: Fri Apr 13 11:01:00 2018 +0530

    [SCB-292] chassis support standard parameter validation
---
 .../demo/jaxrs/client/CustomLoadbalanceExtensionsFactory.java    | 9 +++++++++
 .../org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java    | 6 +++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/CustomLoadbalanceExtensionsFactory.java b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/CustomLoadbalanceExtensionsFactory.java
index 819249d..77ce21b 100644
--- a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/CustomLoadbalanceExtensionsFactory.java
+++ b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/CustomLoadbalanceExtensionsFactory.java
@@ -22,6 +22,7 @@ import org.springframework.stereotype.Component;
 
 import com.netflix.client.DefaultLoadBalancerRetryHandler;
 import com.netflix.client.RetryHandler;
+import com.netflix.client.Utils;
 import com.netflix.loadbalancer.IRule;
 import com.netflix.loadbalancer.RoundRobinRule;
 
@@ -33,6 +34,14 @@ public class CustomLoadbalanceExtensionsFactory implements ExtensionsFactory {
   }
 
   class MyCustomHandler extends DefaultLoadBalancerRetryHandler {
+    @Override
+    public boolean isRetriableException(Throwable e, boolean sameServer) {
+      if (retryEnabled) {
+        return Utils.isPresentAsCause(e, getRetriableExceptions());
+      }
+      return false;
+    }
+
     public MyCustomHandler(int retrySameServer, int retryNextServer, boolean retryEnabled) {
       super(retrySameServer, retryNextServer, retryEnabled);
     }
diff --git a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
index 6b7a8af..680e6ad 100644
--- a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
+++ b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
@@ -178,7 +178,7 @@ public class JaxrsClient {
       template.postForObject(cseUrlPrefix + "add", params, Integer.class);
     } catch (InvocationException e) {
       isExcep = true;
-      TestMgr.check(490, e.getStatus().getStatusCode());
+      TestMgr.check(400, e.getStatus().getStatusCode());
     }
 
     TestMgr.check(true, isExcep);
@@ -198,7 +198,7 @@ public class JaxrsClient {
       template.exchange(cseUrlPrefix + "sayhi/{name}", HttpMethod.PUT, null, String.class, "te");
     } catch (InvocationException e) {
       isExcep = true;
-      TestMgr.check(490, e.getStatus().getStatusCode());
+      TestMgr.check(400, e.getStatus().getStatusCode());
     }
     TestMgr.check(true, isExcep);
   }
@@ -225,7 +225,7 @@ public class JaxrsClient {
           Student.class);
     } catch (InvocationException e) {
       isExcep = true;
-      TestMgr.check(490, e.getStatus().getStatusCode());
+      TestMgr.check(400, e.getStatus().getStatusCode());
     }
     TestMgr.check(true, isExcep);
   }

-- 
To stop receiving notification emails like this one, please contact
liubao@apache.org.

[incubator-servicecomb-java-chassis] 09/13: [SCB-292] chassis support standard parameter validation

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit ad72bd701db37fe8eff2f994b63109a0a2e5e390
Author: acsukesh <su...@huawei.com>
AuthorDate: Tue Apr 10 18:08:42 2018 +0530

    [SCB-292] chassis support standard parameter validation
---
 .../servicecomb/demo/jaxrs/client/JaxrsClient.java |  64 ++++++++++
 demo/demo-jaxrs/jaxrs-server/pom.xml               | 129 +++++++++++----------
 .../servicecomb/demo/jaxrs/server/Validator.java}  |  28 +++--
 .../servicecomb/demo/validator/Student.java}       |  44 +++++--
 demo/demo-validator/pom.xml                        |  34 ------
 demo/demo-validator/validator-client/pom.xml       |  55 ---------
 .../client/CodeFirstValidatorRestTemplate.java     | 118 -------------------
 .../demo/validator/client/ValidatorClient.java     |  48 --------
 .../src/main/resources/microservice.yaml           |  29 -----
 demo/demo-validator/validator-server/pom.xml       |  85 --------------
 .../src/main/resources/microservice.yaml           |  33 ------
 demo/pom.xml                                       |   1 -
 .../invocation-validator/pom.xml                   |  68 ++++++-----
 13 files changed, 212 insertions(+), 524 deletions(-)

diff --git a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
index 5047a87..8781929 100644
--- a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
+++ b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
@@ -28,9 +28,11 @@ import org.apache.servicecomb.demo.CodeFirstRestTemplate;
 import org.apache.servicecomb.demo.DemoConst;
 import org.apache.servicecomb.demo.TestMgr;
 import org.apache.servicecomb.demo.compute.Person;
+import org.apache.servicecomb.demo.compute.Student;
 import org.apache.servicecomb.foundation.common.utils.BeanUtils;
 import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
 import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
+import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
@@ -57,6 +59,7 @@ public class JaxrsClient {
     CodeFirstRestTemplate codeFirstClient = new CodeFirstRestTemplateJaxrs();
     codeFirstClient.testCodeFirst(templateNew, "jaxrs", "/codeFirstJaxrs/");
     testCompute(templateNew);
+    testValidator(templateNew);
   }
 
   private static void testCompute(RestTemplate template) throws Exception {
@@ -76,6 +79,21 @@ public class JaxrsClient {
     }
   }
 
+  private static void testValidator(RestTemplate template) throws Exception {
+    String microserviceName = "jaxrs";
+    for (String transport : DemoConst.transports) {
+      CseContext.getInstance().getConsumerProviderManager().setTransport(microserviceName, transport);
+      TestMgr.setMsg(microserviceName, transport);
+
+      String cseUrlPrefix = "cse://" + microserviceName + "/validator/";
+
+      testValidatorAdd(template, cseUrlPrefix);
+      testValidatorSayHi(template, cseUrlPrefix);
+      testValidatorExchange(template, cseUrlPrefix);
+    }
+  }
+
+
   private static void testGet(RestTemplate template, String cseUrlPrefix) {
     Map<String, String> params = new HashMap<>();
     params.put("a", "5");
@@ -147,4 +165,50 @@ public class JaxrsClient {
     TestMgr.check("hello Tom",
         template.postForObject(cseUrlPrefix + "/compute/testrawjson", jsonPerson, String.class));
   }
+
+  private static void testValidatorAdd(RestTemplate template, String cseUrlPrefix) {
+    Map<String, String> params = new HashMap<>();
+    params.put("a", "5");
+    params.put("b", "3");
+    boolean isExcep = false;
+    try {
+      template.postForObject(cseUrlPrefix + "add", params, Integer.class);
+    } catch (InvocationException e) {
+      isExcep = true;
+      TestMgr.check(490, e.getStatus().getStatusCode());
+    }
+
+    TestMgr.check(true, isExcep);
+  }
+
+  private static void testValidatorSayHi(RestTemplate template, String cseUrlPrefix) {
+    boolean isExcep = false;
+    try {
+      template.exchange(cseUrlPrefix + "sayhi/{name}", HttpMethod.PUT, null, String.class, "te");
+    } catch (InvocationException e) {
+      isExcep = true;
+      TestMgr.check(490, e.getStatus().getStatusCode());
+    }
+    TestMgr.check(true, isExcep);
+  }
+
+  private static void testValidatorExchange(RestTemplate template, String cseUrlPrefix) {
+    HttpHeaders headers = new HttpHeaders();
+    headers.add("Accept", MediaType.APPLICATION_JSON);
+    Student student = new Student();
+    student.setName("");
+    student.setAge(25);
+    boolean isExcep = false;
+    try {
+      HttpEntity<Student> requestEntity = new HttpEntity<>(student, headers);
+      template.exchange(cseUrlPrefix + "/sayhello",
+          HttpMethod.POST,
+          requestEntity,
+          Student.class);
+    } catch (InvocationException e) {
+      isExcep = true;
+      TestMgr.check(490, e.getStatus().getStatusCode());
+    }
+    TestMgr.check(true, isExcep);
+  }
 }
diff --git a/demo/demo-jaxrs/jaxrs-server/pom.xml b/demo/demo-jaxrs/jaxrs-server/pom.xml
index af8de56..0abb64f 100644
--- a/demo/demo-jaxrs/jaxrs-server/pom.xml
+++ b/demo/demo-jaxrs/jaxrs-server/pom.xml
@@ -17,68 +17,69 @@
   -->
 
 <project
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
-	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-	<modelVersion>4.0.0</modelVersion>
-	<parent>
-		<groupId>org.apache.servicecomb.demo</groupId>
-		<artifactId>demo-jaxrs</artifactId>
-		<version>1.0.0-m2-SNAPSHOT</version>
-	</parent>
-	<artifactId>jaxrs-server</artifactId>
-	<name>Java Chassis::Demo::JAXRS::Server</name>
-
-	<dependencies>
-		<dependency>
-			<groupId>org.apache.servicecomb.demo</groupId>
-			<artifactId>demo-schema</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.servicecomb</groupId>
-			<artifactId>provider-jaxrs</artifactId>
-		</dependency>
-	</dependencies>
-
-	<properties>
-		<demo.main>org.apache.servicecomb.demo.jaxrs.server.JaxrsServer</demo.main>
-	</properties>
-	<build>
-		<plugins>
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-dependency-plugin</artifactId>
-			</plugin>
-			<plugin>
-				<groupId>com.github.odavid.maven.plugins</groupId>
-				<artifactId>mixin-maven-plugin</artifactId>
-				<configuration>
-					<mixins>
-						<mixin>
-							<groupId>org.apache.servicecomb.demo</groupId>
-							<artifactId>docker-build-config</artifactId>
-							<version>1.0.0-m2-SNAPSHOT</version>
-						</mixin>
-					</mixins>
-				</configuration>
-			</plugin>
-		</plugins>
-	</build>
-
-	<profiles>
-		<profile>
-			<id>docker</id>
-			<build>
-				<plugins>
-					<plugin>
-						<groupId>io.fabric8</groupId>
-						<artifactId>docker-maven-plugin</artifactId>
-					</plugin>
-					<plugin>
-						<groupId>org.commonjava.maven.plugins</groupId>
-						<artifactId>directory-maven-plugin</artifactId>
-					</plugin>
-				</plugins>
-			</build>
-		</profile>
-	</profiles>
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+  xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.servicecomb.demo</groupId>
+    <artifactId>demo-jaxrs</artifactId>
+    <version>1.0.0-m2-SNAPSHOT</version>
+  </parent>
+  <artifactId>jaxrs-server</artifactId>
+  <name>Java Chassis::Demo::JAXRS::Server</name>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.servicecomb.demo</groupId>
+      <artifactId>demo-schema</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>provider-jaxrs</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>swagger-invocation-validator</artifactId>
+    </dependency>
+  </dependencies>
+  <properties>
+    <demo.main>org.apache.servicecomb.demo.jaxrs.server.JaxrsServer</demo.main>
+  </properties>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+      </plugin>
+      <plugin>
+        <groupId>com.github.odavid.maven.plugins</groupId>
+        <artifactId>mixin-maven-plugin</artifactId>
+        <configuration>
+          <mixins>
+            <mixin>
+              <groupId>org.apache.servicecomb.demo</groupId>
+              <artifactId>docker-build-config</artifactId>
+              <version>1.0.0-m2-SNAPSHOT</version>
+            </mixin>
+          </mixins>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <profiles>
+    <profile>
+      <id>docker</id>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>io.fabric8</groupId>
+            <artifactId>docker-maven-plugin</artifactId>
+          </plugin>
+          <plugin>
+            <groupId>org.commonjava.maven.plugins</groupId>
+            <artifactId>directory-maven-plugin</artifactId>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
 </project>
diff --git a/demo/demo-validator/validator-server/src/main/java/org/apache/servicecomb/demo/validator/server/CodeFirstJaxrs.java b/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/Validator.java
similarity index 79%
rename from demo/demo-validator/validator-server/src/main/java/org/apache/servicecomb/demo/validator/server/CodeFirstJaxrs.java
rename to demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/Validator.java
index a9fc320..a87e61f 100644
--- a/demo/demo-validator/validator-server/src/main/java/org/apache/servicecomb/demo/validator/server/CodeFirstJaxrs.java
+++ b/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/Validator.java
@@ -15,11 +15,11 @@
  * limitations under the License.
  */
 
-package org.apache.servicecomb.demo.validator.server;
+package org.apache.servicecomb.demo.jaxrs.server;
 
+import javax.validation.Valid;
 import javax.validation.constraints.Min;
 import javax.ws.rs.FormParam;
-import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
@@ -27,20 +27,15 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 
-import org.apache.servicecomb.core.Const;
+import org.apache.servicecomb.demo.compute.Student;
 import org.apache.servicecomb.provider.rest.common.RestSchema;
 import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
 import org.hibernate.validator.constraints.Length;
 
-@RestSchema(schemaId = "codeFirst")
-@Path("/codeFirstJaxrs")
+@RestSchema(schemaId = "validator")
+@Path("/validator")
 @Produces(MediaType.APPLICATION_JSON)
-public class CodeFirstJaxrs {
-
-  @GET
-  public int defaultPath() {
-    return 100;
-  }
+public class Validator {
 
   @Path("/add")
   @POST
@@ -55,9 +50,12 @@ public class CodeFirstJaxrs {
     return name + " sayhi";
   }
 
-  @Path("/traceId")
-  @GET
-  public String getTraceId() {
-    return ContextUtils.getInvocationContext().getContext(Const.TRACE_ID_NAME);
+  @Path("/sayhello")
+  @POST
+  public Student sayHello(@Valid Student student) {
+    student.setName("hello " + student.getName());
+    student.setAge(student.getAge());
+    return student;
   }
+
 }
diff --git a/demo/demo-validator/validator-server/src/main/java/org/apache/servicecomb/demo/validator/server/ValidatorServer.java b/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/validator/Student.java
similarity index 56%
rename from demo/demo-validator/validator-server/src/main/java/org/apache/servicecomb/demo/validator/server/ValidatorServer.java
rename to demo/demo-schema/src/main/java/org/apache/servicecomb/demo/validator/Student.java
index 5ce0ed0..65feea2 100644
--- a/demo/demo-validator/validator-server/src/main/java/org/apache/servicecomb/demo/validator/server/ValidatorServer.java
+++ b/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/validator/Student.java
@@ -15,14 +15,44 @@
  * limitations under the License.
  */
 
-package org.apache.servicecomb.demo.validator.server;
+package org.apache.servicecomb.demo.validator;
 
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
-import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.NotNull;
 
-public class ValidatorServer {
-  public static void main(String[] args) throws Exception {
-    Log4jUtils.init();
-    BeanUtils.init();
+public class Student {
+  @NotNull
+  private String name;
+
+  @Max(20)
+  private int age;
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getName() {
+    return this.name;
+  }
+
+  public Student() {
+  }
+
+  public int getAge() {
+    return age;
+  }
+
+  public void setAge(int age) {
+    this.age = age;
+  }
+
+  public Student(String name, int age) {
+    this.name = name;
+    this.age = age;
+  }
+
+  @Override
+  public String toString() {
+    return name + " " + age;
   }
 }
diff --git a/demo/demo-validator/pom.xml b/demo/demo-validator/pom.xml
deleted file mode 100644
index 2cb5750..0000000
--- a/demo/demo-validator/pom.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  ~ 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.
-  -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-  <modelVersion>4.0.0</modelVersion>
-  <parent>
-    <groupId>org.apache.servicecomb.demo</groupId>
-    <artifactId>demo-parent</artifactId>
-    <version>1.0.0-m2-SNAPSHOT</version>
-  </parent>
-  <artifactId>demo-validator</artifactId>
-  <name>Java Chassis::Demo::Validator</name>
-  <packaging>pom</packaging>
-  <modules>
-    <module>validator-server</module>
-    <module>validator-client</module>
-  </modules>
-</project>
diff --git a/demo/demo-validator/validator-client/pom.xml b/demo/demo-validator/validator-client/pom.xml
deleted file mode 100644
index 7b906e9..0000000
--- a/demo/demo-validator/validator-client/pom.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-<?xml version="1.0"?>
-<!--
-  ~ 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.
-  -->
-
-<project
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
-  xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-  <modelVersion>4.0.0</modelVersion>
-  <parent>
-    <groupId>org.apache.servicecomb.demo</groupId>
-    <artifactId>demo-validator</artifactId>
-    <version>1.0.0-m2-SNAPSHOT</version>
-  </parent>
-  <artifactId>validator-client</artifactId>
-  <name>Java Chassis::Demo::Validator::Client</name>
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.servicecomb.demo</groupId>
-      <artifactId>demo-schema</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.servicecomb</groupId>
-      <artifactId>provider-jaxrs</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.servicecomb</groupId>
-      <artifactId>provider-springmvc</artifactId>
-    </dependency>
-  </dependencies>
-  <properties>
-    <demo.main>org.apache.servicecomb.demo.validator.client.ValidatorClient</demo.main>
-  </properties>
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-dependency-plugin</artifactId>
-      </plugin>
-    </plugins>
-  </build>
-</project>
diff --git a/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/CodeFirstValidatorRestTemplate.java b/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/CodeFirstValidatorRestTemplate.java
deleted file mode 100644
index 5026970..0000000
--- a/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/CodeFirstValidatorRestTemplate.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * 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.demo.validator.client;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.servicecomb.core.Const;
-import org.apache.servicecomb.core.CseContext;
-import org.apache.servicecomb.demo.DemoConst;
-import org.apache.servicecomb.demo.TestMgr;
-import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
-import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
-import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.client.RestTemplate;
-
-public class CodeFirstValidatorRestTemplate {
-  protected void changeTransport(String microserviceName, String transport) {
-    CseContext.getInstance().getConsumerProviderManager().setTransport(microserviceName, transport);
-    TestMgr.setMsg(microserviceName, transport);
-  }
-
-  public void testCodeFirst(RestTemplate template, String microserviceName, String basePath) {
-    String cseUrlPrefix = "cse://" + microserviceName + basePath;
-    for (String transport : DemoConst.transports) {
-      changeTransport(microserviceName, transport);
-      testAllTransport(microserviceName, template, cseUrlPrefix);
-    }
-  }
-
-  protected void testAllTransport(String microserviceName, RestTemplate template, String cseUrlPrefix) {
-    testCodeFirstAdd(template, cseUrlPrefix);
-    testCodeFirstAddForException(template, cseUrlPrefix);
-    testCodeFirstSayHi(template, cseUrlPrefix);
-    testCodeFirstSayHiForException(template, cseUrlPrefix);
-    testTraceIdOnContextContainsTraceId(template, cseUrlPrefix);
-  }
-
-  protected void checkStatusCode(String microserviceName, int expectStatusCode, HttpStatus httpStatus) {
-    TestMgr.check(expectStatusCode, httpStatus.value());
-  }
-
-  protected void testCodeFirstSayHi(RestTemplate template, String cseUrlPrefix) {
-    ResponseEntity<String> responseEntity =
-        template.exchange(cseUrlPrefix + "sayhi/{name}", HttpMethod.PUT, null, String.class, "world");
-    TestMgr.check(202, responseEntity.getStatusCode());
-    TestMgr.check("world sayhi", responseEntity.getBody());
-  }
-
-  protected void testCodeFirstSayHiForException(RestTemplate template, String cseUrlPrefix) {
-    boolean isExcep = false;
-    try {
-      template.exchange(cseUrlPrefix + "sayhi/{name}", HttpMethod.PUT, null, String.class, "te");
-    } catch (InvocationException e) {
-      isExcep = true;
-      TestMgr.check(e.getStatus().getStatusCode(), 400);
-    }
-    TestMgr.check(true, isExcep);
-  }
-
-  protected void testCodeFirstAdd(RestTemplate template, String cseUrlPrefix) {
-    Map<String, String> params = new HashMap<>();
-    params.put("a", "5");
-    params.put("b", "20");
-    int result =
-        template.postForObject(cseUrlPrefix + "add", params, Integer.class);
-    TestMgr.check(25, result);
-  }
-
-  protected void testCodeFirstAddForException(RestTemplate template, String cseUrlPrefix) {
-    Map<String, String> params = new HashMap<>();
-    params.put("a", "5");
-    params.put("b", "3");
-    boolean isExcep = false;
-    try {
-      template.postForObject(cseUrlPrefix + "add", params, Integer.class);
-    } catch (InvocationException e) {
-      isExcep = true;
-      TestMgr.check(e.getStatus().getStatusCode(), 400);
-    }
-
-    TestMgr.check(true, isExcep);
-  }
-
-  protected void testTraceIdOnNotSetBefore(RestTemplate template, String cseUrlPrefix) {
-    String traceIdUrl = cseUrlPrefix + "traceId";
-    String result = template.getForObject(traceIdUrl, String.class);
-    TestMgr.checkNotEmpty(result);
-  }
-
-  protected void testTraceIdOnContextContainsTraceId(RestTemplate template, String cseUrlPrefix) {
-    String traceIdUrl = cseUrlPrefix + "traceId";
-    InvocationContext invocationContext = new InvocationContext();
-    invocationContext.addContext(Const.TRACE_ID_NAME, String.valueOf(Long.MIN_VALUE));
-    ContextUtils.setInvocationContext(invocationContext);
-    String result = template.getForObject(traceIdUrl, String.class);
-    TestMgr.check(String.valueOf(Long.MIN_VALUE), result);
-    ContextUtils.removeInvocationContext();
-  }
-}
diff --git a/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/ValidatorClient.java b/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/ValidatorClient.java
deleted file mode 100644
index 2f257a1..0000000
--- a/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/ValidatorClient.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.demo.validator.client;
-
-import org.apache.servicecomb.demo.TestMgr;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
-import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
-import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
-import org.springframework.web.client.RestTemplate;
-
-public class ValidatorClient {
-  private static RestTemplate templateNew = RestTemplateBuilder.create();
-
-  public static void main(String[] args) throws Exception {
-    init();
-
-    run();
-
-    TestMgr.summary();
-  }
-
-  public static void init() throws Exception {
-    Log4jUtils.init();
-    BeanUtils.init();
-  }
-
-  public static void run() throws Exception {
-    CodeFirstValidatorRestTemplate codeFirstClient = new CodeFirstValidatorRestTemplate();
-    codeFirstClient.testCodeFirst(templateNew, "validator", "/codeFirstJaxrs/");
-  }
-
-
-}
diff --git a/demo/demo-validator/validator-client/src/main/resources/microservice.yaml b/demo/demo-validator/validator-client/src/main/resources/microservice.yaml
deleted file mode 100644
index 8055ff5..0000000
--- a/demo/demo-validator/validator-client/src/main/resources/microservice.yaml
+++ /dev/null
@@ -1,29 +0,0 @@
-## ---------------------------------------------------------------------------
-## 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.
-## ---------------------------------------------------------------------------
-
-APPLICATION_ID: validatortest
-service_description:
-  name: validatorClient
-  version: 0.0.1
-cse:
-  service:
-    registry:
-      address: http://127.0.0.1:30100
-  handler:
-    chain:
-      Consumer:
-        default: bizkeeper-consumer,loadbalance
diff --git a/demo/demo-validator/validator-server/pom.xml b/demo/demo-validator/validator-server/pom.xml
deleted file mode 100644
index 4437cf9..0000000
--- a/demo/demo-validator/validator-server/pom.xml
+++ /dev/null
@@ -1,85 +0,0 @@
-<?xml version="1.0"?>
-<!--
-  ~ 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.
-  -->
-
-<project
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
-  xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-  <modelVersion>4.0.0</modelVersion>
-  <parent>
-    <groupId>org.apache.servicecomb.demo</groupId>
-    <artifactId>demo-validator</artifactId>
-    <version>1.0.0-m2-SNAPSHOT</version>
-  </parent>
-  <artifactId>validator-server</artifactId>
-  <name>Java Chassis::Demo::Validator::Server</name>
-  <dependencies>
-    <dependency>
-    <groupId>org.apache.servicecomb.demo</groupId>
-    <artifactId>demo-schema</artifactId>
-    </dependency>
-    <dependency>
-    <groupId>org.apache.servicecomb</groupId>
-    <artifactId>provider-jaxrs</artifactId>
-    </dependency>
-    <dependency>
-    <groupId>org.apache.servicecomb</groupId>
-    <artifactId>swagger-invocation-validator</artifactId>
-    </dependency>
-  </dependencies>
-  <properties>
-    <demo.main>org.apache.servicecomb.demo.validator.server.ValidatorServer</demo.main>
-  </properties>
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-dependency-plugin</artifactId>
-      </plugin>
-      <plugin>
-        <groupId>com.github.odavid.maven.plugins</groupId>
-        <artifactId>mixin-maven-plugin</artifactId>
-        <configuration>
-          <mixins>
-            <mixin>
-              <groupId>org.apache.servicecomb.demo</groupId>
-              <artifactId>docker-build-config</artifactId>
-              <version>1.0.0-m2-SNAPSHOT</version>
-            </mixin>
-          </mixins>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
-  <profiles>
-    <profile>
-      <id>docker</id>
-      <build>
-        <plugins>
-          <plugin>
-            <groupId>io.fabric8</groupId>
-            <artifactId>docker-maven-plugin</artifactId>
-          </plugin>
-          <plugin>
-            <groupId>org.commonjava.maven.plugins</groupId>
-            <artifactId>directory-maven-plugin</artifactId>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-  </profiles>
-</project>
diff --git a/demo/demo-validator/validator-server/src/main/resources/microservice.yaml b/demo/demo-validator/validator-server/src/main/resources/microservice.yaml
deleted file mode 100644
index b2711fd..0000000
--- a/demo/demo-validator/validator-server/src/main/resources/microservice.yaml
+++ /dev/null
@@ -1,33 +0,0 @@
-## ---------------------------------------------------------------------------
-## 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.
-## ---------------------------------------------------------------------------
-
-APPLICATION_ID: validatortest
-service_description:
-  name: validator
-  version: 0.0.2
-cse:
-  service:
-    registry:
-      address: http://127.0.0.1:30100
-  rest:
-    address: 0.0.0.0:8080
-  highway:
-    address: 0.0.0.0:7070
-  handler:
-    chain:
-      Provider:
-        default: bizkeeper-provider
diff --git a/demo/pom.xml b/demo/pom.xml
index 465ec97..55505d2 100644
--- a/demo/pom.xml
+++ b/demo/pom.xml
@@ -47,7 +47,6 @@
     <module>demo-multiple</module>
     <module>demo-signature</module>
     <module>demo-edge</module>
-    <module>demo-validator</module>
     <module>perf</module>
   </modules>
 
diff --git a/swagger/swagger-invocation/invocation-validator/pom.xml b/swagger/swagger-invocation/invocation-validator/pom.xml
index b0eb754..08b2c0c 100644
--- a/swagger/swagger-invocation/invocation-validator/pom.xml
+++ b/swagger/swagger-invocation/invocation-validator/pom.xml
@@ -16,39 +16,37 @@
   -->
 
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-	<modelVersion>4.0.0</modelVersion>
-	<parent>
-		<groupId>org.apache.servicecomb</groupId>
-		<artifactId>swagger-invocation</artifactId>
-		<version>1.0.0-m2-SNAPSHOT</version>
-	</parent>
-	<artifactId>swagger-invocation-validator</artifactId>
-	<name>Java Chassis::Swagger::Invocation::Validator</name>
-
-
-	<dependencies>
-		<dependency>
-			<groupId>org.apache.servicecomb</groupId>
-			<artifactId>swagger-invocation-core</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>org.hibernate</groupId>
-			<artifactId>hibernate-validator</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>org.glassfish</groupId>
-			<artifactId>javax.el</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>org.slf4j</groupId>
-			<artifactId>slf4j-log4j12</artifactId>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>log4j</groupId>
-			<artifactId>log4j</artifactId>
-			<scope>test</scope>
-		</dependency>
-	</dependencies>
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.servicecomb</groupId>
+    <artifactId>swagger-invocation</artifactId>
+    <version>1.0.0-m2-SNAPSHOT</version>
+  </parent>
+  <artifactId>swagger-invocation-validator</artifactId>
+  <name>Java Chassis::Swagger::Invocation::Validator</name>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>swagger-invocation-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.hibernate</groupId>
+      <artifactId>hibernate-validator</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.glassfish</groupId>
+      <artifactId>javax.el</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
 </project>
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
liubao@apache.org.

[incubator-servicecomb-java-chassis] 06/13: Update ExceptionToResponseConverter.java

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 91958ffe556d1564249abccd78e9e4b2c46feea8
Author: acsukesh <su...@huawei.com>
AuthorDate: Mon Apr 9 14:14:16 2018 +0530

    Update ExceptionToResponseConverter.java
---
 .../swagger/invocation/exception/ExceptionToResponseConverter.java      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java
index 1d6e6e8..4c14ad8 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java
@@ -23,7 +23,7 @@ public interface ExceptionToResponseConverter<T extends Throwable> {
   Class<T> getExceptionClass();
 
   default int getOrder() {
-    return 100;
+    return 0;
   }
 
   Response convert(SwaggerInvocation swaggerInvocation, T e);

-- 
To stop receiving notification emails like this one, please contact
liubao@apache.org.

[incubator-servicecomb-java-chassis] 03/13: [SCB-292] chassis support standard parameter validation

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 0bfdcaccceb6adccba821f4034469b4dd97a82b4
Author: acsukesh <su...@huawei.com>
AuthorDate: Fri Mar 30 19:04:50 2018 +0530

    [SCB-292] chassis support standard parameter validation
---
 java-chassis-dependencies/pom.xml                  |  5 +++++
 java-chassis-distribution/pom.xml                  |  4 ++++
 swagger/swagger-invocation/invocation-core/pom.xml | 10 +---------
 .../extension/ProducerInvokeExtension.java         |  4 +---
 ...vocation.exception.ExceptionToResponseConverter |  1 -
 .../pom.xml                                        | 23 +++++++++-------------
 ...raintViolationExceptionToResponseConverter.java |  2 +-
 .../invocation/validator}/ParameterValidator.java  |  8 +++++++-
 ...ocation.exception.ExceptionToResponseConverter} |  2 +-
 ...er.invocation.extension.ProducerInvokeExtension |  2 +-
 swagger/swagger-invocation/pom.xml                 |  1 +
 11 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/java-chassis-dependencies/pom.xml b/java-chassis-dependencies/pom.xml
index 02af808..92a0047 100644
--- a/java-chassis-dependencies/pom.xml
+++ b/java-chassis-dependencies/pom.xml
@@ -901,6 +901,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.servicecomb</groupId>
+        <artifactId>swagger-invocation-validator</artifactId>
+        <version>1.0.0-m2-SNAPSHOT</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.servicecomb</groupId>
         <artifactId>service-registry</artifactId>
         <version>1.0.0-m2-SNAPSHOT</version>
       </dependency>
diff --git a/java-chassis-distribution/pom.xml b/java-chassis-distribution/pom.xml
index 95b30e1..ebaa667 100644
--- a/java-chassis-distribution/pom.xml
+++ b/java-chassis-distribution/pom.xml
@@ -90,6 +90,10 @@
         </dependency>
         <dependency>
             <groupId>org.apache.servicecomb</groupId>
+            <artifactId>swagger-invocation-validator</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicecomb</groupId>
             <artifactId>foundation-common</artifactId>
         </dependency>
         <dependency>
diff --git a/swagger/swagger-invocation/invocation-core/pom.xml b/swagger/swagger-invocation/invocation-core/pom.xml
index 492be2e..b7a367e 100644
--- a/swagger/swagger-invocation/invocation-core/pom.xml
+++ b/swagger/swagger-invocation/invocation-core/pom.xml
@@ -38,14 +38,6 @@
 			<scope>test</scope>
 		</dependency>
 		<dependency>
-      	    <groupId>org.hibernate</groupId>
-      		<artifactId>hibernate-validator</artifactId>
-    	</dependency>
-    	<dependency>
-      		<groupId>org.glassfish</groupId>
-      		<artifactId>javax.el</artifactId>
-	    </dependency>
-		<dependency>
 			<groupId>org.slf4j</groupId>
 			<artifactId>slf4j-log4j12</artifactId>
 			<scope>test</scope>
@@ -56,4 +48,4 @@
 			<scope>test</scope>
 		</dependency>
 	</dependencies>
-</project>
+</project>
\ No newline at end of file
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java
index efa1b9c..e559124 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java
@@ -22,9 +22,7 @@ import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
 
 public interface ProducerInvokeExtension {
 
-  default int getOrder() {
-    return 0;
-  }
+  public int getOrder();
 
   <T> void beforeMethodInvoke(SwaggerInvocation invocation, SwaggerProducerOperation producerOperation,
       Object[] args) throws Exception;
diff --git a/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter b/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter
index 1d0e0bc..b717491 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter
+++ b/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter
@@ -17,4 +17,3 @@
 
 org.apache.servicecomb.swagger.invocation.exception.InvocationExceptionToResponseConverter
 org.apache.servicecomb.swagger.invocation.exception.DefaultExceptionToResponseConverter
-org.apache.servicecomb.swagger.invocation.extension.ConstraintViolationExceptionToResponseConverter
\ No newline at end of file
diff --git a/swagger/swagger-invocation/invocation-core/pom.xml b/swagger/swagger-invocation/invocation-validator/pom.xml
similarity index 75%
copy from swagger/swagger-invocation/invocation-core/pom.xml
copy to swagger/swagger-invocation/invocation-validator/pom.xml
index 492be2e..b0eb754 100644
--- a/swagger/swagger-invocation/invocation-core/pom.xml
+++ b/swagger/swagger-invocation/invocation-validator/pom.xml
@@ -23,28 +23,23 @@
 		<artifactId>swagger-invocation</artifactId>
 		<version>1.0.0-m2-SNAPSHOT</version>
 	</parent>
-	<artifactId>swagger-invocation-core</artifactId>
-	<name>Java Chassis::Swagger::Invocation::Core</name>
+	<artifactId>swagger-invocation-validator</artifactId>
+	<name>Java Chassis::Swagger::Invocation::Validator</name>
 
 
 	<dependencies>
 		<dependency>
 			<groupId>org.apache.servicecomb</groupId>
-			<artifactId>swagger-generator-core</artifactId>
+			<artifactId>swagger-invocation-core</artifactId>
 		</dependency>
 		<dependency>
-			<groupId>org.apache.servicecomb</groupId>
-			<artifactId>swagger-generator-jaxrs</artifactId>
-			<scope>test</scope>
+			<groupId>org.hibernate</groupId>
+			<artifactId>hibernate-validator</artifactId>
 		</dependency>
 		<dependency>
-      	    <groupId>org.hibernate</groupId>
-      		<artifactId>hibernate-validator</artifactId>
-    	</dependency>
-    	<dependency>
-      		<groupId>org.glassfish</groupId>
-      		<artifactId>javax.el</artifactId>
-	    </dependency>
+			<groupId>org.glassfish</groupId>
+			<artifactId>javax.el</artifactId>
+		</dependency>
 		<dependency>
 			<groupId>org.slf4j</groupId>
 			<artifactId>slf4j-log4j12</artifactId>
@@ -56,4 +51,4 @@
 			<scope>test</scope>
 		</dependency>
 	</dependencies>
-</project>
+</project>
\ No newline at end of file
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ConstraintViolationExceptionToResponseConverter.java b/swagger/swagger-invocation/invocation-validator/src/main/java/org/apache/servicecomb/swagger/invocation/validator/ConstraintViolationExceptionToResponseConverter.java
similarity index 96%
rename from swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ConstraintViolationExceptionToResponseConverter.java
rename to swagger/swagger-invocation/invocation-validator/src/main/java/org/apache/servicecomb/swagger/invocation/validator/ConstraintViolationExceptionToResponseConverter.java
index 98a1412..61c2c30 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ConstraintViolationExceptionToResponseConverter.java
+++ b/swagger/swagger-invocation/invocation-validator/src/main/java/org/apache/servicecomb/swagger/invocation/validator/ConstraintViolationExceptionToResponseConverter.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.servicecomb.swagger.invocation.extension;
+package org.apache.servicecomb.swagger.invocation.validator;
 
 import javax.validation.ConstraintViolationException;
 import javax.ws.rs.core.Response.Status;
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ParameterValidator.java b/swagger/swagger-invocation/invocation-validator/src/main/java/org/apache/servicecomb/swagger/invocation/validator/ParameterValidator.java
similarity index 91%
rename from swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ParameterValidator.java
rename to swagger/swagger-invocation/invocation-validator/src/main/java/org/apache/servicecomb/swagger/invocation/validator/ParameterValidator.java
index 7372377..a2ed0c6 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ParameterValidator.java
+++ b/swagger/swagger-invocation/invocation-validator/src/main/java/org/apache/servicecomb/swagger/invocation/validator/ParameterValidator.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.servicecomb.swagger.invocation.extension;
+package org.apache.servicecomb.swagger.invocation.validator;
 
 import java.util.Set;
 
@@ -27,6 +27,7 @@ import javax.validation.groups.Default;
 
 import org.apache.servicecomb.swagger.engine.SwaggerProducerOperation;
 import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -56,4 +57,9 @@ public class ParameterValidator implements ProducerInvokeExtension {
     }
   }
 
+  @Override
+  public int getOrder() {
+    return 100;
+  }
+
 }
diff --git a/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension b/swagger/swagger-invocation/invocation-validator/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter
similarity index 88%
copy from swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension
copy to swagger/swagger-invocation/invocation-validator/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter
index a532fe7..9667b7a 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension
+++ b/swagger/swagger-invocation/invocation-validator/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-org.apache.servicecomb.swagger.invocation.extension.ParameterValidator
+org.apache.servicecomb.swagger.invocation.validator.ConstraintViolationExceptionToResponseConverter
\ No newline at end of file
diff --git a/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension b/swagger/swagger-invocation/invocation-validator/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension
similarity index 92%
rename from swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension
rename to swagger/swagger-invocation/invocation-validator/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension
index a532fe7..215fc56 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension
+++ b/swagger/swagger-invocation/invocation-validator/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-org.apache.servicecomb.swagger.invocation.extension.ParameterValidator
+org.apache.servicecomb.swagger.invocation.validator.ParameterValidator
diff --git a/swagger/swagger-invocation/pom.xml b/swagger/swagger-invocation/pom.xml
index b22339c..515db2c 100644
--- a/swagger/swagger-invocation/pom.xml
+++ b/swagger/swagger-invocation/pom.xml
@@ -30,5 +30,6 @@
   	<module>invocation-core</module>
   	<module>invocation-jaxrs</module>
   	<module>invocation-springmvc</module>
+  	<module>invocation-validator</module>
   </modules>
 </project>

-- 
To stop receiving notification emails like this one, please contact
liubao@apache.org.

[incubator-servicecomb-java-chassis] 10/13: [SCB-292] chassis support standard parameter validation

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit ca933c141d41615dc04d2d55b577277aa20b78dc
Author: acsukesh <su...@huawei.com>
AuthorDate: Tue Apr 10 20:46:16 2018 +0530

    [SCB-292] chassis support standard parameter validation
---
 .../servicecomb/demo/jaxrs/client/JaxrsClient.java | 40 ++++++++++++++++++----
 .../servicecomb/demo/jaxrs/server/Validator.java   |  2 +-
 2 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
index 8781929..6b7a8af 100644
--- a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
+++ b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
@@ -28,7 +28,7 @@ import org.apache.servicecomb.demo.CodeFirstRestTemplate;
 import org.apache.servicecomb.demo.DemoConst;
 import org.apache.servicecomb.demo.TestMgr;
 import org.apache.servicecomb.demo.compute.Person;
-import org.apache.servicecomb.demo.compute.Student;
+import org.apache.servicecomb.demo.validator.Student;
 import org.apache.servicecomb.foundation.common.utils.BeanUtils;
 import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
 import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
@@ -87,9 +87,12 @@ public class JaxrsClient {
 
       String cseUrlPrefix = "cse://" + microserviceName + "/validator/";
 
-      testValidatorAdd(template, cseUrlPrefix);
-      testValidatorSayHi(template, cseUrlPrefix);
-      testValidatorExchange(template, cseUrlPrefix);
+      testValidatorAddSuccess(template, cseUrlPrefix);
+      testValidatorAddFail(template, cseUrlPrefix);
+      testValidatorSayHiSuccess(template, cseUrlPrefix);
+      testValidatorSayHiFail(template, cseUrlPrefix);
+      testValidatorExchangeSuccess(template, cseUrlPrefix);
+      testValidatorExchangeFail(template, cseUrlPrefix);
     }
   }
 
@@ -166,7 +169,7 @@ public class JaxrsClient {
         template.postForObject(cseUrlPrefix + "/compute/testrawjson", jsonPerson, String.class));
   }
 
-  private static void testValidatorAdd(RestTemplate template, String cseUrlPrefix) {
+  private static void testValidatorAddFail(RestTemplate template, String cseUrlPrefix) {
     Map<String, String> params = new HashMap<>();
     params.put("a", "5");
     params.put("b", "3");
@@ -181,7 +184,15 @@ public class JaxrsClient {
     TestMgr.check(true, isExcep);
   }
 
-  private static void testValidatorSayHi(RestTemplate template, String cseUrlPrefix) {
+  private static void testValidatorAddSuccess(RestTemplate template, String cseUrlPrefix) {
+    Map<String, String> params = new HashMap<>();
+    params.put("a", "5");
+    params.put("b", "20");
+    int result = template.postForObject(cseUrlPrefix + "add", params, Integer.class);
+    TestMgr.check(25, result);
+  }
+
+  private static void testValidatorSayHiFail(RestTemplate template, String cseUrlPrefix) {
     boolean isExcep = false;
     try {
       template.exchange(cseUrlPrefix + "sayhi/{name}", HttpMethod.PUT, null, String.class, "te");
@@ -192,7 +203,14 @@ public class JaxrsClient {
     TestMgr.check(true, isExcep);
   }
 
-  private static void testValidatorExchange(RestTemplate template, String cseUrlPrefix) {
+  private static void testValidatorSayHiSuccess(RestTemplate template, String cseUrlPrefix) {
+    ResponseEntity<String> responseEntity =
+        template.exchange(cseUrlPrefix + "sayhi/{name}", HttpMethod.PUT, null, String.class, "world");
+    TestMgr.check(202, responseEntity.getStatusCode());
+    TestMgr.check("world sayhi", responseEntity.getBody());
+  }
+
+  private static void testValidatorExchangeFail(RestTemplate template, String cseUrlPrefix) {
     HttpHeaders headers = new HttpHeaders();
     headers.add("Accept", MediaType.APPLICATION_JSON);
     Student student = new Student();
@@ -211,4 +229,12 @@ public class JaxrsClient {
     }
     TestMgr.check(true, isExcep);
   }
+
+  private static void testValidatorExchangeSuccess(RestTemplate template, String cseUrlPrefix) {
+    Student student = new Student();
+    student.setName("test");
+    student.setAge(15);
+    Student result = template.postForObject(cseUrlPrefix + "sayhello", student, Student.class);
+    TestMgr.check("hello test 15", result);
+  }
 }
diff --git a/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/Validator.java b/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/Validator.java
index a87e61f..986f6a3 100644
--- a/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/Validator.java
+++ b/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/Validator.java
@@ -27,7 +27,7 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 
-import org.apache.servicecomb.demo.compute.Student;
+import org.apache.servicecomb.demo.validator.Student;
 import org.apache.servicecomb.provider.rest.common.RestSchema;
 import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
 import org.hibernate.validator.constraints.Length;

-- 
To stop receiving notification emails like this one, please contact
liubao@apache.org.

[incubator-servicecomb-java-chassis] 08/13: [SCB-292] chassis support standard parameter validation

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit c1d265ef874ae95a0c3a2e70fba80ca9fbf463f7
Author: acsukesh <su...@huawei.com>
AuthorDate: Tue Apr 10 11:28:10 2018 +0530

    [SCB-292] chassis support standard parameter validation
---
 .../schema/TestProducerSchemaFactory.java          |   2 +-
 demo/demo-validator/pom.xml                        |  27 ++---
 demo/demo-validator/validator-client/pom.xml       |  73 ++++++-----
 .../client/CodeFirstRestTemplateValidator.java     |  37 ------
 .../client/CodeFirstValidatorRestTemplate.java     |   7 +-
 demo/demo-validator/validator-server/pom.xml       | 133 ++++++++++-----------
 6 files changed, 119 insertions(+), 160 deletions(-)

diff --git a/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java b/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
index 5aa29c2..40e40cf 100644
--- a/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
+++ b/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
@@ -1,5 +1,5 @@
 /*
-	 * Licensed to the Apache Software Foundation (ASF) under one or more
+ * 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
diff --git a/demo/demo-validator/pom.xml b/demo/demo-validator/pom.xml
index 1525262..2cb5750 100644
--- a/demo/demo-validator/pom.xml
+++ b/demo/demo-validator/pom.xml
@@ -17,19 +17,18 @@
   -->
 
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-	<modelVersion>4.0.0</modelVersion>
-	<parent>
-		<groupId>org.apache.servicecomb.demo</groupId>
-		<artifactId>demo-parent</artifactId>
-		<version>1.0.0-m2-SNAPSHOT</version>
-	</parent>
-	<artifactId>demo-validator</artifactId>
-	<name>Java Chassis::Demo::Validator</name>
-	<packaging>pom</packaging>
-	<modules>
-		<module>validator-server</module>
-		<module>validator-client</module>
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.servicecomb.demo</groupId>
+    <artifactId>demo-parent</artifactId>
+    <version>1.0.0-m2-SNAPSHOT</version>
+  </parent>
+  <artifactId>demo-validator</artifactId>
+  <name>Java Chassis::Demo::Validator</name>
+  <packaging>pom</packaging>
+  <modules>
+    <module>validator-server</module>
+    <module>validator-client</module>
   </modules>
-
 </project>
diff --git a/demo/demo-validator/validator-client/pom.xml b/demo/demo-validator/validator-client/pom.xml
index c9e044b..7b906e9 100644
--- a/demo/demo-validator/validator-client/pom.xml
+++ b/demo/demo-validator/validator-client/pom.xml
@@ -17,42 +17,39 @@
   -->
 
 <project
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
-	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-	<modelVersion>4.0.0</modelVersion>
-	<parent>
-		<groupId>org.apache.servicecomb.demo</groupId>
-		<artifactId>demo-validator</artifactId>
-		<version>1.0.0-m2-SNAPSHOT</version>
-	</parent>
-	<artifactId>validator-client</artifactId>
-	<name>Java Chassis::Demo::Validator::Client</name>
-
-	<dependencies>
-		<dependency>
-			<groupId>org.apache.servicecomb.demo</groupId>
-			<artifactId>demo-schema</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.servicecomb</groupId>
-			<artifactId>provider-jaxrs</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.servicecomb</groupId>
-			<artifactId>provider-springmvc</artifactId>
-		</dependency>
-	</dependencies>
-
-	<properties>
-		<demo.main>org.apache.servicecomb.demo.jaxrs.client.JaxrsClient</demo.main>
-	</properties>
-	<build>
-		<plugins>
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-dependency-plugin</artifactId>
-			</plugin>
-		</plugins>
-	</build>
-
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+  xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.servicecomb.demo</groupId>
+    <artifactId>demo-validator</artifactId>
+    <version>1.0.0-m2-SNAPSHOT</version>
+  </parent>
+  <artifactId>validator-client</artifactId>
+  <name>Java Chassis::Demo::Validator::Client</name>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.servicecomb.demo</groupId>
+      <artifactId>demo-schema</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>provider-jaxrs</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>provider-springmvc</artifactId>
+    </dependency>
+  </dependencies>
+  <properties>
+    <demo.main>org.apache.servicecomb.demo.validator.client.ValidatorClient</demo.main>
+  </properties>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </build>
 </project>
diff --git a/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/CodeFirstRestTemplateValidator.java b/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/CodeFirstRestTemplateValidator.java
deleted file mode 100644
index 2f4ff80..0000000
--- a/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/CodeFirstRestTemplateValidator.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.demo.validator.client;
-
-import org.apache.servicecomb.demo.CodeFirstRestTemplate;
-import org.apache.servicecomb.demo.TestMgr;
-import org.springframework.web.client.RestTemplate;
-
-public class CodeFirstRestTemplateValidator extends CodeFirstRestTemplate {
-  @Override
-  protected void testAllTransport(String microserviceName, RestTemplate template, String cseUrlPrefix) {
-    testDefaultPath(template, cseUrlPrefix);
-
-    super.testAllTransport(microserviceName, template, cseUrlPrefix);
-  }
-
-  private void testDefaultPath(RestTemplate template, String cseUrlPrefix) {
-    int result =
-        template.getForObject(cseUrlPrefix.substring(0, cseUrlPrefix.length() - 1), Integer.class);
-    TestMgr.check(100, result);
-  }
-}
diff --git a/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/CodeFirstValidatorRestTemplate.java b/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/CodeFirstValidatorRestTemplate.java
index 9c4c971..5026970 100644
--- a/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/CodeFirstValidatorRestTemplate.java
+++ b/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/CodeFirstValidatorRestTemplate.java
@@ -26,6 +26,7 @@ import org.apache.servicecomb.demo.DemoConst;
 import org.apache.servicecomb.demo.TestMgr;
 import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
 import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
+import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -68,8 +69,9 @@ public class CodeFirstValidatorRestTemplate {
     boolean isExcep = false;
     try {
       template.exchange(cseUrlPrefix + "sayhi/{name}", HttpMethod.PUT, null, String.class, "te");
-    } catch (Exception e) {
+    } catch (InvocationException e) {
       isExcep = true;
+      TestMgr.check(e.getStatus().getStatusCode(), 400);
     }
     TestMgr.check(true, isExcep);
   }
@@ -90,8 +92,9 @@ public class CodeFirstValidatorRestTemplate {
     boolean isExcep = false;
     try {
       template.postForObject(cseUrlPrefix + "add", params, Integer.class);
-    } catch (Exception e) {
+    } catch (InvocationException e) {
       isExcep = true;
+      TestMgr.check(e.getStatus().getStatusCode(), 400);
     }
 
     TestMgr.check(true, isExcep);
diff --git a/demo/demo-validator/validator-server/pom.xml b/demo/demo-validator/validator-server/pom.xml
index 7959ae4..4437cf9 100644
--- a/demo/demo-validator/validator-server/pom.xml
+++ b/demo/demo-validator/validator-server/pom.xml
@@ -17,72 +17,69 @@
   -->
 
 <project
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
-	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-	<modelVersion>4.0.0</modelVersion>
-	<parent>
-		<groupId>org.apache.servicecomb.demo</groupId>
-		<artifactId>demo-validator</artifactId>
-		<version>1.0.0-m2-SNAPSHOT</version>
-	</parent>
-	<artifactId>validator-server</artifactId>
-	<name>Java Chassis::Demo::Validator::Server</name>
-
-	<dependencies>
-		<dependency>
-			<groupId>org.apache.servicecomb.demo</groupId>
-			<artifactId>demo-schema</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.servicecomb</groupId>
-			<artifactId>provider-jaxrs</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.servicecomb</groupId>
-			<artifactId>swagger-invocation-validator</artifactId>
-	</dependency>
-	</dependencies>
-
-	<properties>
-		<demo.main>org.apache.servicecomb.demo.jaxrs.server.JaxrsServer</demo.main>
-	</properties>
-	<build>
-		<plugins>
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-dependency-plugin</artifactId>
-			</plugin>
-			<plugin>
-				<groupId>com.github.odavid.maven.plugins</groupId>
-				<artifactId>mixin-maven-plugin</artifactId>
-				<configuration>
-					<mixins>
-						<mixin>
-							<groupId>org.apache.servicecomb.demo</groupId>
-							<artifactId>docker-build-config</artifactId>
-							<version>1.0.0-m2-SNAPSHOT</version>
-						</mixin>
-					</mixins>
-				</configuration>
-			</plugin>
-		</plugins>
-	</build>
-
-	<profiles>
-		<profile>
-			<id>docker</id>
-			<build>
-				<plugins>
-					<plugin>
-						<groupId>io.fabric8</groupId>
-						<artifactId>docker-maven-plugin</artifactId>
-					</plugin>
-					<plugin>
-						<groupId>org.commonjava.maven.plugins</groupId>
-						<artifactId>directory-maven-plugin</artifactId>
-					</plugin>
-				</plugins>
-			</build>
-		</profile>
-	</profiles>
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+  xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.servicecomb.demo</groupId>
+    <artifactId>demo-validator</artifactId>
+    <version>1.0.0-m2-SNAPSHOT</version>
+  </parent>
+  <artifactId>validator-server</artifactId>
+  <name>Java Chassis::Demo::Validator::Server</name>
+  <dependencies>
+    <dependency>
+    <groupId>org.apache.servicecomb.demo</groupId>
+    <artifactId>demo-schema</artifactId>
+    </dependency>
+    <dependency>
+    <groupId>org.apache.servicecomb</groupId>
+    <artifactId>provider-jaxrs</artifactId>
+    </dependency>
+    <dependency>
+    <groupId>org.apache.servicecomb</groupId>
+    <artifactId>swagger-invocation-validator</artifactId>
+    </dependency>
+  </dependencies>
+  <properties>
+    <demo.main>org.apache.servicecomb.demo.validator.server.ValidatorServer</demo.main>
+  </properties>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+      </plugin>
+      <plugin>
+        <groupId>com.github.odavid.maven.plugins</groupId>
+        <artifactId>mixin-maven-plugin</artifactId>
+        <configuration>
+          <mixins>
+            <mixin>
+              <groupId>org.apache.servicecomb.demo</groupId>
+              <artifactId>docker-build-config</artifactId>
+              <version>1.0.0-m2-SNAPSHOT</version>
+            </mixin>
+          </mixins>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <profiles>
+    <profile>
+      <id>docker</id>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>io.fabric8</groupId>
+            <artifactId>docker-maven-plugin</artifactId>
+          </plugin>
+          <plugin>
+            <groupId>org.commonjava.maven.plugins</groupId>
+            <artifactId>directory-maven-plugin</artifactId>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
 </project>

-- 
To stop receiving notification emails like this one, please contact
liubao@apache.org.

[incubator-servicecomb-java-chassis] 02/13: [SCB-292] chassis support standard parameter validation

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 29f68197d699ce367704fd9d571ead875ae3e5cf
Author: acsukesh <su...@huawei.com>
AuthorDate: Fri Mar 30 12:37:56 2018 +0530

    [SCB-292] chassis support standard parameter validation
---
 .../exception/ExceptionToResponseConverter.java      |  4 ++++
 .../extension/AbstractProducerInvokeExtension.java   | 20 --------------------
 ...traintViolationExceptionToResponseConverter.java} | 20 ++++++++++++++++----
 .../invocation/extension/ParameterValidator.java     |  4 ++--
 ...invocation.exception.ExceptionToResponseConverter |  3 ++-
 5 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java
index 3b36f5a..4c14ad8 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java
@@ -22,5 +22,9 @@ import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
 public interface ExceptionToResponseConverter<T extends Throwable> {
   Class<T> getExceptionClass();
 
+  default int getOrder() {
+    return 0;
+  }
+
   Response convert(SwaggerInvocation swaggerInvocation, T e);
 }
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/AbstractProducerInvokeExtension.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/AbstractProducerInvokeExtension.java
deleted file mode 100644
index 7080bf7..0000000
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/AbstractProducerInvokeExtension.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * 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.swagger.invocation.extension;
-
-public abstract class AbstractProducerInvokeExtension implements ProducerInvokeExtension {
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ConstraintViolationExceptionToResponseConverter.java
similarity index 53%
copy from swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java
copy to swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ConstraintViolationExceptionToResponseConverter.java
index 3b36f5a..98a1412 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ConstraintViolationExceptionToResponseConverter.java
@@ -14,13 +14,25 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.servicecomb.swagger.invocation.exception;
+package org.apache.servicecomb.swagger.invocation.extension;
+
+import javax.validation.ConstraintViolationException;
+import javax.ws.rs.core.Response.Status;
 
 import org.apache.servicecomb.swagger.invocation.Response;
 import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter;
+import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
 
-public interface ExceptionToResponseConverter<T extends Throwable> {
-  Class<T> getExceptionClass();
+public class ConstraintViolationExceptionToResponseConverter
+    implements ExceptionToResponseConverter<ConstraintViolationException> {
+  @Override
+  public Class<ConstraintViolationException> getExceptionClass() {
+    return ConstraintViolationException.class;
+  }
 
-  Response convert(SwaggerInvocation swaggerInvocation, T e);
+  @Override
+  public Response convert(SwaggerInvocation swaggerInvocation, ConstraintViolationException e) {
+    return Response.createFail(new InvocationException(Status.BAD_REQUEST, e.getMessage()));
+  }
 }
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ParameterValidator.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ParameterValidator.java
index 510ed75..7372377 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ParameterValidator.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ParameterValidator.java
@@ -30,7 +30,7 @@ import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class ParameterValidator extends AbstractProducerInvokeExtension {
+public class ParameterValidator implements ProducerInvokeExtension {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(ParameterValidator.class);
 
@@ -52,7 +52,7 @@ public class ParameterValidator extends AbstractProducerInvokeExtension {
             Default.class);
     if (violations.size() > 0) {
       LOGGER.warn("Parameter validation failed : " + violations.toString());
-      throw new ConstraintViolationException(violations);
+      throw new ConstraintViolationException(violations.toString(), violations);
     }
   }
 
diff --git a/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter b/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter
index 2fc781e..1d0e0bc 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter
+++ b/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter
@@ -16,4 +16,5 @@
 #
 
 org.apache.servicecomb.swagger.invocation.exception.InvocationExceptionToResponseConverter
-org.apache.servicecomb.swagger.invocation.exception.DefaultExceptionToResponseConverter
\ No newline at end of file
+org.apache.servicecomb.swagger.invocation.exception.DefaultExceptionToResponseConverter
+org.apache.servicecomb.swagger.invocation.extension.ConstraintViolationExceptionToResponseConverter
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
liubao@apache.org.

[incubator-servicecomb-java-chassis] 12/13: [SCB-292] chassis support standard parameter validation

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 35941661f5f17d823ddf82f7673e1f7ff3b30f8d
Author: acsukesh <su...@huawei.com>
AuthorDate: Fri Apr 13 14:34:00 2018 +0530

    [SCB-292] chassis support standard parameter validation
---
 .../java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
index 680e6ad..ba82bd1 100644
--- a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
+++ b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
@@ -21,6 +21,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response.Status;
 
 import org.apache.servicecomb.common.rest.codec.RestObjectMapper;
 import org.apache.servicecomb.core.CseContext;
@@ -179,6 +180,8 @@ public class JaxrsClient {
     } catch (InvocationException e) {
       isExcep = true;
       TestMgr.check(400, e.getStatus().getStatusCode());
+      TestMgr.check(Status.BAD_REQUEST, e.getReasonPhrase());
+      TestMgr.check(true, e.getErrorData().toString().contains("ConstraintViolationImpl"));
     }
 
     TestMgr.check(true, isExcep);
@@ -199,6 +202,8 @@ public class JaxrsClient {
     } catch (InvocationException e) {
       isExcep = true;
       TestMgr.check(400, e.getStatus().getStatusCode());
+      TestMgr.check(Status.BAD_REQUEST, e.getReasonPhrase());
+      TestMgr.check(true, e.getErrorData().toString().contains("ConstraintViolationImpl"));
     }
     TestMgr.check(true, isExcep);
   }
@@ -226,6 +231,8 @@ public class JaxrsClient {
     } catch (InvocationException e) {
       isExcep = true;
       TestMgr.check(400, e.getStatus().getStatusCode());
+      TestMgr.check(Status.BAD_REQUEST, e.getReasonPhrase());
+      TestMgr.check(true, e.getErrorData().toString().contains("ConstraintViolationImpl"));
     }
     TestMgr.check(true, isExcep);
   }

-- 
To stop receiving notification emails like this one, please contact
liubao@apache.org.

[incubator-servicecomb-java-chassis] 01/13: [SCB-292] chassis support standard parameter validation

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit ae70b49730a3bef2c9b86f70b28bfc89c06abae0
Author: acsukesh <su...@huawei.com>
AuthorDate: Thu Mar 29 16:12:49 2018 +0530

    [SCB-292] chassis support standard parameter validation
---
 .../schema/TestProducerSchemaFactory.java          |  8 +++
 swagger/swagger-invocation/invocation-core/pom.xml |  8 +++
 .../swagger/engine/SwaggerProducerOperation.java   | 16 ++++++
 .../extension/AbstractProducerInvokeExtension.java | 20 ++++++++
 .../invocation/extension/ParameterValidator.java   | 59 ++++++++++++++++++++++
 .../extension/ProducerInvokeExtension.java         | 31 ++++++++++++
 ...er.invocation.extension.ProducerInvokeExtension | 18 +++++++
 7 files changed, 160 insertions(+)

diff --git a/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java b/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
index 40e40cf..e0f433e 100644
--- a/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
+++ b/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
@@ -16,6 +16,7 @@
  */
 package org.apache.servicecomb.core.definition.schema;
 
+import java.util.List;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.Executor;
 
@@ -33,6 +34,7 @@ import org.apache.servicecomb.core.executor.ReactiveExecutor;
 import org.apache.servicecomb.core.unittest.UnitTestMeta;
 import org.apache.servicecomb.foundation.common.utils.BeanUtils;
 import org.apache.servicecomb.foundation.common.utils.ReflectUtils;
+import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
 import org.apache.servicecomb.serviceregistry.RegistryUtils;
 import org.apache.servicecomb.serviceregistry.ServiceRegistry;
 import org.apache.servicecomb.serviceregistry.registry.ServiceRegistryFactory;
@@ -45,6 +47,7 @@ import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgu
 import org.apache.servicecomb.swagger.invocation.converter.ConverterMgr;
 import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
 import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension;
 import org.hamcrest.Matchers;
 import org.junit.AfterClass;
 import org.junit.Assert;
@@ -134,6 +137,11 @@ public class TestProducerSchemaFactory {
 
     SwaggerProducerOperation producerOperation = operationMeta.getExtData(Const.PRODUCER_OPERATION);
 
+    List<ProducerInvokeExtension> producerInvokeExtenstionList =
+        SPIServiceUtils.getSortedService(ProducerInvokeExtension.class);
+
+    producerOperation.setProducerInvokeExtenstionList(producerInvokeExtenstionList);
+
     Object addBody = Class.forName("cse.gen.app.ms.schema.addBody").newInstance();
     ReflectUtils.setField(addBody, "x", 1);
     ReflectUtils.setField(addBody, "y", 2);
diff --git a/swagger/swagger-invocation/invocation-core/pom.xml b/swagger/swagger-invocation/invocation-core/pom.xml
index d60e954..492be2e 100644
--- a/swagger/swagger-invocation/invocation-core/pom.xml
+++ b/swagger/swagger-invocation/invocation-core/pom.xml
@@ -38,6 +38,14 @@
 			<scope>test</scope>
 		</dependency>
 		<dependency>
+      	    <groupId>org.hibernate</groupId>
+      		<artifactId>hibernate-validator</artifactId>
+    	</dependency>
+    	<dependency>
+      		<groupId>org.glassfish</groupId>
+      		<artifactId>javax.el</artifactId>
+	    </dependency>
+		<dependency>
 			<groupId>org.slf4j</groupId>
 			<artifactId>slf4j-log4j12</artifactId>
 			<scope>test</scope>
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
index 4827a76..150bce1 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
@@ -18,14 +18,17 @@ package org.apache.servicecomb.swagger.engine;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.List;
 import java.util.concurrent.CompletableFuture;
 
+import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
 import org.apache.servicecomb.swagger.invocation.AsyncResponse;
 import org.apache.servicecomb.swagger.invocation.Response;
 import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
 import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapper;
 import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
 import org.apache.servicecomb.swagger.invocation.exception.ExceptionFactory;
+import org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension;
 import org.apache.servicecomb.swagger.invocation.response.producer.ProducerResponseMapper;
 
 public class SwaggerProducerOperation {
@@ -44,6 +47,13 @@ public class SwaggerProducerOperation {
 
   private ProducerResponseMapper responseMapper;
 
+  private List<ProducerInvokeExtension> producerInvokeExtenstionList =
+      SPIServiceUtils.getSortedService(ProducerInvokeExtension.class);
+
+  public void setProducerInvokeExtenstionList(List<ProducerInvokeExtension> producerInvokeExtenstionList) {
+    this.producerInvokeExtenstionList = producerInvokeExtenstionList;
+  }
+
   public String getName() {
     return name;
   }
@@ -119,6 +129,9 @@ public class SwaggerProducerOperation {
   public void doCompletableFutureInvoke(SwaggerInvocation invocation, AsyncResponse asyncResp) {
     try {
       Object[] args = argumentsMapper.toProducerArgs(invocation);
+      for (ProducerInvokeExtension producerInvokeExtension : producerInvokeExtenstionList) {
+        producerInvokeExtension.beforeMethodInvoke(invocation, this, args);
+      }
       Object result = producerMethod.invoke(producerInstance, args);
 
       ((CompletableFuture<Object>) result).whenComplete((realResult, ex) -> {
@@ -145,6 +158,9 @@ public class SwaggerProducerOperation {
     Response response = null;
     try {
       Object[] args = argumentsMapper.toProducerArgs(invocation);
+      for (ProducerInvokeExtension producerInvokeExtension : producerInvokeExtenstionList) {
+        producerInvokeExtension.beforeMethodInvoke(invocation, this, args);
+      }
       Object result = producerMethod.invoke(producerInstance, args);
       response = responseMapper.mapResponse(invocation.getStatus(), result);
     } catch (Throwable e) {
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/AbstractProducerInvokeExtension.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/AbstractProducerInvokeExtension.java
new file mode 100644
index 0000000..7080bf7
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/AbstractProducerInvokeExtension.java
@@ -0,0 +1,20 @@
+/*
+ * 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.swagger.invocation.extension;
+
+public abstract class AbstractProducerInvokeExtension implements ProducerInvokeExtension {
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ParameterValidator.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ParameterValidator.java
new file mode 100644
index 0000000..510ed75
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ParameterValidator.java
@@ -0,0 +1,59 @@
+/*
+ * 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.swagger.invocation.extension;
+
+import java.util.Set;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.ConstraintViolationException;
+import javax.validation.Validation;
+import javax.validation.ValidatorFactory;
+import javax.validation.executable.ExecutableValidator;
+import javax.validation.groups.Default;
+
+import org.apache.servicecomb.swagger.engine.SwaggerProducerOperation;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ParameterValidator extends AbstractProducerInvokeExtension {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(ParameterValidator.class);
+
+  private static ExecutableValidator executableValidator;
+
+  @Override
+  public <T> void beforeMethodInvoke(SwaggerInvocation invocation, SwaggerProducerOperation producerOperation,
+      Object[] args)
+      throws ConstraintViolationException {
+
+    if (null == executableValidator) {
+      ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
+      executableValidator = factory.getValidator().forExecutables();
+    }
+    Set<ConstraintViolation<Object>> violations =
+        executableValidator.validateParameters(producerOperation.getProducerInstance(),
+            producerOperation.getProducerMethod(),
+            args,
+            Default.class);
+    if (violations.size() > 0) {
+      LOGGER.warn("Parameter validation failed : " + violations.toString());
+      throw new ConstraintViolationException(violations);
+    }
+  }
+
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java
new file mode 100644
index 0000000..efa1b9c
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java
@@ -0,0 +1,31 @@
+/*
+ * 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.swagger.invocation.extension;
+
+import org.apache.servicecomb.swagger.engine.SwaggerProducerOperation;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+
+
+public interface ProducerInvokeExtension {
+
+  default int getOrder() {
+    return 0;
+  }
+
+  <T> void beforeMethodInvoke(SwaggerInvocation invocation, SwaggerProducerOperation producerOperation,
+      Object[] args) throws Exception;
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension b/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension
new file mode 100644
index 0000000..a532fe7
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.servicecomb.swagger.invocation.extension.ParameterValidator

-- 
To stop receiving notification emails like this one, please contact
liubao@apache.org.

[incubator-servicecomb-java-chassis] 05/13: [SCB-292] chassis support standard parameter validation

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit a9388f0bf6cd044d404480e7bd7d10ff5c6996e6
Author: acsukesh <su...@huawei.com>
AuthorDate: Mon Apr 9 14:05:47 2018 +0530

    [SCB-292] chassis support standard parameter validation
---
 .../schema/TestProducerSchemaFactory.java          |  10 +-
 demo/demo-validator/pom.xml                        |  35 +++++++
 demo/demo-validator/validator-client/pom.xml       |  58 +++++++++++
 .../client/CodeFirstRestTemplateValidator.java     |  22 ++--
 .../client/CodeFirstValidatorRestTemplate.java     | 115 +++++++++++++++++++++
 .../demo/validator/client/ValidatorClient.java     |  48 +++++++++
 .../src/main/resources/microservice.yaml           |  29 ++++++
 demo/demo-validator/validator-server/pom.xml       |  88 ++++++++++++++++
 .../demo/validator/server/CodeFirstJaxrs.java      |  63 +++++++++++
 .../demo/validator/server/ValidatorServer.java     |  17 ++-
 .../src/main/resources/microservice.yaml           |  33 ++++++
 demo/pom.xml                                       |   2 +-
 .../swagger/engine/SwaggerProducerOperation.java   |   4 -
 .../exception/ExceptionToResponseConverters.java   |   2 +-
 .../extension/ProducerInvokeExtension.java         |   5 +-
 ...raintViolationExceptionToResponseConverter.java |   7 +-
 .../invocation/validator/ParameterValidator.java   |   2 +-
 17 files changed, 506 insertions(+), 34 deletions(-)

diff --git a/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java b/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
index e0f433e..5aa29c2 100644
--- a/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
+++ b/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
@@ -1,5 +1,5 @@
 /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
+	 * 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
@@ -16,7 +16,6 @@
  */
 package org.apache.servicecomb.core.definition.schema;
 
-import java.util.List;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.Executor;
 
@@ -34,7 +33,6 @@ import org.apache.servicecomb.core.executor.ReactiveExecutor;
 import org.apache.servicecomb.core.unittest.UnitTestMeta;
 import org.apache.servicecomb.foundation.common.utils.BeanUtils;
 import org.apache.servicecomb.foundation.common.utils.ReflectUtils;
-import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
 import org.apache.servicecomb.serviceregistry.RegistryUtils;
 import org.apache.servicecomb.serviceregistry.ServiceRegistry;
 import org.apache.servicecomb.serviceregistry.registry.ServiceRegistryFactory;
@@ -47,7 +45,6 @@ import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgu
 import org.apache.servicecomb.swagger.invocation.converter.ConverterMgr;
 import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
 import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
-import org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension;
 import org.hamcrest.Matchers;
 import org.junit.AfterClass;
 import org.junit.Assert;
@@ -137,11 +134,6 @@ public class TestProducerSchemaFactory {
 
     SwaggerProducerOperation producerOperation = operationMeta.getExtData(Const.PRODUCER_OPERATION);
 
-    List<ProducerInvokeExtension> producerInvokeExtenstionList =
-        SPIServiceUtils.getSortedService(ProducerInvokeExtension.class);
-
-    producerOperation.setProducerInvokeExtenstionList(producerInvokeExtenstionList);
-
     Object addBody = Class.forName("cse.gen.app.ms.schema.addBody").newInstance();
     ReflectUtils.setField(addBody, "x", 1);
     ReflectUtils.setField(addBody, "y", 2);
diff --git a/demo/demo-validator/pom.xml b/demo/demo-validator/pom.xml
new file mode 100644
index 0000000..1525262
--- /dev/null
+++ b/demo/demo-validator/pom.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.servicecomb.demo</groupId>
+		<artifactId>demo-parent</artifactId>
+		<version>1.0.0-m2-SNAPSHOT</version>
+	</parent>
+	<artifactId>demo-validator</artifactId>
+	<name>Java Chassis::Demo::Validator</name>
+	<packaging>pom</packaging>
+	<modules>
+		<module>validator-server</module>
+		<module>validator-client</module>
+  </modules>
+
+</project>
diff --git a/demo/demo-validator/validator-client/pom.xml b/demo/demo-validator/validator-client/pom.xml
new file mode 100644
index 0000000..c9e044b
--- /dev/null
+++ b/demo/demo-validator/validator-client/pom.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0"?>
+<!--
+  ~ 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.
+  -->
+
+<project
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.servicecomb.demo</groupId>
+		<artifactId>demo-validator</artifactId>
+		<version>1.0.0-m2-SNAPSHOT</version>
+	</parent>
+	<artifactId>validator-client</artifactId>
+	<name>Java Chassis::Demo::Validator::Client</name>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.servicecomb.demo</groupId>
+			<artifactId>demo-schema</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.servicecomb</groupId>
+			<artifactId>provider-jaxrs</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.servicecomb</groupId>
+			<artifactId>provider-springmvc</artifactId>
+		</dependency>
+	</dependencies>
+
+	<properties>
+		<demo.main>org.apache.servicecomb.demo.jaxrs.client.JaxrsClient</demo.main>
+	</properties>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-dependency-plugin</artifactId>
+			</plugin>
+		</plugins>
+	</build>
+
+</project>
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java b/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/CodeFirstRestTemplateValidator.java
similarity index 51%
copy from swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java
copy to demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/CodeFirstRestTemplateValidator.java
index e559124..2f4ff80 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java
+++ b/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/CodeFirstRestTemplateValidator.java
@@ -14,16 +14,24 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.servicecomb.swagger.invocation.extension;
 
-import org.apache.servicecomb.swagger.engine.SwaggerProducerOperation;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+package org.apache.servicecomb.demo.validator.client;
 
+import org.apache.servicecomb.demo.CodeFirstRestTemplate;
+import org.apache.servicecomb.demo.TestMgr;
+import org.springframework.web.client.RestTemplate;
 
-public interface ProducerInvokeExtension {
+public class CodeFirstRestTemplateValidator extends CodeFirstRestTemplate {
+  @Override
+  protected void testAllTransport(String microserviceName, RestTemplate template, String cseUrlPrefix) {
+    testDefaultPath(template, cseUrlPrefix);
 
-  public int getOrder();
+    super.testAllTransport(microserviceName, template, cseUrlPrefix);
+  }
 
-  <T> void beforeMethodInvoke(SwaggerInvocation invocation, SwaggerProducerOperation producerOperation,
-      Object[] args) throws Exception;
+  private void testDefaultPath(RestTemplate template, String cseUrlPrefix) {
+    int result =
+        template.getForObject(cseUrlPrefix.substring(0, cseUrlPrefix.length() - 1), Integer.class);
+    TestMgr.check(100, result);
+  }
 }
diff --git a/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/CodeFirstValidatorRestTemplate.java b/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/CodeFirstValidatorRestTemplate.java
new file mode 100644
index 0000000..9c4c971
--- /dev/null
+++ b/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/CodeFirstValidatorRestTemplate.java
@@ -0,0 +1,115 @@
+/*
+ * 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.demo.validator.client;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.core.Const;
+import org.apache.servicecomb.core.CseContext;
+import org.apache.servicecomb.demo.DemoConst;
+import org.apache.servicecomb.demo.TestMgr;
+import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
+import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+
+public class CodeFirstValidatorRestTemplate {
+  protected void changeTransport(String microserviceName, String transport) {
+    CseContext.getInstance().getConsumerProviderManager().setTransport(microserviceName, transport);
+    TestMgr.setMsg(microserviceName, transport);
+  }
+
+  public void testCodeFirst(RestTemplate template, String microserviceName, String basePath) {
+    String cseUrlPrefix = "cse://" + microserviceName + basePath;
+    for (String transport : DemoConst.transports) {
+      changeTransport(microserviceName, transport);
+      testAllTransport(microserviceName, template, cseUrlPrefix);
+    }
+  }
+
+  protected void testAllTransport(String microserviceName, RestTemplate template, String cseUrlPrefix) {
+    testCodeFirstAdd(template, cseUrlPrefix);
+    testCodeFirstAddForException(template, cseUrlPrefix);
+    testCodeFirstSayHi(template, cseUrlPrefix);
+    testCodeFirstSayHiForException(template, cseUrlPrefix);
+    testTraceIdOnContextContainsTraceId(template, cseUrlPrefix);
+  }
+
+  protected void checkStatusCode(String microserviceName, int expectStatusCode, HttpStatus httpStatus) {
+    TestMgr.check(expectStatusCode, httpStatus.value());
+  }
+
+  protected void testCodeFirstSayHi(RestTemplate template, String cseUrlPrefix) {
+    ResponseEntity<String> responseEntity =
+        template.exchange(cseUrlPrefix + "sayhi/{name}", HttpMethod.PUT, null, String.class, "world");
+    TestMgr.check(202, responseEntity.getStatusCode());
+    TestMgr.check("world sayhi", responseEntity.getBody());
+  }
+
+  protected void testCodeFirstSayHiForException(RestTemplate template, String cseUrlPrefix) {
+    boolean isExcep = false;
+    try {
+      template.exchange(cseUrlPrefix + "sayhi/{name}", HttpMethod.PUT, null, String.class, "te");
+    } catch (Exception e) {
+      isExcep = true;
+    }
+    TestMgr.check(true, isExcep);
+  }
+
+  protected void testCodeFirstAdd(RestTemplate template, String cseUrlPrefix) {
+    Map<String, String> params = new HashMap<>();
+    params.put("a", "5");
+    params.put("b", "20");
+    int result =
+        template.postForObject(cseUrlPrefix + "add", params, Integer.class);
+    TestMgr.check(25, result);
+  }
+
+  protected void testCodeFirstAddForException(RestTemplate template, String cseUrlPrefix) {
+    Map<String, String> params = new HashMap<>();
+    params.put("a", "5");
+    params.put("b", "3");
+    boolean isExcep = false;
+    try {
+      template.postForObject(cseUrlPrefix + "add", params, Integer.class);
+    } catch (Exception e) {
+      isExcep = true;
+    }
+
+    TestMgr.check(true, isExcep);
+  }
+
+  protected void testTraceIdOnNotSetBefore(RestTemplate template, String cseUrlPrefix) {
+    String traceIdUrl = cseUrlPrefix + "traceId";
+    String result = template.getForObject(traceIdUrl, String.class);
+    TestMgr.checkNotEmpty(result);
+  }
+
+  protected void testTraceIdOnContextContainsTraceId(RestTemplate template, String cseUrlPrefix) {
+    String traceIdUrl = cseUrlPrefix + "traceId";
+    InvocationContext invocationContext = new InvocationContext();
+    invocationContext.addContext(Const.TRACE_ID_NAME, String.valueOf(Long.MIN_VALUE));
+    ContextUtils.setInvocationContext(invocationContext);
+    String result = template.getForObject(traceIdUrl, String.class);
+    TestMgr.check(String.valueOf(Long.MIN_VALUE), result);
+    ContextUtils.removeInvocationContext();
+  }
+}
diff --git a/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/ValidatorClient.java b/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/ValidatorClient.java
new file mode 100644
index 0000000..2f257a1
--- /dev/null
+++ b/demo/demo-validator/validator-client/src/main/java/org/apache/servicecomb/demo/validator/client/ValidatorClient.java
@@ -0,0 +1,48 @@
+/*
+ * 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.demo.validator.client;
+
+import org.apache.servicecomb.demo.TestMgr;
+import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
+import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
+import org.springframework.web.client.RestTemplate;
+
+public class ValidatorClient {
+  private static RestTemplate templateNew = RestTemplateBuilder.create();
+
+  public static void main(String[] args) throws Exception {
+    init();
+
+    run();
+
+    TestMgr.summary();
+  }
+
+  public static void init() throws Exception {
+    Log4jUtils.init();
+    BeanUtils.init();
+  }
+
+  public static void run() throws Exception {
+    CodeFirstValidatorRestTemplate codeFirstClient = new CodeFirstValidatorRestTemplate();
+    codeFirstClient.testCodeFirst(templateNew, "validator", "/codeFirstJaxrs/");
+  }
+
+
+}
diff --git a/demo/demo-validator/validator-client/src/main/resources/microservice.yaml b/demo/demo-validator/validator-client/src/main/resources/microservice.yaml
new file mode 100644
index 0000000..8055ff5
--- /dev/null
+++ b/demo/demo-validator/validator-client/src/main/resources/microservice.yaml
@@ -0,0 +1,29 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+APPLICATION_ID: validatortest
+service_description:
+  name: validatorClient
+  version: 0.0.1
+cse:
+  service:
+    registry:
+      address: http://127.0.0.1:30100
+  handler:
+    chain:
+      Consumer:
+        default: bizkeeper-consumer,loadbalance
diff --git a/demo/demo-validator/validator-server/pom.xml b/demo/demo-validator/validator-server/pom.xml
new file mode 100644
index 0000000..7959ae4
--- /dev/null
+++ b/demo/demo-validator/validator-server/pom.xml
@@ -0,0 +1,88 @@
+<?xml version="1.0"?>
+<!--
+  ~ 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.
+  -->
+
+<project
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.servicecomb.demo</groupId>
+		<artifactId>demo-validator</artifactId>
+		<version>1.0.0-m2-SNAPSHOT</version>
+	</parent>
+	<artifactId>validator-server</artifactId>
+	<name>Java Chassis::Demo::Validator::Server</name>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.servicecomb.demo</groupId>
+			<artifactId>demo-schema</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.servicecomb</groupId>
+			<artifactId>provider-jaxrs</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.servicecomb</groupId>
+			<artifactId>swagger-invocation-validator</artifactId>
+	</dependency>
+	</dependencies>
+
+	<properties>
+		<demo.main>org.apache.servicecomb.demo.jaxrs.server.JaxrsServer</demo.main>
+	</properties>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-dependency-plugin</artifactId>
+			</plugin>
+			<plugin>
+				<groupId>com.github.odavid.maven.plugins</groupId>
+				<artifactId>mixin-maven-plugin</artifactId>
+				<configuration>
+					<mixins>
+						<mixin>
+							<groupId>org.apache.servicecomb.demo</groupId>
+							<artifactId>docker-build-config</artifactId>
+							<version>1.0.0-m2-SNAPSHOT</version>
+						</mixin>
+					</mixins>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+
+	<profiles>
+		<profile>
+			<id>docker</id>
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>io.fabric8</groupId>
+						<artifactId>docker-maven-plugin</artifactId>
+					</plugin>
+					<plugin>
+						<groupId>org.commonjava.maven.plugins</groupId>
+						<artifactId>directory-maven-plugin</artifactId>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+	</profiles>
+</project>
diff --git a/demo/demo-validator/validator-server/src/main/java/org/apache/servicecomb/demo/validator/server/CodeFirstJaxrs.java b/demo/demo-validator/validator-server/src/main/java/org/apache/servicecomb/demo/validator/server/CodeFirstJaxrs.java
new file mode 100644
index 0000000..a9fc320
--- /dev/null
+++ b/demo/demo-validator/validator-server/src/main/java/org/apache/servicecomb/demo/validator/server/CodeFirstJaxrs.java
@@ -0,0 +1,63 @@
+/*
+ * 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.demo.validator.server;
+
+import javax.validation.constraints.Min;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.servicecomb.core.Const;
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
+import org.hibernate.validator.constraints.Length;
+
+@RestSchema(schemaId = "codeFirst")
+@Path("/codeFirstJaxrs")
+@Produces(MediaType.APPLICATION_JSON)
+public class CodeFirstJaxrs {
+
+  @GET
+  public int defaultPath() {
+    return 100;
+  }
+
+  @Path("/add")
+  @POST
+  public int add(@FormParam("a") int a, @Min(20) @FormParam("b") int b) {
+    return a + b;
+  }
+
+  @Path("/sayhi/{name}")
+  @PUT
+  public String sayHi(@Length(min = 3) @PathParam("name") String name) {
+    ContextUtils.getInvocationContext().setStatus(202);
+    return name + " sayhi";
+  }
+
+  @Path("/traceId")
+  @GET
+  public String getTraceId() {
+    return ContextUtils.getInvocationContext().getContext(Const.TRACE_ID_NAME);
+  }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java b/demo/demo-validator/validator-server/src/main/java/org/apache/servicecomb/demo/validator/server/ValidatorServer.java
similarity index 66%
copy from swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java
copy to demo/demo-validator/validator-server/src/main/java/org/apache/servicecomb/demo/validator/server/ValidatorServer.java
index e559124..5ce0ed0 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java
+++ b/demo/demo-validator/validator-server/src/main/java/org/apache/servicecomb/demo/validator/server/ValidatorServer.java
@@ -14,16 +14,15 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.servicecomb.swagger.invocation.extension;
 
-import org.apache.servicecomb.swagger.engine.SwaggerProducerOperation;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+package org.apache.servicecomb.demo.validator.server;
 
+import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
 
-public interface ProducerInvokeExtension {
-
-  public int getOrder();
-
-  <T> void beforeMethodInvoke(SwaggerInvocation invocation, SwaggerProducerOperation producerOperation,
-      Object[] args) throws Exception;
+public class ValidatorServer {
+  public static void main(String[] args) throws Exception {
+    Log4jUtils.init();
+    BeanUtils.init();
+  }
 }
diff --git a/demo/demo-validator/validator-server/src/main/resources/microservice.yaml b/demo/demo-validator/validator-server/src/main/resources/microservice.yaml
new file mode 100644
index 0000000..b2711fd
--- /dev/null
+++ b/demo/demo-validator/validator-server/src/main/resources/microservice.yaml
@@ -0,0 +1,33 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+APPLICATION_ID: validatortest
+service_description:
+  name: validator
+  version: 0.0.2
+cse:
+  service:
+    registry:
+      address: http://127.0.0.1:30100
+  rest:
+    address: 0.0.0.0:8080
+  highway:
+    address: 0.0.0.0:7070
+  handler:
+    chain:
+      Provider:
+        default: bizkeeper-provider
diff --git a/demo/pom.xml b/demo/pom.xml
index 2cf4603..465ec97 100644
--- a/demo/pom.xml
+++ b/demo/pom.xml
@@ -47,7 +47,7 @@
     <module>demo-multiple</module>
     <module>demo-signature</module>
     <module>demo-edge</module>
-    
+    <module>demo-validator</module>
     <module>perf</module>
   </modules>
 
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
index 150bce1..5c3caf0 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
@@ -50,10 +50,6 @@ public class SwaggerProducerOperation {
   private List<ProducerInvokeExtension> producerInvokeExtenstionList =
       SPIServiceUtils.getSortedService(ProducerInvokeExtension.class);
 
-  public void setProducerInvokeExtenstionList(List<ProducerInvokeExtension> producerInvokeExtenstionList) {
-    this.producerInvokeExtenstionList = producerInvokeExtenstionList;
-  }
-
   public String getName() {
     return name;
   }
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverters.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverters.java
index bc2ea31..60706a9 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverters.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverters.java
@@ -31,7 +31,7 @@ public class ExceptionToResponseConverters {
 
   @SuppressWarnings("unchecked")
   public ExceptionToResponseConverters() {
-    SPIServiceUtils.getAllService(ExceptionToResponseConverter.class).forEach(converter -> {
+    SPIServiceUtils.getSortedService(ExceptionToResponseConverter.class).forEach(converter -> {
       if (converter.getExceptionClass() == null) {
         defaultConverter = converter;
         return;
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java
index e559124..370b3d1 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/extension/ProducerInvokeExtension.java
@@ -19,11 +19,14 @@ package org.apache.servicecomb.swagger.invocation.extension;
 import org.apache.servicecomb.swagger.engine.SwaggerProducerOperation;
 import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
 
-
+/**
+ * Producer method invocation extension to handle the required validations/checks before invoking the actual method.
+ */
 public interface ProducerInvokeExtension {
 
   public int getOrder();
 
+  ///Invoked before the method execution to handle the required checks before method invocation.
   <T> void beforeMethodInvoke(SwaggerInvocation invocation, SwaggerProducerOperation producerOperation,
       Object[] args) throws Exception;
 }
diff --git a/swagger/swagger-invocation/invocation-validator/src/main/java/org/apache/servicecomb/swagger/invocation/validator/ConstraintViolationExceptionToResponseConverter.java b/swagger/swagger-invocation/invocation-validator/src/main/java/org/apache/servicecomb/swagger/invocation/validator/ConstraintViolationExceptionToResponseConverter.java
index 61c2c30..5ade951 100644
--- a/swagger/swagger-invocation/invocation-validator/src/main/java/org/apache/servicecomb/swagger/invocation/validator/ConstraintViolationExceptionToResponseConverter.java
+++ b/swagger/swagger-invocation/invocation-validator/src/main/java/org/apache/servicecomb/swagger/invocation/validator/ConstraintViolationExceptionToResponseConverter.java
@@ -33,6 +33,11 @@ public class ConstraintViolationExceptionToResponseConverter
 
   @Override
   public Response convert(SwaggerInvocation swaggerInvocation, ConstraintViolationException e) {
-    return Response.createFail(new InvocationException(Status.BAD_REQUEST, e.getMessage()));
+    return Response.createFail(new InvocationException(Status.BAD_REQUEST, e.getConstraintViolations().toString()));
+  }
+
+  @Override
+  public int getOrder() {
+    return -100;
   }
 }
diff --git a/swagger/swagger-invocation/invocation-validator/src/main/java/org/apache/servicecomb/swagger/invocation/validator/ParameterValidator.java b/swagger/swagger-invocation/invocation-validator/src/main/java/org/apache/servicecomb/swagger/invocation/validator/ParameterValidator.java
index a2ed0c6..0cb42ed 100644
--- a/swagger/swagger-invocation/invocation-validator/src/main/java/org/apache/servicecomb/swagger/invocation/validator/ParameterValidator.java
+++ b/swagger/swagger-invocation/invocation-validator/src/main/java/org/apache/servicecomb/swagger/invocation/validator/ParameterValidator.java
@@ -53,7 +53,7 @@ public class ParameterValidator implements ProducerInvokeExtension {
             Default.class);
     if (violations.size() > 0) {
       LOGGER.warn("Parameter validation failed : " + violations.toString());
-      throw new ConstraintViolationException(violations.toString(), violations);
+      throw new ConstraintViolationException(violations);
     }
   }
 

-- 
To stop receiving notification emails like this one, please contact
liubao@apache.org.

[incubator-servicecomb-java-chassis] 13/13: [SCB-292] chassis support standard parameter validation

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 01c377cf67157e78388c88b4eb3997e6fb403953
Author: acsukesh <su...@huawei.com>
AuthorDate: Mon Apr 16 10:22:54 2018 +0530

    [SCB-292] chassis support standard parameter validation
---
 .../apache/servicecomb/demo/jaxrs/client/JaxrsClient.java    | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
index ba82bd1..5e63c2d 100644
--- a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
+++ b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
@@ -181,7 +181,9 @@ public class JaxrsClient {
       isExcep = true;
       TestMgr.check(400, e.getStatus().getStatusCode());
       TestMgr.check(Status.BAD_REQUEST, e.getReasonPhrase());
-      TestMgr.check(true, e.getErrorData().toString().contains("ConstraintViolationImpl"));
+      TestMgr.check(
+          "CommonExceptionData [message=[ConstraintViolationImpl{interpolatedMessage='must be greater than or equal to 20', propertyPath=add.arg1, rootBeanClass=class org.apache.servicecomb.demo.jaxrs.server.Validator, messageTemplate='{javax.validation.constraints.Min.message}'}]]",
+          e.getErrorData());
     }
 
     TestMgr.check(true, isExcep);
@@ -203,7 +205,9 @@ public class JaxrsClient {
       isExcep = true;
       TestMgr.check(400, e.getStatus().getStatusCode());
       TestMgr.check(Status.BAD_REQUEST, e.getReasonPhrase());
-      TestMgr.check(true, e.getErrorData().toString().contains("ConstraintViolationImpl"));
+      TestMgr.check(
+          "CommonExceptionData [message=[ConstraintViolationImpl{interpolatedMessage='length must be between 3 and 2147483647', propertyPath=sayHi.arg0, rootBeanClass=class org.apache.servicecomb.demo.jaxrs.server.Validator, messageTemplate='{org.hibernate.validator.constraints.Length.message}'}]]",
+          e.getErrorData());
     }
     TestMgr.check(true, isExcep);
   }
@@ -232,7 +236,9 @@ public class JaxrsClient {
       isExcep = true;
       TestMgr.check(400, e.getStatus().getStatusCode());
       TestMgr.check(Status.BAD_REQUEST, e.getReasonPhrase());
-      TestMgr.check(true, e.getErrorData().toString().contains("ConstraintViolationImpl"));
+      TestMgr.check(
+          "CommonExceptionData [message=[ConstraintViolationImpl{interpolatedMessage='must be less than or equal to 20', propertyPath=sayHello.arg0.age, rootBeanClass=class org.apache.servicecomb.demo.jaxrs.server.Validator, messageTemplate='{javax.validation.constraints.Max.message}'}]]",
+          e.getErrorData());
     }
     TestMgr.check(true, isExcep);
   }

-- 
To stop receiving notification emails like this one, please contact
liubao@apache.org.

[incubator-servicecomb-java-chassis] 07/13: [SCB-292] chassis support standard parameter validation

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 8319ac9aac4b61170393d5cd7f93cd15b29f77b9
Author: acsukesh <su...@huawei.com>
AuthorDate: Mon Apr 9 14:20:56 2018 +0530

    [SCB-292] chassis support standard parameter validation
---
 .../swagger/invocation/exception/TestExceptionToResponseConverters.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/exception/TestExceptionToResponseConverters.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/exception/TestExceptionToResponseConverters.java
index 221ae9e..022ff8c 100644
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/exception/TestExceptionToResponseConverters.java
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/exception/TestExceptionToResponseConverters.java
@@ -38,7 +38,7 @@ public class TestExceptionToResponseConverters {
       @Mocked Response rDef) {
     new Expectations(SPIServiceUtils.class) {
       {
-        SPIServiceUtils.getAllService(ExceptionToResponseConverter.class);
+        SPIServiceUtils.getSortedService(ExceptionToResponseConverter.class);
         result = Arrays.asList(c1, c2, cDef);
 
         c1.getExceptionClass();

-- 
To stop receiving notification emails like this one, please contact
liubao@apache.org.