[
https://issues.apache.org/jira/browse/SCB-900?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16609966#comment-16609966
]
ASF GitHub Bot commented on SCB-900:
------------------------------------
liubao68 closed pull request #898: [SCB-900]Allow number parameter to be quoted
in query string
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/898
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/RestObjectMapper.java
b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestObjectMapper.java
index 327175b22..69bdb7a12 100644
---
a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestObjectMapper.java
+++
b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestObjectMapper.java
@@ -30,6 +30,7 @@
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.type.TypeFactory;
+import com.netflix.config.DynamicPropertyFactory;
import io.vertx.core.json.JsonObject;
@@ -45,6 +46,9 @@ public void serialize(JsonObject value, JsonGenerator jgen,
SerializerProvider p
private static final JavaType STRING_JAVA_TYPE =
TypeFactory.defaultInstance().constructType(String.class);
+ private boolean allowQuotedNumber = DynamicPropertyFactory.getInstance()
+ .getBooleanProperty("servicecomb.rest.parameter.allowQuotedNumber",
false).get();
+
@SuppressWarnings("deprecation")
public RestObjectMapper() {
// swagger中要求date使用ISO8601格式传递,这里与之做了功能绑定,这在cse中是没有问题的
@@ -81,6 +85,23 @@ public String convertToString(Object value) throws Exception
{
@Override
public <T> T convertValue(Object fromValue, JavaType toValueType) throws
IllegalArgumentException {
+ if (allowQuotedNumber && needProcessNumber(fromValue, toValueType)) {
+ String strValue = (String) fromValue;
+ fromValue = strValue.substring(1, fromValue.toString().length() - 1);
+ }
return super.convertValue(fromValue, toValueType);
}
+
+ private boolean needProcessNumber(Object fromValue, JavaType toValueType) {
+ if (fromValue instanceof String) {
+ String strValue = (String) fromValue;
+ if (toValueType.getRawClass() == int.class || toValueType.getRawClass()
== long.class
+ || toValueType.getRawClass() == Integer.class ||
toValueType.getRawClass() == Long.class) {
+ if (strValue.length() > 2 && strValue.startsWith("\"") &&
strValue.endsWith("\"")) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
}
diff --git a/integration-tests/it-common/src/main/resources/microservice.yaml
b/integration-tests/it-common/src/main/resources/microservice.yaml
index d4a11c79c..13942ab6e 100644
--- a/integration-tests/it-common/src/main/resources/microservice.yaml
+++ b/integration-tests/it-common/src/main/resources/microservice.yaml
@@ -21,10 +21,15 @@ APPLICATION_ID: integration-test
service_description:
name: $invalid-name-must-be-overridden
version: 1.0.0
+ environment: development
servicecomb:
service:
registry:
address: http://127.0.0.1:30100
+ instance:
+ healthCheck:
+ interval: 5
+ times: 3
request:
# 10 minute
timeout: 600000
@@ -36,6 +41,8 @@ servicecomb:
thread-count: 8
connection:
maxPoolSize: 30
+ parameter:
+ allowQuotedNumber: true
highway:
address: 0.0.0.0:0
server:
diff --git
a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDataTypePrimitive.java
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDataTypePrimitive.java
index c19cc4a76..e5b9fba24 100644
---
a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDataTypePrimitive.java
+++
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDataTypePrimitive.java
@@ -111,6 +111,30 @@ public void intQuery_jaxrs_intf() {
@Test
public void intQuery_jaxrs_rt() {
assertEquals(10, (int)
consumersJaxrs.getSCBRestTemplate().getForObject("/intQuery?input=10",
int.class));
+ assertEquals(10, (int)
consumersJaxrs.getSCBRestTemplate().getForObject("/intQuery?input=\"10\"",
int.class));
+ assertEquals(10, (int)
consumersJaxrs.getEdgeRestTemplate().getForObject("/intQuery?input=\"10\"",
int.class));
+ assertEquals(0, (int)
consumersJaxrs.getEdgeRestTemplate().getForObject("/intQuery", int.class));
+ }
+
+ @Test
+ public void integerQuery_jaxrs_rt() {
+ assertEquals(10, (int)
consumersJaxrs.getSCBRestTemplate().getForObject("/integerQuery?input=10",
int.class));
+ assertEquals(10, (int)
consumersJaxrs.getSCBRestTemplate().getForObject("/integerQuery?input=\"10\"",
int.class));
+ assertEquals(10, (int)
consumersJaxrs.getEdgeRestTemplate().getForObject("/integerQuery?input=\"10\"",
int.class));
+ }
+
+ @Test
+ public void longQuery_jaxrs_rt() {
+ assertEquals(10,
consumersJaxrs.getSCBRestTemplate().getForObject("/longQuery?input=10",
long.class).intValue());
+ assertEquals(10,
consumersJaxrs.getSCBRestTemplate().getForObject("/longQuery?input=\"10\"",
long.class).intValue());
+ assertEquals(10,
consumersJaxrs.getEdgeRestTemplate().getForObject("/longQuery?input=\"10\"",
long.class).intValue());
+ }
+
+ @Test
+ public void longWrapperQuery_jaxrs_rt() {
+ assertEquals(10,
consumersJaxrs.getSCBRestTemplate().getForObject("/longWrapperQuery?input=10",
Long.class).intValue());
+ assertEquals(10,
consumersJaxrs.getSCBRestTemplate().getForObject("/longWrapperQuery?input=\"10\"",
Long.class).intValue());
+ assertEquals(10,
consumersJaxrs.getEdgeRestTemplate().getForObject("/longWrapperQuery?input=\"10\"",
Long.class).intValue());
}
@Test
@@ -196,6 +220,14 @@ public void add_jaxrs_rt() {
assertEquals(12, (int)
consumersJaxrs.getSCBRestTemplate().getForObject("/add?a=10&b=2", int.class));
}
+ @Test
+ public void stringQuery_jaxrs_rt() {
+ assertEquals("abcdefg",
+
consumersJaxrs.getSCBRestTemplate().getForObject("/stringQuery?input=abcdefg",
String.class));
+ assertEquals("\"abcdefg\"",
+
consumersJaxrs.getSCBRestTemplate().getForObject("/stringQuery?input=\"abcdefg\"",
String.class));
+ }
+
@Test
public void intPath_springmvc_intf() {
assertEquals(10, consumersSpringmvc.getIntf().intPath(10));
diff --git
a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypeJaxrsSchema.java
b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypeJaxrsSchema.java
index 1e372cf97..ac11f5846 100644
---
a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypeJaxrsSchema.java
+++
b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypeJaxrsSchema.java
@@ -42,6 +42,12 @@ public int intQuery(@QueryParam("input") int input) {
return input;
}
+ @Path("integerQuery")
+ @GET
+ public Integer integerQuery(@QueryParam("input") Integer input) {
+ return input;
+ }
+
@Path("intHeader")
@GET
public int intHeader(@HeaderParam("input") int input) {
@@ -71,4 +77,22 @@ public int intBody(int input) {
public int add(@QueryParam("a") int a, @QueryParam("b") int b) {
return a + b;
}
+
+ @Path("longQuery")
+ @GET
+ public long longQuery(@QueryParam("input") long input) {
+ return input;
+ }
+
+ @Path("longWrapperQuery")
+ @GET
+ public Long longWrapperQuery(@QueryParam("input") Long input) {
+ return input;
+ }
+
+ @Path("stringQuery")
+ @GET
+ public String stringQuery(@QueryParam("input") String input) {
+ return input;
+ }
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Allow number parameter to be quoted in query string
> ---------------------------------------------------
>
> Key: SCB-900
> URL: https://issues.apache.org/jira/browse/SCB-900
> Project: Apache ServiceComb
> Issue Type: New Feature
> Components: Java-Chassis
> Reporter: liubao
> Assignee: liubao
> Priority: Major
>
> Allow number query parameters parsed like ?key="100".
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)