[ 
https://issues.apache.org/jira/browse/SCB-760?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16549115#comment-16549115
 ] 

ASF GitHub Bot commented on SCB-760:
------------------------------------

liubao68 closed pull request #822: [SCB-760]provide a way to invoke service 
with full path
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/822
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
 
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
index cc93248b5..beab26a74 100644
--- 
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
+++ 
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
@@ -30,6 +30,7 @@
 import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
 import org.apache.servicecomb.provider.springmvc.reference.CseRestTemplate;
 import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
+import 
org.apache.servicecomb.provider.springmvc.reference.UrlWithProviderPrefixClientHttpRequestFactory;
 import 
org.apache.servicecomb.provider.springmvc.reference.UrlWithServiceNameClientHttpRequestFactory;
 import org.apache.servicecomb.swagger.invocation.exception.ExceptionFactory;
 import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
@@ -47,6 +48,8 @@
 public class SpringmvcClient {
   private static RestTemplate templateUrlWithServiceName = new 
CseRestTemplate();
 
+  private static RestTemplate templateUrlWithProviderPrefix = new 
CseRestTemplate();
+
   private static RestTemplate restTemplate;
 
   private static Controller controller;
@@ -65,6 +68,7 @@ public static void run() {
 
     templateUrlWithServiceName.setRequestFactory(new 
UrlWithServiceNameClientHttpRequestFactory());
     restTemplate = RestTemplateBuilder.create();
+    templateUrlWithProviderPrefix.setRequestFactory(new 
UrlWithProviderPrefixClientHttpRequestFactory("/pojo/rest"));
     controller = BeanUtils.getBean("controller");
 
     String prefix = "cse://springmvc";
@@ -80,6 +84,7 @@ public static void run() {
     CodeFirstRestTemplateSpringmvc codeFirstClient =
         BeanUtils.getContext().getBean(CodeFirstRestTemplateSpringmvc.class);
     codeFirstClient.testCodeFirst(restTemplate, "springmvc", 
"/codeFirstSpringmvc/");
+    codeFirstClient.testCodeFirst(templateUrlWithProviderPrefix, "springmvc", 
"/pojo/rest/codeFirstSpringmvc/");
 
     String microserviceName = "springmvc";
     for (String transport : DemoConst.transports) {
@@ -115,11 +120,13 @@ public static void run() {
     TestMgr.check(true, metrics.size() > 0);
     TestMgr.check(true,
         metrics.get(
-            
"servicecomb.invocation(operation=springmvc.codeFirst.saySomething,role=PRODUCER,stage=total,statistic=count,status=200,transport=highway)")
 >= 0);
+            
"servicecomb.invocation(operation=springmvc.codeFirst.saySomething,role=PRODUCER,stage=total,statistic=count,status=200,transport=highway)")
+            >= 0);
 
     //prometheus integration test
     try {
-      String content = 
restTemplate.getForObject("cse://springmvc/codeFirstSpringmvc/prometheusForTest",
 String.class);
+      String content = restTemplate
+          
.getForObject("cse://springmvc/codeFirstSpringmvc/prometheusForTest", 
String.class);
 
       TestMgr.check(true, 
content.contains("servicecomb_invocation{operation=\"springmvc.codeFirst.addDate"));
       TestMgr.check(true, 
content.contains("servicecomb_invocation{operation=\"springmvc.codeFirst.sayHello"));
diff --git 
a/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/UrlWithProviderPrefixClientHttpRequestFactory.java
 
b/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/UrlWithProviderPrefixClientHttpRequestFactory.java
new file mode 100644
index 000000000..6c7ba67d3
--- /dev/null
+++ 
b/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/UrlWithProviderPrefixClientHttpRequestFactory.java
@@ -0,0 +1,56 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.net.URI;
+
+import org.springframework.http.HttpMethod;
+import org.springframework.http.client.ClientHttpRequest;
+import org.springframework.http.client.ClientHttpRequestFactory;
+
+/**
+ * When deploying in a container, like tomcat, users want to invoke service 
with full path, including container context
+ * root and servlet path.
+ */
+public class UrlWithProviderPrefixClientHttpRequestFactory implements 
ClientHttpRequestFactory {
+  static class UrlWithProviderPrefixClientHttpRequest extends 
CseClientHttpRequest {
+    private String prefix;
+
+    public UrlWithProviderPrefixClientHttpRequest(URI uri, HttpMethod 
httpMethod, String prefix) {
+      super(uri, httpMethod);
+      this.prefix = prefix;
+    }
+
+    @Override
+    protected String findUriPath(URI uri) {
+      return uri.getRawPath().substring(prefix.length());
+    }
+  }
+
+  private String prefix;
+
+  public UrlWithProviderPrefixClientHttpRequestFactory(String prefix) {
+    this.prefix = prefix;
+  }
+
+  @Override
+  public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) 
throws IOException {
+    return new UrlWithProviderPrefixClientHttpRequest(uri, httpMethod, prefix);
+  }
+}
diff --git 
a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestUrlWithProviderPrefixClientHttpRequestFactory.java
 
b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestUrlWithProviderPrefixClientHttpRequestFactory.java
new file mode 100644
index 000000000..c66684188
--- /dev/null
+++ 
b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestUrlWithProviderPrefixClientHttpRequestFactory.java
@@ -0,0 +1,80 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.common.rest.RestConst;
+import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.core.definition.OperationMeta;
+import org.apache.servicecomb.core.invocation.InvocationFactory;
+import org.apache.servicecomb.core.provider.consumer.ReferenceConfig;
+import 
org.apache.servicecomb.provider.springmvc.reference.UrlWithProviderPrefixClientHttpRequestFactory.UrlWithProviderPrefixClientHttpRequest;
+import org.apache.servicecomb.swagger.invocation.Response;
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.http.HttpMethod;
+
+import mockit.Deencapsulation;
+import mockit.Expectations;
+import mockit.Mocked;
+
+public class TestUrlWithProviderPrefixClientHttpRequestFactory {
+  UrlWithProviderPrefixClientHttpRequestFactory factory = new 
UrlWithProviderPrefixClientHttpRequestFactory("/a/b/c");
+
+  URI uri = URI.create("cse://ms/a/b/c/v1/path");
+
+  @Test
+  public void findUriPath() throws IOException {
+    UrlWithProviderPrefixClientHttpRequest request =
+        (UrlWithProviderPrefixClientHttpRequest) factory.createRequest(uri, 
HttpMethod.GET);
+
+    Assert.assertEquals("/v1/path", request.findUriPath(uri));
+  }
+
+  @Test
+  public void invoke_checkPath(@Mocked Invocation invocation, @Mocked 
RequestMeta requestMeta) {
+    Map<String, String> handlerContext = new HashMap<>();
+    UrlWithProviderPrefixClientHttpRequest request = new 
UrlWithProviderPrefixClientHttpRequest(uri, HttpMethod.GET,
+        "/a/b/c") {
+      @Override
+      protected Response doInvoke(Invocation invocation) {
+        return Response.ok(null);
+      }
+    };
+
+    new Expectations(InvocationFactory.class) {
+      {
+        invocation.getHandlerContext();
+        result = handlerContext;
+        InvocationFactory.forConsumer((ReferenceConfig) any, (OperationMeta) 
any, (Object[]) any);
+        result = invocation;
+      }
+    };
+
+    Deencapsulation.setField(request, "requestMeta", requestMeta);
+    Deencapsulation.setField(request, "path", request.findUriPath(uri));
+
+    Deencapsulation.invoke(request, "invoke", new Object[] {new Object[] {}});
+
+    Assert.assertEquals("/v1/path?null", 
handlerContext.get(RestConst.REST_CLIENT_REQUEST_PATH));
+  }
+}
diff --git 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/TestInstanceCacheChecker.java
 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/TestInstanceCacheChecker.java
index d4d55bf23..b932070b2 100644
--- 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/TestInstanceCacheChecker.java
+++ 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/TestInstanceCacheChecker.java
@@ -83,13 +83,6 @@ public void check_microserviceManager_empty() {
     appId = "notExist";
     serviceRegistry.getAppManager().getOrCreateMicroserviceVersions(appId, 
microserviceName);
     InstanceCacheSummary instanceCacheSummary = checker.check();
-
-    InstanceCacheResult instanceCacheResult = new InstanceCacheResult();
-    instanceCacheResult.setAppId(appId);
-    instanceCacheResult.setMicroserviceName(microserviceName);
-    instanceCacheResult.setStatus(Status.NORMAL);
-    expectedSummary.getProducers().add(instanceCacheResult);
-
     Assert.assertEquals(Json.encode(expectedSummary), 
Json.encode(instanceCacheSummary));
   }
 


 

----------------------------------------------------------------
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


> provide a way to invoke service with full path
> ----------------------------------------------
>
>                 Key: SCB-760
>                 URL: https://issues.apache.org/jira/browse/SCB-760
>             Project: Apache ServiceComb
>          Issue Type: New Feature
>            Reporter: liubao
>            Assignee: liubao
>            Priority: Major
>
>  When deploying in a container, like tomcat, users want to invoke service 
> with full path, including container context
> root and servlet path.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to