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/incubator-servicecomb-java-chassis.git

commit 69f8b17bb82c777ea0b685405fa4e3c44ae9b066
Author: liubao <bao....@huawei.com>
AuthorDate: Tue May 29 15:49:33 2018 +0800

    [SCB-611]change pathIndex to prefixSegmentCount
---
 .../edge-service/src/main/resources/microservice.yaml          |  6 +++---
 .../apache/servicecomb/edge/core/DefaultEdgeDispatcher.java    |  8 ++++----
 .../apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java  | 10 +++++-----
 .../servicecomb/edge/core/TestURLMappedEdgeDispatcher.java     |  6 +++---
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/demo/demo-edge/edge-service/src/main/resources/microservice.yaml 
b/demo/demo-edge/edge-service/src/main/resources/microservice.yaml
index e029172..7bfa1b9 100644
--- a/demo/demo-edge/edge-service/src/main/resources/microservice.yaml
+++ b/demo/demo-edge/edge-service/src/main/resources/microservice.yaml
@@ -44,17 +44,17 @@ servicecomb:
           enabled: true
           prefix: rest
           withVersion: true
-          pathIndex: 1
+          prefixSegmentCount: 1
         url:
           enabled: true
           mappings:
             businessV1:
-              pathIndex: 1
+              prefixSegmentCount: 1
               path: "/url/business/v1/.*"
               microserviceName: business
               versionRule: 1.0.0-2.0.0
             businessV2:
-              pathIndex: 1
+              prefixSegmentCount: 1
               path: "/url/business/v2/.*"
               microserviceName: business
               versionRule: 2.0.0-3.0.0
diff --git 
a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/DefaultEdgeDispatcher.java
 
b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/DefaultEdgeDispatcher.java
index 6ed0894..20ecb21 100644
--- 
a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/DefaultEdgeDispatcher.java
+++ 
b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/DefaultEdgeDispatcher.java
@@ -35,7 +35,7 @@ public class DefaultEdgeDispatcher extends 
AbstractEdgeDispatcher {
 
   private static final String KEY_WITH_VERSION = 
"servicecomb.http.dispatcher.edge.default.withVersion";
 
-  private static final String KEY_PATH_INDEX = 
"servicecomb.http.dispatcher.edge.default.pathIndex";
+  private static final String KEY_PREFIX_SEGMENT_COUNT = 
"servicecomb.http.dispatcher.edge.default.prefixSegmentCount";
 
   private CompatiblePathVersionMapper versionMapper = new 
CompatiblePathVersionMapper();
 
@@ -43,7 +43,7 @@ public class DefaultEdgeDispatcher extends 
AbstractEdgeDispatcher {
 
   private boolean withVersion;
 
-  private int pathIndex;
+  private int prefixSegmentCount;
 
   @Override
   public int getOrder() {
@@ -59,7 +59,7 @@ public class DefaultEdgeDispatcher extends 
AbstractEdgeDispatcher {
   public void init(Router router) {
     prefix = 
DynamicPropertyFactory.getInstance().getStringProperty(KEY_PREFIX, "api").get();
     withVersion = 
DynamicPropertyFactory.getInstance().getBooleanProperty(KEY_WITH_VERSION, 
true).get();
-    pathIndex = 
DynamicPropertyFactory.getInstance().getIntProperty(KEY_PATH_INDEX, 1).get();
+    prefixSegmentCount = 
DynamicPropertyFactory.getInstance().getIntProperty(KEY_PREFIX_SEGMENT_COUNT, 
1).get();
     String regex;
     if (withVersion) {
       regex = "/" + prefix + "/([^\\\\/]+)/([^\\\\/]+)/(.*)";
@@ -74,7 +74,7 @@ public class DefaultEdgeDispatcher extends 
AbstractEdgeDispatcher {
   protected void onRequest(RoutingContext context) {
     Map<String, String> pathParams = context.pathParams();
     String microserviceName = pathParams.get("param0");
-    String path = Utils.findActualPath(context.request().path(), pathIndex);
+    String path = Utils.findActualPath(context.request().path(), 
prefixSegmentCount);
 
     EdgeInvocation edgeInvocation = new EdgeInvocation();
     if (withVersion) {
diff --git 
a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
 
b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
index a67e883..f8c1695 100644
--- 
a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
+++ 
b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
@@ -42,7 +42,7 @@ public class URLMappedEdgeDispatcher extends 
AbstractEdgeDispatcher {
 
     String versionRule;
 
-    int pathIndex;
+    int prefixSegmentCount;
 
     Pattern pattern;
 
@@ -63,7 +63,7 @@ public class URLMappedEdgeDispatcher extends 
AbstractEdgeDispatcher {
 
   private static final String KEY_MAPPING_VERSION_RULE = 
"servicecomb.http.dispatcher.edge.url.mappings.%s.versionRule";
 
-  private static final String KEY_MAPPING_PATH_INDEX = 
"servicecomb.http.dispatcher.edge.url.mappings.%s.pathIndex";
+  private static final String KEY_MAPPING_PREFIX_SEGMENT_COUNT = 
"servicecomb.http.dispatcher.edge.url.mappings.%s.prefixSegmentCount";
 
   private Map<String, ConfigurationItem> configurations = new HashMap<>();
 
@@ -123,8 +123,8 @@ public class URLMappedEdgeDispatcher extends 
AbstractEdgeDispatcher {
         if (StringUtils.isEmpty(configurationItem.microserviceName)) {
           continue;
         }
-        configurationItem.pathIndex = DynamicPropertyFactory.getInstance()
-            .getIntProperty(String.format(KEY_MAPPING_PATH_INDEX, 
pathKeyItem), 0).get();
+        configurationItem.prefixSegmentCount = 
DynamicPropertyFactory.getInstance()
+            .getIntProperty(String.format(KEY_MAPPING_PREFIX_SEGMENT_COUNT, 
pathKeyItem), 0).get();
         configurationItem.versionRule = DynamicPropertyFactory.getInstance()
             .getStringProperty(String.format(KEY_MAPPING_VERSION_RULE, 
pathKeyItem), "0.0.0+").get();
         configurations.put(pathKeyItem, configurationItem);
@@ -149,7 +149,7 @@ public class URLMappedEdgeDispatcher extends 
AbstractEdgeDispatcher {
       return;
     }
 
-    String path = Utils.findActualPath(context.request().path(), 
configurationItem.pathIndex);
+    String path = Utils.findActualPath(context.request().path(), 
configurationItem.prefixSegmentCount);
 
     EdgeInvocation edgeInvocation = new EdgeInvocation();
     if (configurationItem.versionRule != null) {
diff --git 
a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestURLMappedEdgeDispatcher.java
 
b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestURLMappedEdgeDispatcher.java
index 3e0732f..3bbf5e6 100644
--- 
a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestURLMappedEdgeDispatcher.java
+++ 
b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestURLMappedEdgeDispatcher.java
@@ -65,13 +65,13 @@ public class TestURLMappedEdgeDispatcher {
 
     
ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.path",
 "/a/b/c/.*");
     
ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.microserviceName",
 "serviceName");
-    
ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.pathIndex",
 2);
+    
ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.prefixSegmentCount",
 2);
     
ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.versionRule",
 "2.0.0+");
     items = Deencapsulation.getField(dispatcher, "configurations");
     Assert.assertEquals(items.size(), 1);
     ConfigurationItem item = items.get("service1");
     Assert.assertEquals(item.microserviceName, "serviceName");
-    Assert.assertEquals(item.pathIndex, 2);
+    Assert.assertEquals(item.prefixSegmentCount, 2);
     Assert.assertEquals(item.stringPattern, "/a/b/c/.*");
     Assert.assertEquals(item.versionRule, "2.0.0+");
 
@@ -81,7 +81,7 @@ public class TestURLMappedEdgeDispatcher {
     Assert.assertEquals(items.size(), 1);
     item = items.get("service1");
     Assert.assertEquals(item.microserviceName, "serviceName");
-    Assert.assertEquals(item.pathIndex, 2);
+    Assert.assertEquals(item.prefixSegmentCount, 2);
     Assert.assertEquals(item.stringPattern, "/a/b/c/.*");
     Assert.assertEquals(item.versionRule, "2.0.0+");
 

-- 
To stop receiving notification emails like this one, please contact
liu...@apache.org.

Reply via email to