jeho0815 closed pull request #537: SCB-314 support custom rest transport server
compress and max header ?
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/537
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/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
index 08eec9beb..58baac15d 100644
---
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
+++
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
@@ -114,6 +114,13 @@ public static void run() {
TestMgr.check(true,
resultMap.get("RequestQueueRelated").contains("springmvc.codeFirst.saySomething"));
TestMgr.check(true,
resultMap.get("RequestQueueRelated").contains("springmvc.controller.sayHi"));
+ ResponseEntity<String> entityCompress =
+ restTemplate.getForEntity(prefix +
"/codeFirstSpringmvc/sayhi/compressed/{name}/v2", String.class, "Test");
+ TestMgr.check(
+ "Test sayhi compressed:This is a big text,This is a big text,This is
a big text,This is a big text,This is a big text,This is a big text,This is a
big text,This is a big text,This is a big text,This is a big text,This is a big
text,This is a big text,This is a big text,This is a big text,This is a big
text,This is a big text,This is a big text,This is a big text,This is a big
text,This is a big text,This is a big text,This is a big text,This is a big
text,This is a big text,This is a big text,This is a big text,This is a big
text,This is a big text,This is a big text,This is a big text,This is a big
text,This is a big text,This is a big text,This is a big text,This is a big
text,This is a big text,This is a big text,This is a big text,This is a big
text,This is a big text,This is a big text,This is a big text,This is a big
text,This is a big text,This is a big text,This is a big text,This is a big
text,This is a big text!",
+ entityCompress.getBody());
+ // this just test length value return correctly, not realy
Content-Length returned by the server, the value has been rewrited by
transport-client
+ TestMgr.check("936", entityCompress.getHeaders().get("Content-Length"));
} catch (Exception e) {
TestMgr.check("true", "false");
}
@@ -126,8 +133,11 @@ public static void run() {
.check(true,
metric.getInstanceMetric().getSystemMetric().getHeapUsed() != 0);
TestMgr.check(true, metric.getProducerMetrics().size() > 0);
TestMgr.check(true,
-
metric.getProducerMetrics().get("springmvc.codeFirst.saySomething").getProducerCall()
- .getTotalValue(MetricsDimension.DIMENSION_STATUS,
MetricsDimension.DIMENSION_STATUS_ALL).getValue() > 0);
+ metric.getProducerMetrics()
+ .get("springmvc.codeFirst.saySomething")
+ .getProducerCall()
+ .getTotalValue(MetricsDimension.DIMENSION_STATUS,
MetricsDimension.DIMENSION_STATUS_ALL)
+ .getValue() > 0);
} catch (Exception e) {
TestMgr.check("true", "false");
}
diff --git
a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java
index 1251f61ec..854e4e2bf 100644
---
a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java
+++
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java
@@ -240,6 +240,18 @@ public String sayHi2(@PathVariable(name = "name") String
name) {
return name + " sayhi 2";
}
+ @RequestMapping(path = "/sayhi/compressed/{name}/v2", method =
RequestMethod.GET)
+ public String sayHiForCompressed(@PathVariable(name = "name") String name) {
+ String bigText =
+ "This is a big text,This is a big text,This is a big text,This is a
big text,This is a big text,This is a big text,This is a big text,This is a big
text,"
+ + "This is a big text,This is a big text,This is a big text,This
is a big text,This is a big text,This is a big text,This is a big text,This is
a big text,"
+ + "This is a big text,This is a big text,This is a big text,This
is a big text,This is a big text,This is a big text,This is a big text,This is
a big text,"
+ + "This is a big text,This is a big text,This is a big text,This
is a big text,This is a big text,This is a big text,This is a big text,This is
a big text,"
+ + "This is a big text,This is a big text,This is a big text,This
is a big text,This is a big text,This is a big text,This is a big text,This is
a big text,"
+ + "This is a big text,This is a big text,This is a big text,This
is a big text,This is a big text,This is a big text,This is a big text,This is
a big text!";
+ return name + " sayhi compressed:" + bigText;
+ }
+
@RequestMapping(path = "/istrue", method = RequestMethod.GET)
public boolean isTrue() {
return true;
diff --git
a/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
b/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
index d7a69d826..34b582a8e 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
+++ b/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
@@ -46,6 +46,8 @@ cse:
autodiscovery: true
rest:
address: 0.0.0.0:8080?sslEnabled=true
+ server:
+ compression: true
highway:
address: 0.0.0.0:7070?sslEnabled=true
handler:
diff --git
a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java
b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java
index d011e8a83..73eab866a 100644
---
a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java
+++
b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java
@@ -124,6 +124,8 @@ private HttpServerOptions createDefaultHttpServerOptions() {
HttpServerOptions serverOptions = new HttpServerOptions();
serverOptions.setUsePooledBuffers(true);
serverOptions.setIdleTimeout(TransportConfig.getConnectionIdleTimeoutInSeconds());
+ serverOptions.setCompressionSupported(TransportConfig.getCompressed());
+ serverOptions.setMaxHeaderSize(TransportConfig.getMaxHeaderSize());
if (endpointObject.isSslEnabled()) {
SSLOptionFactory factory =
diff --git
a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/TransportConfig.java
b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/TransportConfig.java
index e723ef093..75bcc98af 100644
---
a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/TransportConfig.java
+++
b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/TransportConfig.java
@@ -21,6 +21,8 @@
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;
+import io.vertx.core.http.HttpServerOptions;
+
public final class TransportConfig {
private TransportConfig() {
}
@@ -42,4 +44,16 @@ public static int getConnectionIdleTimeoutInSeconds() {
.getIntProperty("cse.rest.server.connection.idleTimeoutInSeconds", 60)
.get();
}
+
+ public static boolean getCompressed() {
+ return DynamicPropertyFactory.getInstance()
+ .getBooleanProperty("cse.rest.server.compression", false)
+ .get();
+ }
+
+ public static int getMaxHeaderSize() {
+ return DynamicPropertyFactory.getInstance()
+ .getIntProperty("cse.rest.server.maxHeaderSize",
HttpServerOptions.DEFAULT_MAX_HEADER_SIZE)
+ .get();
+ }
}
diff --git
a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestTransportConfig.java
b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestTransportConfig.java
index 514fb1398..e63dcd5b8 100644
---
a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestTransportConfig.java
+++
b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestTransportConfig.java
@@ -63,4 +63,14 @@ public void testGetThreadCountNormal() {
Assert.assertEquals(10, TransportConfig.getThreadCount());
config.clearProperty("cse.rest.server.thread-count");
}
+
+ @Test
+ public void testGetCompressedAndHeaderSize() {
+ config.addProperty("cse.rest.server.compression", true);
+ Assert.assertEquals(true, TransportConfig.getCompressed());
+ config.addProperty("cse.rest.server.maxHeaderSize", 2048);
+ Assert.assertEquals(2048, TransportConfig.getMaxHeaderSize());
+ config.clearProperty("cse.rest.server.compression");
+ config.clearProperty("cse.rest.server.maxHeaderSize");
+ }
}
----------------------------------------------------------------
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]
With regards,
Apache Git Services