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/05/23 02:50:22 UTC

[servicecomb-java-chassis] branch master updated: [SCB-1924] invocation context provide transport context

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


The following commit(s) were added to refs/heads/master by this push:
     new 955c68a  [SCB-1924] invocation context provide transport context
955c68a is described below

commit 955c68ad77ee9b2ef69c436593797043c2a6e432
Author: wujimin <wu...@huawei.com>
AuthorDate: Wed May 20 15:27:45 2020 +0800

    [SCB-1924] invocation context provide transport context
---
 ...stInvocation.java => HttpTransportContext.java} | 26 ++++++++----
 .../common/rest/VertxHttpTransportContext.java     | 48 ++++++++++++++++++++++
 .../common/rest/VertxRestInvocation.java           |  9 +++-
 .../org/apache/servicecomb/core/Invocation.java    |  2 +
 .../org/apache/servicecomb/it/ConsumerMain.java    | 13 ++++++
 .../apache/servicecomb/it/junit/ITJUnitUtils.java  |  4 ++
 .../it/testcase/TestChangeTransport.java           | 14 +++----
 .../it/testcase/TestTransportContext.java          | 23 +++++++----
 .../it/schema/TransportContextSchema.java          | 21 +++++-----
 integration-tests/pom.xml                          |  6 +++
 .../invocation/context/InvocationContext.java      | 11 +++++
 .../invocation/context/TransportContext.java       | 16 +++-----
 .../invocation/context/VertxTransportContext.java  | 15 ++-----
 .../transport/highway/HighwayServerInvoke.java     |  1 +
 .../transport/highway/HighwayTransportContext.java | 21 ++++++----
 .../servlet/RestServletProducerInvocation.java     |  8 ++++
 16 files changed, 173 insertions(+), 65 deletions(-)

diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/HttpTransportContext.java
similarity index 55%
copy from common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java
copy to common/common-rest/src/main/java/org/apache/servicecomb/common/rest/HttpTransportContext.java
index 2cd5f31..4e048a8 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/HttpTransportContext.java
@@ -14,17 +14,27 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.servicecomb.common.rest;
 
-import org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest;
+import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
+import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
+import org.apache.servicecomb.swagger.invocation.context.TransportContext;
+
+public class HttpTransportContext implements TransportContext {
+  private HttpServletRequestEx requestEx;
+
+  private HttpServletResponseEx responseEx;
 
-public class VertxRestInvocation extends RestProducerInvocation {
-  @Override
-  protected void createInvocation() {
-    super.createInvocation();
+  public HttpTransportContext(HttpServletRequestEx requestEx, HttpServletResponseEx responseEx) {
+    this.requestEx = requestEx;
+    this.responseEx = responseEx;
+  }
+
+  public HttpServletRequestEx getRequestEx() {
+    return requestEx;
+  }
 
-    ((VertxServerRequestToHttpServletRequest) this.requestEx).getContext()
-        .put(RestConst.REST_INVOCATION_CONTEXT, this.invocation);
+  public HttpServletResponseEx getResponseEx() {
+    return responseEx;
   }
 }
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxHttpTransportContext.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxHttpTransportContext.java
new file mode 100644
index 0000000..5e2b01b
--- /dev/null
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxHttpTransportContext.java
@@ -0,0 +1,48 @@
+/*
+ * 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.common.rest;
+
+import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
+import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
+import org.apache.servicecomb.swagger.invocation.context.VertxTransportContext;
+
+import io.vertx.core.Context;
+import io.vertx.core.Vertx;
+import io.vertx.ext.web.RoutingContext;
+
+public class VertxHttpTransportContext extends HttpTransportContext implements VertxTransportContext {
+  private RoutingContext routingContext;
+
+  private Context vertxContext;
+
+  public VertxHttpTransportContext(RoutingContext routingContext, HttpServletRequestEx requestEx,
+      HttpServletResponseEx responseEx) {
+    super(requestEx, responseEx);
+
+    this.routingContext = routingContext;
+    this.vertxContext = Vertx.currentContext();
+  }
+
+  public RoutingContext getRoutingContext() {
+    return routingContext;
+  }
+
+  @Override
+  public Context getVertxContext() {
+    return vertxContext;
+  }
+}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java
index 2cd5f31..b6e5534 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java
@@ -19,12 +19,17 @@ package org.apache.servicecomb.common.rest;
 
 import org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest;
 
+import io.vertx.ext.web.RoutingContext;
+
 public class VertxRestInvocation extends RestProducerInvocation {
   @Override
   protected void createInvocation() {
     super.createInvocation();
 
-    ((VertxServerRequestToHttpServletRequest) this.requestEx).getContext()
-        .put(RestConst.REST_INVOCATION_CONTEXT, this.invocation);
+    RoutingContext routingContext = ((VertxServerRequestToHttpServletRequest) this.requestEx).getContext();
+    VertxHttpTransportContext transportContext = new VertxHttpTransportContext(routingContext, requestEx, responseEx);
+    
+    invocation.setTransportContext(transportContext);
+    routingContext.put(RestConst.REST_INVOCATION_CONTEXT, this.invocation);
   }
 }
diff --git a/core/src/main/java/org/apache/servicecomb/core/Invocation.java b/core/src/main/java/org/apache/servicecomb/core/Invocation.java
index 38dbeb6..e390e18 100644
--- a/core/src/main/java/org/apache/servicecomb/core/Invocation.java
+++ b/core/src/main/java/org/apache/servicecomb/core/Invocation.java
@@ -336,6 +336,7 @@ public class Invocation extends SwaggerInvocation {
     this.invocationRuntimeType.setSuccessResponseType(javaType);
   }
 
+  @Override
   public String getInvocationQualifiedName() {
     return invocationType.name() + " " + getRealTransportName() + " "
         + getOperationMeta().getMicroserviceQualifiedName();
@@ -382,6 +383,7 @@ public class Invocation extends SwaggerInvocation {
 
   public void onStart(HttpServletRequestEx requestEx, long start) {
     this.requestEx = requestEx;
+
     onStart(start);
   }
 
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
index eefb630..ff0bd9d 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
@@ -16,6 +16,8 @@
  */
 package org.apache.servicecomb.it;
 
+import org.apache.servicecomb.common.rest.HttpTransportContext;
+import org.apache.servicecomb.common.rest.VertxHttpTransportContext;
 import org.apache.servicecomb.core.SCBEngine;
 import org.apache.servicecomb.foundation.common.utils.BeanUtils;
 import org.apache.servicecomb.it.deploy.Deploys;
@@ -48,6 +50,7 @@ import org.apache.servicecomb.it.testcase.TestRestServerConfigEdge;
 import org.apache.servicecomb.it.testcase.TestRestVertxTransportConfig;
 import org.apache.servicecomb.it.testcase.TestTrace;
 import org.apache.servicecomb.it.testcase.TestTraceEdge;
+import org.apache.servicecomb.it.testcase.TestTransportContext;
 import org.apache.servicecomb.it.testcase.TestUpload;
 import org.apache.servicecomb.it.testcase.base.TestGeneric;
 import org.apache.servicecomb.it.testcase.objectparams.TestJAXRSObjectParamType;
@@ -57,6 +60,7 @@ import org.apache.servicecomb.it.testcase.objectparams.TestSpringMVCObjectParamT
 import org.apache.servicecomb.it.testcase.publicHeaders.TestPublicHeadersEdge;
 import org.apache.servicecomb.it.testcase.thirdparty.Test3rdPartyInvocation;
 import org.apache.servicecomb.it.testcase.weak.consumer.TestSpringmvcBasic;
+import org.apache.servicecomb.transport.highway.HighwayTransportContext;
 
 public class ConsumerMain {
   private static ResultPrinter resultPrinter = new ResultPrinter();
@@ -183,6 +187,12 @@ public class ConsumerMain {
 
     // currently, only support vertx download
     ITJUnitUtils.run(TestDownloadSlowStreamEdge.class);
+
+    TestTransportContext.expectName = VertxHttpTransportContext.class.getName();
+    ITJUnitUtils.runWithRest(TestTransportContext.class);
+
+    TestTransportContext.expectName = HighwayTransportContext.class.getName();
+    ITJUnitUtils.runWithHighway(TestTransportContext.class);
   }
 
   private static void testH2CStandalone() throws Throwable {
@@ -210,5 +220,8 @@ public class ConsumerMain {
 
   private static void testSpringBoot2Servlet() throws Throwable {
     runShareTestCases();
+
+    TestTransportContext.expectName = HttpTransportContext.class.getName();
+    ITJUnitUtils.runWithRest(TestTransportContext.class);
   }
 }
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/junit/ITJUnitUtils.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/junit/ITJUnitUtils.java
index 105ac2f..fbf0b7c 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/junit/ITJUnitUtils.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/junit/ITJUnitUtils.java
@@ -167,6 +167,10 @@ public final class ITJUnitUtils {
     runWithTransports(Arrays.asList(Const.RESTFUL), classes);
   }
 
+  public static void runWithHighway(Class<?>... classes) throws Throwable {
+    runWithTransports(Arrays.asList(Const.HIGHWAY), classes);
+  }
+
   public static void runWithTransports(List<String> transports, Class<?>... classes) throws Throwable {
     for (String transport : transports) {
       ITJUnitUtils.pushTransport(transport);
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestChangeTransport.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestChangeTransport.java
index 633dad0..c399a3e 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestChangeTransport.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestChangeTransport.java
@@ -21,22 +21,22 @@ import org.junit.Assert;
 import org.junit.Test;
 
 public class TestChangeTransport {
-  interface ChangeTranportIntf {
+  interface ChangeTransportIntf {
     String checkTransport();
   }
 
-  static Consumers<ChangeTranportIntf> consumersPojo = new Consumers<>("transportPojo", ChangeTranportIntf.class);
+  static Consumers<ChangeTransportIntf> consumersPojo = new Consumers<>("transportPojo", ChangeTransportIntf.class);
 
-  static Consumers<ChangeTranportIntf> consumersJaxrs = new Consumers<>("transportJaxrs", ChangeTranportIntf.class);
+  static Consumers<ChangeTransportIntf> consumersJaxrs = new Consumers<>("transportJaxrs", ChangeTransportIntf.class);
 
-  static Consumers<ChangeTranportIntf> consumersSpringmvc = new Consumers<>("transportSpringmvc",
-      ChangeTranportIntf.class);
+  static Consumers<ChangeTransportIntf> consumersSpringmvc = new Consumers<>("transportSpringmvc",
+      ChangeTransportIntf.class);
 
-  void checkTransport_intf(Consumers<ChangeTranportIntf> consumers) {
+  void checkTransport_intf(Consumers<ChangeTransportIntf> consumers) {
     Assert.assertEquals(consumers.getTransport(), consumers.getIntf().checkTransport());
   }
 
-  void checkTransport_rt(Consumers<ChangeTranportIntf> consumers) {
+  void checkTransport_rt(Consumers<ChangeTransportIntf> consumers) {
     Assert.assertEquals(consumers.getTransport(),
         consumers.getSCBRestTemplate().getForObject("/checkTransport", String.class));
   }
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestTransportContext.java
similarity index 59%
copy from common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java
copy to integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestTransportContext.java
index 2cd5f31..f47defb 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestTransportContext.java
@@ -14,17 +14,24 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.servicecomb.it.testcase;
 
-package org.apache.servicecomb.common.rest;
+import static org.assertj.core.api.Assertions.assertThat;
 
-import org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest;
+import org.apache.servicecomb.it.Consumers;
+import org.junit.Test;
 
-public class VertxRestInvocation extends RestProducerInvocation {
-  @Override
-  protected void createInvocation() {
-    super.createInvocation();
+public class TestTransportContext {
+  interface TransportContextIntf {
+    String context();
+  }
+
+  static Consumers<TransportContextIntf> consumers = new Consumers<>("transport-context", TransportContextIntf.class);
+
+  public static String expectName;
 
-    ((VertxServerRequestToHttpServletRequest) this.requestEx).getContext()
-        .put(RestConst.REST_INVOCATION_CONTEXT, this.invocation);
+  @Test
+  public void should_get_transport_context_name() {
+    assertThat(consumers.getIntf().context()).isEqualTo(expectName);
   }
 }
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/TransportContextSchema.java
similarity index 58%
copy from common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java
copy to integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/TransportContextSchema.java
index 2cd5f31..68263cd 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java
+++ b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/TransportContextSchema.java
@@ -14,17 +14,18 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.servicecomb.it.schema;
 
-package org.apache.servicecomb.common.rest;
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
 
-import org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest;
-
-public class VertxRestInvocation extends RestProducerInvocation {
-  @Override
-  protected void createInvocation() {
-    super.createInvocation();
-
-    ((VertxServerRequestToHttpServletRequest) this.requestEx).getContext()
-        .put(RestConst.REST_INVOCATION_CONTEXT, this.invocation);
+@RestSchema(schemaId = "transport-context")
+@RequestMapping(path = "/v1/transport-context")
+public class TransportContextSchema {
+  @GetMapping(path = "/")
+  public String context(InvocationContext context) {
+    return context.getTransportContext().getClass().getName();
   }
 }
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index aeafbda..5f3ec4f 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -151,6 +151,12 @@
       <scope>compile</scope>
     </dependency>
     <dependency>
+      <groupId>org.assertj</groupId>
+      <artifactId>assertj-core</artifactId>
+      <scope>compile</scope>
+    </dependency>
+
+    <dependency>
       <groupId>org.apache.servicecomb</groupId>
       <artifactId>foundation-test-scaffolding</artifactId>
       <scope>compile</scope>
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/context/InvocationContext.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/context/InvocationContext.java
index 009fc94..bdfc85f 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/context/InvocationContext.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/context/InvocationContext.java
@@ -36,6 +36,8 @@ public class InvocationContext {
 
   protected Map<String, Object> localContext = new HashMap<>();
 
+  protected TransportContext transportContext;
+
   public InvocationContext() {
     httpStatus = Status.OK;
   }
@@ -126,4 +128,13 @@ public class InvocationContext {
   public void setStatus(int statusCode) {
     this.httpStatus = statusMgr.getOrCreateByStatusCode(statusCode);
   }
+
+  @SuppressWarnings("unchecked")
+  public <T extends TransportContext> T getTransportContext() {
+    return (T) transportContext;
+  }
+
+  public void setTransportContext(TransportContext transportContext) {
+    this.transportContext = transportContext;
+  }
 }
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/context/TransportContext.java
similarity index 65%
copy from common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java
copy to swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/context/TransportContext.java
index 2cd5f31..7991e6b 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/context/TransportContext.java
@@ -15,16 +15,10 @@
  * limitations under the License.
  */
 
-package org.apache.servicecomb.common.rest;
+package org.apache.servicecomb.swagger.invocation.context;
 
-import org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest;
-
-public class VertxRestInvocation extends RestProducerInvocation {
-  @Override
-  protected void createInvocation() {
-    super.createInvocation();
-
-    ((VertxServerRequestToHttpServletRequest) this.requestEx).getContext()
-        .put(RestConst.REST_INVOCATION_CONTEXT, this.invocation);
-  }
+/**
+ * currently, only for server side
+ */
+public interface TransportContext {
 }
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/context/VertxTransportContext.java
similarity index 65%
copy from common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java
copy to swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/context/VertxTransportContext.java
index 2cd5f31..103af47 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/context/VertxTransportContext.java
@@ -14,17 +14,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.servicecomb.swagger.invocation.context;
 
-package org.apache.servicecomb.common.rest;
+import io.vertx.core.Context;
 
-import org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest;
-
-public class VertxRestInvocation extends RestProducerInvocation {
-  @Override
-  protected void createInvocation() {
-    super.createInvocation();
-
-    ((VertxServerRequestToHttpServletRequest) this.requestEx).getContext()
-        .put(RestConst.REST_INVOCATION_CONTEXT, this.invocation);
-  }
+public interface VertxTransportContext extends TransportContext {
+  Context getVertxContext();
 }
diff --git a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerInvoke.java b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerInvoke.java
index 47c9afa..3c4442c 100644
--- a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerInvoke.java
+++ b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerInvoke.java
@@ -173,6 +173,7 @@ public class HighwayServerInvoke {
           operationMeta,
           null);
       operationProtobuf = ProtobufManager.getOrCreateOperation(invocation);
+      invocation.setTransportContext(new HighwayTransportContext());
       invocation.onStart(null, start);
       invocation.getInvocationStageTrace().startSchedule();
 
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayTransportContext.java
similarity index 64%
copy from common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java
copy to transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayTransportContext.java
index 2cd5f31..d45e786 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/VertxRestInvocation.java
+++ b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayTransportContext.java
@@ -14,17 +14,22 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.servicecomb.transport.highway;
 
-package org.apache.servicecomb.common.rest;
+import org.apache.servicecomb.swagger.invocation.context.VertxTransportContext;
 
-import org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest;
+import io.vertx.core.Context;
+import io.vertx.core.Vertx;
 
-public class VertxRestInvocation extends RestProducerInvocation {
-  @Override
-  protected void createInvocation() {
-    super.createInvocation();
+public class HighwayTransportContext implements VertxTransportContext {
+  protected Context vertxContext;
+
+  public HighwayTransportContext() {
+    this.vertxContext = Vertx.currentContext();
+  }
 
-    ((VertxServerRequestToHttpServletRequest) this.requestEx).getContext()
-        .put(RestConst.REST_INVOCATION_CONTEXT, this.invocation);
+  @Override
+  public Context getVertxContext() {
+    return vertxContext;
   }
 }
diff --git a/transports/transport-rest/transport-rest-servlet/src/main/java/org/apache/servicecomb/transport/rest/servlet/RestServletProducerInvocation.java b/transports/transport-rest/transport-rest-servlet/src/main/java/org/apache/servicecomb/transport/rest/servlet/RestServletProducerInvocation.java
index 299c611..0be644c 100644
--- a/transports/transport-rest/transport-rest-servlet/src/main/java/org/apache/servicecomb/transport/rest/servlet/RestServletProducerInvocation.java
+++ b/transports/transport-rest/transport-rest-servlet/src/main/java/org/apache/servicecomb/transport/rest/servlet/RestServletProducerInvocation.java
@@ -17,6 +17,7 @@
 
 package org.apache.servicecomb.transport.rest.servlet;
 
+import org.apache.servicecomb.common.rest.HttpTransportContext;
 import org.apache.servicecomb.common.rest.RestProducerInvocation;
 import org.apache.servicecomb.common.rest.filter.HttpServerFilter;
 import org.apache.servicecomb.core.definition.OperationMeta;
@@ -39,4 +40,11 @@ public class RestServletProducerInvocation extends RestProducerInvocation {
     }
     return false;
   }
+
+  @Override
+  protected void createInvocation() {
+    super.createInvocation();
+
+    invocation.setTransportContext(new HttpTransportContext(requestEx, responseEx));
+  }
 }