[
https://issues.apache.org/jira/browse/SCB-778?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16560540#comment-16560540
]
ASF GitHub Bot commented on SCB-778:
liubao68 closed pull request #838: [SCB-778]add container path to base path
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/838
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/core/src/main/java/org/apache/servicecomb/core/definition/schema/ProducerSchemaFactory.java
b/core/src/main/java/org/apache/servicecomb/core/definition/schema/ProducerSchemaFactory.java
index a3b0a38cf..87e7cb2d8 100644
---
a/core/src/main/java/org/apache/servicecomb/core/definition/schema/ProducerSchemaFactory.java
+++
b/core/src/main/java/org/apache/servicecomb/core/definition/schema/ProducerSchemaFactory.java
@@ -17,6 +17,9 @@
package org.apache.servicecomb.core.definition.schema;
+import static
org.apache.servicecomb.serviceregistry.api.Const.REGISTER_URL_PREFIX;
+import static org.apache.servicecomb.serviceregistry.api.Const.URL_PREFIX;
+
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
@@ -39,9 +42,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectWriter;
+import com.netflix.config.DynamicPropertyFactory;
import io.swagger.models.Operation;
import io.swagger.models.Swagger;
@@ -129,6 +134,13 @@ protected SchemaMeta createSchema(ProducerSchemaContext
context) {
swaggerContent);
}
+String urlPrefix = System.getProperty(URL_PREFIX);
+if (!StringUtils.isEmpty(urlPrefix) &&
!swagger.getBasePath().startsWith(urlPrefix)
+&& DynamicPropertyFactory.getInstance()
+.getBooleanProperty(REGISTER_URL_PREFIX, false).get()) {
+ LOGGER.info("Add swagger base path prefix for {} with {}",
swagger.getBasePath(), urlPrefix);
+ swagger.setBasePath(urlPrefix + swagger.getBasePath());
+}
// 注册契约
return schemaLoader.registerSchema(context.getMicroserviceMeta(),
context.getSchemaId(), swagger);
}
diff --git
a/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
b/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
index 6500c6439..97f7ddbf3 100644
---
a/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
+++
b/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
@@ -33,6 +33,7 @@
import org.apache.servicecomb.core.unittest.UnitTestMeta;
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.foundation.common.utils.ReflectUtils;
+import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.serviceregistry.RegistryUtils;
import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
import org.apache.servicecomb.swagger.engine.SwaggerProducerOperation;
@@ -49,6 +50,7 @@
import org.junit.BeforeClass;
import org.junit.Test;
+import io.swagger.models.Swagger;
import mockit.Mock;
import mockit.MockUp;
@@ -57,8 +59,6 @@
private static ProducerSchemaFactory producerSchemaFactory = new
ProducerSchemaFactory();
- private static SchemaMeta schemaMeta;
-
public static class TestProducerSchemaFactoryImpl {
public int add(int x, int y) {
return x + y;
@@ -102,11 +102,6 @@ public static void init() {
return (T) normalExecutor;
}
};
-
-schemaMeta = producerSchemaFactory.getOrCreateProducerSchema("app:ms",
-"schema",
-TestProducerSchemaFactoryImpl.class,
-new TestProducerSchemaFactoryImpl());
}
@AfterClass
@@ -116,6 +111,12 @@ public static void teardown() {
@Test
public void testGetOrCreateProducer() throws Exception {
+SchemaMeta schemaMeta =
producerSchemaFactory.getOrCreateProducerSchema("app:ms",
+"schema",
+TestProducerSchemaFactoryImpl.class,
+new TestProducerSchemaFactoryImpl());
+Swagger swagger = schemaMeta.getSwagger();
+Assert.assertEquals(swagger.getBasePath(),
"/TestProducerSchemaFactoryImpl");
OperationMeta operationMeta = schemaMeta.ensureFindOperation("add");
Assert.assertEquals("add", operationMeta.getOperationId());
@@ -146,8 +147,30 @@ public String getInvocationQualifiedName() {
Assert.assertEquals("Cse Internal Server Error", data.getMessage());
}
+ @Test
+ public void testGetOrCreateProducerWithPrefix()