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

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

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));
   }
 }