wujimin commented on a change in pull request #594: [SCB-379] support 
AsyncRestTemplate
URL: 
https://github.com/apache/incubator-servicecomb-java-chassis/pull/594#discussion_r179024800
 
 

 ##########
 File path: 
providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequest.java
 ##########
 @@ -0,0 +1,93 @@
+/*
+ * 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.provider.springmvc.reference.async;
+
+import java.io.OutputStream;
+import java.net.URI;
+import java.util.concurrent.CompletableFuture;
+
+import org.apache.servicecomb.common.rest.RestConst;
+import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.core.invocation.InvocationFactory;
+import org.apache.servicecomb.core.provider.consumer.InvokerUtils;
+import 
org.apache.servicecomb.provider.springmvc.reference.CseClientHttpRequest;
+import 
org.apache.servicecomb.provider.springmvc.reference.CseClientHttpResponse;
+import org.apache.servicecomb.swagger.invocation.Response;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.client.AsyncClientHttpRequest;
+import org.springframework.http.client.ClientHttpResponse;
+import 
org.springframework.util.concurrent.CompletableToListenableFutureAdapter;
+import org.springframework.util.concurrent.ListenableFuture;
+
+import io.netty.handler.codec.http.QueryStringDecoder;
+
+public class CseAsyncClientHttpRequest extends CseClientHttpRequest implements 
AsyncClientHttpRequest {
+
+  CseAsyncClientHttpRequest() {
+  }
+
+  CseAsyncClientHttpRequest(URI uri, HttpMethod method) {
+    this.setUri(uri);
+    this.setMethod(method);
+  }
+
+  @Override
+  public OutputStream getBody() {
+    return null;
+  }
+
+  @SuppressWarnings("unchecked")
+  private ListenableFuture<ClientHttpResponse> invoke(Object[] args) {
+    Invocation invocation =
+        
InvocationFactory.forConsumer(this.getRequestMeta().getReferenceConfig(),
+            this.getRequestMeta().getOperationMeta(),
+            args);
+    invocation.getHandlerContext().put(RestConst.REST_CLIENT_REQUEST_PATH,
+        this.getPath() + "?" + this.getURI().getRawQuery());
+
+    if (this.getContext() != null) {
+      invocation.addContext(this.getContext());
+    }
+    invocation.getHandlerContext().put(RestConst.CONSUMER_HEADER, 
this.getHeaders());
+    CompletableFuture<ClientHttpResponse> clientHttpResponseCompletableFuture 
= doAsyncInvoke(invocation);
+    return new 
CompletableToListenableFutureAdapter(clientHttpResponseCompletableFuture);
 
 Review comment:
   CompletableToListenableFutureAdapter.addCallback handled this scenes, there 
is no problem.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to