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 2020/01/16 11:39:41 UTC

[servicecomb-java-chassis] 02/02: [SCB-1728]support response headers in Response type

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 e3d0be4a1d1d69b797aad0480376346e07792ff8
Author: liubao <bi...@qq.com>
AuthorDate: Thu Jan 16 14:37:59 2020 +0800

    [SCB-1728]support response headers in Response type
---
 .../protobuf/definition/RequestRootDeserializer.java   |  6 +++---
 .../client/CodeFirstRestTemplateSpringmvc.java         |  2 +-
 .../servicecomb/demo/springmvc/client/TestObject.java  |  5 ++---
 .../demo/springmvc/client/TestResponse.java            |  7 +++----
 .../demo/springmvc/client/TestRestTemplate.java        |  3 +--
 .../protobuf/internal/schema/any/AnyEntrySchema.java   |  1 +
 .../schema/deserializer/DeserializerSchemaManager.java |  1 +
 .../servicecomb/transport/highway/HighwayCodec.java    |  4 ----
 .../transport/highway/message/ResponseHeader.java      |  1 -
 .../src/main/resources/LoginRequest.proto              |  6 +++---
 .../src/main/resources/LoginResponse.proto             |  6 +++---
 .../src/main/resources/RequestHeader.proto             | 12 ++++++------
 .../src/main/resources/ResponseHeader.proto            | 18 ++++++++++++------
 13 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/definition/RequestRootDeserializer.java b/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/definition/RequestRootDeserializer.java
index c8b70f4..00f2ba9 100644
--- a/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/definition/RequestRootDeserializer.java
+++ b/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/definition/RequestRootDeserializer.java
@@ -39,14 +39,14 @@ public class RequestRootDeserializer<T> {
   @SuppressWarnings("unchecked")
   public Map<String, Object> deserialize(byte[] bytes) throws IOException {
     if (!wrapArgument) {
-      if (parameterName == null) {
-        return null;
-      }
       Map<String, Object> result = new HashMap<>(1);
       Object obj = rootDeserializer.deserialize(bytes);
       if (obj instanceof PropertyWrapper) {
         obj = ((PropertyWrapper) obj).getValue();
       }
+      if (parameterName == null) {
+        return result;
+      }
       result.put(parameterName, obj);
       return result;
     } else {
diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/CodeFirstRestTemplateSpringmvc.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/CodeFirstRestTemplateSpringmvc.java
index 6c3c18c..bc4998d 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/CodeFirstRestTemplateSpringmvc.java
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/CodeFirstRestTemplateSpringmvc.java
@@ -112,7 +112,7 @@ public class CodeFirstRestTemplateSpringmvc extends CodeFirstRestTemplate {
     testRestTemplate.runAllTest();
     testBizkeeper.runAllTest();
     // TODO : WEAK not supported now in HIGHWAY
-//    testResponseEntity("springmvc", template, cseUrlPrefix);
+    testResponseEntity("springmvc", template, cseUrlPrefix);
 //    testCodeFirstTestForm(template, cseUrlPrefix);
 //    testFallback(template, cseUrlPrefix);
 
diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestObject.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestObject.java
index fe36b6b..0bbf13e 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestObject.java
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestObject.java
@@ -55,10 +55,9 @@ public class TestObject {
   }
 
   public void runAllTransport() {
-    // TODO : WEAK not supported now in HIGHWAY
     testObject();
-//    testListObject();
-//    testHolderObject();
+    testListObject();
+    testHolderObject();
   }
 
   @SuppressWarnings("unchecked")
diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestResponse.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestResponse.java
index eb5968d..7c54eba 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestResponse.java
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestResponse.java
@@ -54,10 +54,9 @@ public class TestResponse {
   public void runAllTransport() {
     testvoidResponse();
     testVoidResponse();
-    // TODO : WEAK not supported now in HIGHWAY
-    // checkQueryObject();
-    //  testCseResponse();
-    // testResponseEntity();
+    checkQueryObject();
+    testCseResponse();
+    testResponseEntity();
   }
 
   private void testCseResponse() {
diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestRestTemplate.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestRestTemplate.java
index 0e67baa..1652e22 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestRestTemplate.java
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestRestTemplate.java
@@ -34,8 +34,7 @@ public class TestRestTemplate {
     testvoidResponse();
     testVoidResponse();
     checkAllVoidTestResult();
-    // TODO : WEAK not supported now in HIGHWAY
-    //checkQueryObject();
+    checkQueryObject();
   }
 
   public void runRest() {
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/any/AnyEntrySchema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/any/AnyEntrySchema.java
index cd89bf9..bcc6559 100644
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/any/AnyEntrySchema.java
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/any/AnyEntrySchema.java
@@ -68,6 +68,7 @@ public class AnyEntrySchema implements SchemaEx<Object> {
   }
 
   @Override
+  @SuppressWarnings({"rawtypes", "unchecked"})
   public void mergeFrom(InputEx input, Object message) throws IOException {
     input.readFieldNumber();
     String typeUrl = input.readString();
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/DeserializerSchemaManager.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/DeserializerSchemaManager.java
index 8408c54..9965a62 100644
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/DeserializerSchemaManager.java
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/DeserializerSchemaManager.java
@@ -99,6 +99,7 @@ public class DeserializerSchemaManager extends SchemaManager {
     return new RootDeserializer<>(messageSchema);
   }
 
+  @SuppressWarnings({"rawtypes", "unchecked"})
   public <T> RootDeserializer<T> createRootDeserializer(Message message, Type type) {
     if (ProtoUtils.isAnyMessage(message)) {
       SchemaEx<Object> messageSchema = new AnyEntrySchema(protoMapper, type);
diff --git a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayCodec.java b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayCodec.java
index fe6e026..9278e56 100644
--- a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayCodec.java
+++ b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayCodec.java
@@ -72,10 +72,6 @@ public final class HighwayCodec {
   private static Map<String, Object> swaggerArgumentsToInvocationArguments(Invocation invocation,
       OperationMeta operationMeta,
       Map<String, Object> swaggerArguments) {
-    if (swaggerArguments == null || swaggerArguments.isEmpty()) {
-      // void types represented by null
-      return swaggerArguments;
-    }
     if (operationMeta.getSwaggerProducerOperation() != null && !invocation.isEdge()) {
       return operationMeta.getSwaggerProducerOperation().getArgumentsMapper()
           .swaggerArgumentToInvocationArguments(invocation, swaggerArguments);
diff --git a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/message/ResponseHeader.java b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/message/ResponseHeader.java
index 01f7697..262ac71 100644
--- a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/message/ResponseHeader.java
+++ b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/message/ResponseHeader.java
@@ -54,7 +54,6 @@ public class ResponseHeader {
 
   private Map<String, String> context;
 
-  // TODO : WEAK map headers
   private Headers headers = new Headers();
 
   public int getFlags() {
diff --git a/transports/transport-highway/src/main/resources/LoginRequest.proto b/transports/transport-highway/src/main/resources/LoginRequest.proto
index 97d0f20..cc402fb 100644
--- a/transports/transport-highway/src/main/resources/LoginRequest.proto
+++ b/transports/transport-highway/src/main/resources/LoginRequest.proto
@@ -15,10 +15,10 @@
   limitations under the License.
  */
 
-syntax = "proto2";
+syntax = "proto3";
 package org.apache.servicecomb.transport.highway.message;
 
 message LoginRequest {
-  required string protocol = 1;
-  required string zipName = 2;
+  string protocol = 1;
+  string zipName = 2;
 }
diff --git a/transports/transport-highway/src/main/resources/LoginResponse.proto b/transports/transport-highway/src/main/resources/LoginResponse.proto
index 79933a9..2931e79 100644
--- a/transports/transport-highway/src/main/resources/LoginResponse.proto
+++ b/transports/transport-highway/src/main/resources/LoginResponse.proto
@@ -15,10 +15,10 @@
   limitations under the License.
  */
 
-syntax = "proto2";
+syntax = "proto3";
 package org.apache.servicecomb.transport.highway.message;
 
 message LoginResponse {
-  required string protocol = 1;
-  required string zipName = 2;
+  string protocol = 1;
+  string zipName = 2;
 }
diff --git a/transports/transport-highway/src/main/resources/RequestHeader.proto b/transports/transport-highway/src/main/resources/RequestHeader.proto
index 6cb1d9f..1ccf235 100644
--- a/transports/transport-highway/src/main/resources/RequestHeader.proto
+++ b/transports/transport-highway/src/main/resources/RequestHeader.proto
@@ -15,14 +15,14 @@
   limitations under the License.
  */
 
-syntax = "proto2";
+syntax = "proto3";
 package org.apache.servicecomb.transport.highway.message;
 
 message RequestHeader {
-  required string destMicroservice = 1;
-  required int32 msgType = 2;
-  required int32 flags = 3;
-  required string schemaId = 4;
-  required string operationName = 5;
+  string destMicroservice = 1;
+  int32 msgType = 2;
+  int32 flags = 3;
+  string schemaId = 4;
+  string operationName = 5;
   map<string,string> context = 6;
 }
diff --git a/transports/transport-highway/src/main/resources/ResponseHeader.proto b/transports/transport-highway/src/main/resources/ResponseHeader.proto
index 0210710..11b89af 100644
--- a/transports/transport-highway/src/main/resources/ResponseHeader.proto
+++ b/transports/transport-highway/src/main/resources/ResponseHeader.proto
@@ -15,17 +15,23 @@
   limitations under the License.
  */
 
-syntax = "proto2";
+syntax = "proto3";
+import "google/protobuf/any.proto";
 package org.apache.servicecomb.transport.highway.message;
 
 message ResponseHeader {
-  required int32 statusCode = 1;
-  required string reason = 2;
-  map<string,string> context = 3;
-  // TODO : map retsponse headers
-  // required Headers headers = 4;
+  int32 flags = 1;
+  int32 statusCode = 2;
+  string reasonPhrase = 3;
+  map<string,string> context = 4;
+  Headers headers = 5;
 }
 
 message Headers {
+  map<string,ListGoogle_protobuf_Any> headerMap = 1;
+}
 
+//@WrapProperty
+message ListGoogle_protobuf_Any {
+  repeated google.protobuf.Any value = 1;
 }
\ No newline at end of file