You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/09/07 01:54:06 UTC
[GitHub] liubao68 closed pull request #894: [SCB-895]When json parse fail
will not get 400 but 590
liubao68 closed pull request #894: [SCB-895]When json parse fail will not get 400 but 590
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/894
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/BodyProcessorCreator.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/BodyProcessorCreator.java
index e3016a0f4..18e5bcfc2 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/BodyProcessorCreator.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/BodyProcessorCreator.java
@@ -92,10 +92,11 @@ public Object getValue(HttpServletRequest request) throws Exception {
.readValue(inputStream, targetType);
} catch (MismatchedInputException e) {
// there is no way to detect InputStream is empty, so have to catch the exception
- if (!isRequired) {
- LOGGER.warn("Mismatched content and required is false, taken as null. Msg=" + e.getMessage());
+ if (!isRequired && e.getMessage().contains("No content to map due to end-of-input")) {
+ LOGGER.info("Empty content and required is false, taken as null");
return null;
}
+ LOGGER.warn("Mismatched content. Msg=" + e.getMessage());
throw e;
}
}
diff --git a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/MultiErrorCodeServiceClient.java b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/MultiErrorCodeServiceClient.java
index 24d90cbad..3128d8211 100644
--- a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/MultiErrorCodeServiceClient.java
+++ b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/MultiErrorCodeServiceClient.java
@@ -29,9 +29,18 @@
import org.apache.servicecomb.demo.multiErrorCode.MultiResponse200;
import org.apache.servicecomb.demo.multiErrorCode.MultiResponse400;
import org.apache.servicecomb.demo.multiErrorCode.MultiResponse500;
+import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
+import org.apache.servicecomb.serviceregistry.RegistryUtils;
+import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
+import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import org.apache.servicecomb.serviceregistry.definition.DefinitionConst;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
import io.vertx.core.json.Json;
@@ -40,6 +49,8 @@
public class MultiErrorCodeServiceClient {
private static final String SERVER = "cse://jaxrs";
+ private static String serverDirectURL;
+
private static RestTemplate template = RestTemplateBuilder.create();
public static void runTest() {
@@ -52,6 +63,51 @@ public static void runTest() {
testErrorCodeWithHeaderJAXRSUsingRowType();
testNoClientErrorCode();
}
+
+ prepareServerDirectURL();
+ testErrorCodeWrongType();
+ }
+
+ private static void prepareServerDirectURL() {
+ Microservice microservice = RegistryUtils.getMicroservice();
+ MicroserviceInstance microserviceInstance = (MicroserviceInstance) RegistryUtils.getServiceRegistry()
+ .getAppManager()
+ .getOrCreateMicroserviceVersionRule(microservice.getAppId(), "jaxrs", DefinitionConst.VERSION_RULE_ALL)
+ .getVersionedCache()
+ .mapData()
+ .values()
+ .stream()
+ .findFirst()
+ .get();
+ URIEndpointObject edgeAddress = new URIEndpointObject(microserviceInstance.getEndpoints().get(0));
+ serverDirectURL = String.format("http://%s:%d/", edgeAddress.getHostOrIp(), edgeAddress.getPort());
+ }
+
+ private static void testErrorCodeWrongType() {
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.APPLICATION_JSON);
+ String body = "{\"message\":\"hello\",\"code\":\"wrongType\"";
+ HttpEntity<String> entity = new HttpEntity<>(body, headers);
+ ResponseEntity<MultiResponse200> result;
+ try {
+ template
+ .postForEntity(serverDirectURL + "/MultiErrorCodeService/errorCode", entity, MultiResponse200.class);
+ } catch (HttpClientErrorException e) {
+ TestMgr.check(e.getStatusCode(), 400);
+ TestMgr.check(e.getMessage(), "400 Bad Request");
+ }
+
+ entity = new HttpEntity<>(null, headers);
+ result = template
+ .postForEntity(serverDirectURL + "/MultiErrorCodeService/errorCode", entity, MultiResponse200.class);
+ TestMgr.check(result.getStatusCodeValue(), 590);
+
+ body = "{\"message\":\"hello\",\"code\":\"200\"}";
+ entity = new HttpEntity<>(body, headers);
+ result = template
+ .postForEntity(serverDirectURL + "/MultiErrorCodeService/errorCode", entity, MultiResponse200.class);
+ TestMgr.check(result.getStatusCode(), 200);
+ TestMgr.check(result.getBody().getMessage(), "success result");
}
private static void testErrorCode() {
diff --git a/demo/demo-schema/pom.xml b/demo/demo-schema/pom.xml
index 4ad7eaa53..6c4ad1d43 100644
--- a/demo/demo-schema/pom.xml
+++ b/demo/demo-schema/pom.xml
@@ -61,10 +61,6 @@
<groupId>org.apache.servicecomb</groupId>
<artifactId>swagger-generator-springmvc</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.servicecomb.demo</groupId>
- <artifactId>demo-signature</artifactId>
- </dependency>
</dependencies>
<build>
<plugins>
diff --git a/demo/demo-spring-boot-discovery/demo-spring-boot-discovery-server/pom.xml b/demo/demo-spring-boot-discovery/demo-spring-boot-discovery-server/pom.xml
index 04a945a37..c44419840 100644
--- a/demo/demo-spring-boot-discovery/demo-spring-boot-discovery-server/pom.xml
+++ b/demo/demo-spring-boot-discovery/demo-spring-boot-discovery-server/pom.xml
@@ -30,12 +30,6 @@
<dependency>
<groupId>org.apache.servicecomb.demo</groupId>
<artifactId>demo-schema</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.apache.servicecomb.demo</groupId>
- <artifactId>demo-signature</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
diff --git a/demo/demo-springmvc/springmvc-client/pom.xml b/demo/demo-springmvc/springmvc-client/pom.xml
index c3c06fdf8..21be7b09b 100644
--- a/demo/demo-springmvc/springmvc-client/pom.xml
+++ b/demo/demo-springmvc/springmvc-client/pom.xml
@@ -49,6 +49,11 @@
<groupId>org.apache.servicecomb</groupId>
<artifactId>handler-fault-injection</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.servicecomb.demo</groupId>
+ <artifactId>demo-signature</artifactId>
+ </dependency>
</dependencies>
<properties>
diff --git a/demo/demo-springmvc/springmvc-server/pom.xml b/demo/demo-springmvc/springmvc-server/pom.xml
index 8e651dd5f..5a53fcf7c 100644
--- a/demo/demo-springmvc/springmvc-server/pom.xml
+++ b/demo/demo-springmvc/springmvc-server/pom.xml
@@ -50,6 +50,11 @@
<groupId>org.apache.servicecomb</groupId>
<artifactId>config-cc</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.servicecomb.demo</groupId>
+ <artifactId>demo-signature</artifactId>
+ </dependency>
</dependencies>
<properties>
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index 9ec78a84d..b2f69b82a 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -64,12 +64,6 @@
<groupId>org.apache.servicecomb.demo</groupId>
<artifactId>demo-schema</artifactId>
<version>1.1.0-SNAPSHOT</version>
- <exclusions>
- <exclusion>
- <groupId>org.apache.servicecomb.demo</groupId>
- <artifactId>demo-signature</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
<groupId>org.apache.servicecomb.tests</groupId>
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services