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:55 UTC

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

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.