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 2019/06/20 03:50:15 UTC

[servicecomb-java-chassis] branch master updated (80a13dd -> 6d5d662)

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/servicecomb-java-chassis.git.


    from 80a13dd  Added  Export Notices in the README.md
     new 4083f5b  [SCB-1305] CseAysncRestTemplate is not set headers
     new 6d5d662  [SCB-1305] add IT and ITSCBAsyncRestTemplate

The 2 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:
 .../src/main/java/org/apache/servicecomb/it/Consumers.java |  9 +++++++++
 ...lientHttpRequest.java => ITAsyncClientHttpRequest.java} |  7 ++++---
 ...stFactory.java => ITAsyncClientHttpRequestFactory.java} | 13 +++++++------
 ...{ITSCBRestTemplate.java => ITSCBAsyncRestTemplate.java} | 11 ++++++-----
 .../apache/servicecomb/it/testcase/TestDefaultValue.java   | 14 ++++++++++++++
 .../provider/springmvc/reference/CseClientHttpRequest.java |  6 ++++++
 .../reference/async/CseAsyncClientHttpRequest.java         |  2 +-
 .../springmvc/reference/async/CseAsyncRequestCallback.java |  1 +
 .../springmvc/reference/TestCseClientHttpRequest.java      |  8 +++++++-
 9 files changed, 55 insertions(+), 16 deletions(-)
 copy integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/extend/engine/{ITClientHttpRequest.java => ITAsyncClientHttpRequest.java} (85%)
 copy integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/extend/engine/{ITClientHttpRequestFactory.java => ITAsyncClientHttpRequestFactory.java} (70%)
 copy integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/extend/engine/{ITSCBRestTemplate.java => ITSCBAsyncRestTemplate.java} (89%)


[servicecomb-java-chassis] 01/02: [SCB-1305] CseAysncRestTemplate is not set headers

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/servicecomb-java-chassis.git

commit 4083f5b47dc3de66d474c1eb2a06f7ceb18a4f89
Author: wangsheng <wa...@huawei.com>
AuthorDate: Fri May 31 10:49:05 2019 +0800

    [SCB-1305] CseAysncRestTemplate is not set headers
---
 .../provider/springmvc/reference/CseClientHttpRequest.java        | 6 ++++++
 .../springmvc/reference/async/CseAsyncRequestCallback.java        | 1 +
 .../provider/springmvc/reference/TestCseClientHttpRequest.java    | 8 +++++++-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/CseClientHttpRequest.java b/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/CseClientHttpRequest.java
index 1191391..0361206 100644
--- a/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/CseClientHttpRequest.java
+++ b/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/CseClientHttpRequest.java
@@ -112,6 +112,12 @@ public class CseClientHttpRequest implements ClientHttpRequest {
     this.requestBody = requestBody;
   }
 
+  public void setHttpHeaders(HttpHeaders headers) {
+    if (headers != null) {
+      this.httpHeaders = headers;
+    }
+  }
+
   @Override
   public HttpMethod getMethod() {
     return method;
diff --git a/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncRequestCallback.java b/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncRequestCallback.java
index 1ca4b4c..e434bd0 100644
--- a/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncRequestCallback.java
+++ b/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncRequestCallback.java
@@ -34,6 +34,7 @@ public class CseAsyncRequestCallback<T> implements AsyncRequestCallback {
     CseAsyncClientHttpRequest cseAsyncClientHttpRequest = (CseAsyncClientHttpRequest) request;
     if (requestBody != null) {
       cseAsyncClientHttpRequest.setRequestBody(requestBody.getBody());
+      cseAsyncClientHttpRequest.setHttpHeaders(requestBody.getHeaders());
     }
 
     if (!CseHttpEntity.class.isInstance(requestBody)) {
diff --git a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCseClientHttpRequest.java b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCseClientHttpRequest.java
index aadf55f..51dbba8 100644
--- a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCseClientHttpRequest.java
+++ b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCseClientHttpRequest.java
@@ -32,8 +32,10 @@ import org.apache.servicecomb.swagger.invocation.Response;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
 import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 
@@ -53,7 +55,7 @@ public class TestCseClientHttpRequest {
   @RequestMapping(path = "SpringmvcImpl")
   static class SpringmvcImpl {
     @RequestMapping(path = "/bytes", method = RequestMethod.POST)
-    public byte[] bytes(@RequestBody byte[] input) {
+    public byte[] bytes(@RequestBody byte[] input, @RequestHeader String token) {
       input[0] = (byte) (input[0] + 1);
       return input;
     }
@@ -84,10 +86,14 @@ public class TestCseClientHttpRequest {
           }
         };
     byte[] body = "abc".getBytes();
+    HttpHeaders headers = new HttpHeaders();
+    headers.add("token", "123");
     client.setRequestBody(body);
+    client.setHttpHeaders(headers);
 
     client.execute();
 
     Assert.assertArrayEquals(body, holder.value.getSwaggerArgument(0));
+    Assert.assertEquals("123", holder.value.getSwaggerArgument(1));
   }
 }


[servicecomb-java-chassis] 02/02: [SCB-1305] add IT and ITSCBAsyncRestTemplate

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/servicecomb-java-chassis.git

commit 6d5d6622791ee05c21afa152f580a9c1ac7f78fc
Author: wangsheng <wa...@huawei.com>
AuthorDate: Wed Jun 19 10:08:43 2019 +0800

    [SCB-1305] add IT and ITSCBAsyncRestTemplate
---
 .../java/org/apache/servicecomb/it/Consumers.java  |  9 +++
 .../it/extend/engine/ITAsyncClientHttpRequest.java | 44 +++++++++++++
 .../engine/ITAsyncClientHttpRequestFactory.java    | 38 +++++++++++
 .../it/extend/engine/ITSCBAsyncRestTemplate.java   | 77 ++++++++++++++++++++++
 .../servicecomb/it/testcase/TestDefaultValue.java  | 14 ++++
 .../reference/async/CseAsyncClientHttpRequest.java |  2 +-
 6 files changed, 183 insertions(+), 1 deletion(-)

diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/Consumers.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/Consumers.java
index ea24dad..8a56980 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/Consumers.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/Consumers.java
@@ -18,8 +18,10 @@ package org.apache.servicecomb.it;
 
 import org.apache.servicecomb.it.extend.engine.GateRestTemplate;
 import org.apache.servicecomb.it.extend.engine.ITInvoker;
+import org.apache.servicecomb.it.extend.engine.ITSCBAsyncRestTemplate;
 import org.apache.servicecomb.it.extend.engine.ITSCBRestTemplate;
 import org.apache.servicecomb.it.junit.ITJUnitUtils;
+import org.apache.servicecomb.provider.springmvc.reference.async.CseAsyncRestTemplate;
 import org.springframework.web.client.RestTemplate;
 
 public class Consumers<INTF> {
@@ -39,6 +41,8 @@ public class Consumers<INTF> {
 
   private String transport;
 
+  private CseAsyncRestTemplate cseAsyncRestTemplate;
+
   public Consumers(String schemaId, Class<INTF> intfCls) {
     this.schemaId = schemaId;
     this.intfCls = intfCls;
@@ -51,6 +55,7 @@ public class Consumers<INTF> {
     scbRestTemplate = new ITSCBRestTemplate(schemaId).init();
     edgeRestTemplate = GateRestTemplate.createEdgeRestTemplate(schemaId).init();
     zuulRestTemplate = null;// GateRestTemplate.createZuulRestTemplate(schemaId).init();
+    this.cseAsyncRestTemplate = new ITSCBAsyncRestTemplate(schemaId).init();
   }
 
   public String getSchemaId() {
@@ -76,4 +81,8 @@ public class Consumers<INTF> {
   public String getTransport() {
     return transport;
   }
+
+  public CseAsyncRestTemplate getCseAsyncRestTemplate() {
+    return cseAsyncRestTemplate;
+  }
 }
\ No newline at end of file
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/extend/engine/ITAsyncClientHttpRequest.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/extend/engine/ITAsyncClientHttpRequest.java
new file mode 100644
index 0000000..5989700
--- /dev/null
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/extend/engine/ITAsyncClientHttpRequest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.it.extend.engine;
+
+import java.net.URI;
+
+import org.apache.servicecomb.core.CseContext;
+import org.apache.servicecomb.core.provider.consumer.ReferenceConfig;
+import org.apache.servicecomb.provider.springmvc.reference.async.CseAsyncClientHttpRequest;
+import org.springframework.http.HttpMethod;
+
+public class ITAsyncClientHttpRequest extends CseAsyncClientHttpRequest {
+  private String transport;
+
+  public ITAsyncClientHttpRequest(URI uri, HttpMethod method, String transport) {
+    super(uri, method);
+    this.transport = transport;
+  }
+
+  @Override
+  protected ReferenceConfig findReferenceConfig(String microserviceName) {
+    ReferenceConfig referenceConfig = CseContext.getInstance().getConsumerProviderManager()
+        .createReferenceConfig(microserviceName);
+    if (transport != null) {
+      referenceConfig.setTransport(transport);
+    }
+    return referenceConfig;
+  }
+}
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/extend/engine/ITAsyncClientHttpRequestFactory.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/extend/engine/ITAsyncClientHttpRequestFactory.java
new file mode 100644
index 0000000..53053b1
--- /dev/null
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/extend/engine/ITAsyncClientHttpRequestFactory.java
@@ -0,0 +1,38 @@
+/*
+ * 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.it.extend.engine;
+
+import java.net.URI;
+
+import org.apache.servicecomb.it.junit.ITJUnitUtils;
+import org.apache.servicecomb.provider.springmvc.reference.async.CseAsyncClientHttpRequestFactory;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.client.AsyncClientHttpRequest;
+
+public class ITAsyncClientHttpRequestFactory extends CseAsyncClientHttpRequestFactory {
+  private String transport;
+
+  public ITAsyncClientHttpRequestFactory() {
+    this.transport = ITJUnitUtils.getTransport();
+  }
+
+  @Override
+  public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) {
+    return new ITAsyncClientHttpRequest(uri, httpMethod, transport);
+  }
+}
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/extend/engine/ITSCBAsyncRestTemplate.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/extend/engine/ITSCBAsyncRestTemplate.java
new file mode 100644
index 0000000..9a7dfb2
--- /dev/null
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/extend/engine/ITSCBAsyncRestTemplate.java
@@ -0,0 +1,77 @@
+/*
+ * 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.it.extend.engine;
+
+import java.util.Optional;
+
+import org.apache.servicecomb.core.definition.MicroserviceVersionMeta;
+import org.apache.servicecomb.core.definition.SchemaMeta;
+import org.apache.servicecomb.it.junit.ITJUnitUtils;
+import org.apache.servicecomb.provider.springmvc.reference.async.CseAsyncRestTemplate;
+import org.apache.servicecomb.serviceregistry.RegistryUtils;
+import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersionRule;
+import org.apache.servicecomb.serviceregistry.definition.DefinitionConst;
+
+public class ITSCBAsyncRestTemplate extends CseAsyncRestTemplate {
+  private String urlPrefix;
+
+  private String schemaId;
+
+  private String basePath;
+
+  private MicroserviceInstance instance;
+
+  public ITSCBAsyncRestTemplate(String schemaId) {
+    this.schemaId = schemaId;
+  }
+
+  public ITSCBAsyncRestTemplate init() {
+    String producerName = ITJUnitUtils.getProducerName();
+    MicroserviceVersionRule microserviceVersionRule = RegistryUtils.getServiceRegistry().getAppManager()
+        .getOrCreateMicroserviceVersionRule(RegistryUtils.getAppId(), producerName,
+            DefinitionConst.VERSION_RULE_ALL);
+    MicroserviceVersionMeta microserviceVersionMeta = microserviceVersionRule.getLatestMicroserviceVersion();
+    SchemaMeta schemaMeta = microserviceVersionMeta.getMicroserviceMeta().ensureFindSchemaMeta(schemaId);
+    basePath = schemaMeta.getSwagger().getBasePath();
+    urlPrefix = String.format("cse://%s%s", producerName, basePath);
+    instance = RegistryUtils.getServiceRegistry().getAppManager()
+        .getOrCreateMicroserviceManager(RegistryUtils.getAppId())
+        .getOrCreateMicroserviceVersions(producerName).getPulledInstances().get(0);
+
+    setUriTemplateHandler(new ITUriTemplateHandler(urlPrefix));
+    setAsyncRequestFactory(new ITAsyncClientHttpRequestFactory());
+
+    return this;
+  }
+
+  public String getBasePath() {
+    return basePath;
+  }
+
+  public String getUrlPrefix() {
+    return urlPrefix;
+  }
+
+  public String getAddress(String transport) {
+    Optional<String> addressHolder = instance.getEndpoints().stream()
+        .filter(endpoint -> endpoint.startsWith(transport))
+        .findFirst();
+    return addressHolder.get();
+  }
+}
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDefaultValue.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDefaultValue.java
index d0b8039..1f39a6f 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDefaultValue.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDefaultValue.java
@@ -17,10 +17,14 @@
 package org.apache.servicecomb.it.testcase;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
 
 import org.apache.servicecomb.it.Consumers;
 import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
 import org.junit.Test;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
 
 public class TestDefaultValue {
   interface DefaultValueIntf {
@@ -514,4 +518,14 @@ public class TestDefaultValue {
     assertEquals(defaultFloat,
         consumersSpringmvc.getSCBRestTemplate().postForObject("/floatFormRequire", null, float.class), 0.0f);
   }
+
+  @Test
+  public void stringHeader_springmvc_cart() {
+    HttpHeaders headers = new HttpHeaders();
+    headers.add("input", "setHeader");
+    HttpEntity<String> requestEntity = new HttpEntity<String>(null, headers);
+    assertNotEquals(defaultStr,
+        consumersSpringmvc.getCseAsyncRestTemplate()
+            .exchange("/stringHeader", HttpMethod.GET, requestEntity, String.class));
+  }
 }
diff --git a/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequest.java b/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequest.java
index d66a0c6..3512c87 100644
--- a/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequest.java
+++ b/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequest.java
@@ -40,7 +40,7 @@ public class CseAsyncClientHttpRequest extends CseClientHttpRequest implements A
   CseAsyncClientHttpRequest() {
   }
 
-  CseAsyncClientHttpRequest(URI uri, HttpMethod method) {
+  protected CseAsyncClientHttpRequest(URI uri, HttpMethod method) {
     this.setUri(uri);
     this.setMethod(method);
   }