[jira] [Commented] (SCB-778) In tomcat, support register swagger base path with container prefix

2018-07-27 Thread ASF GitHub Bot (JIRA)


[ 
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() 

[jira] [Commented] (SCB-778) In tomcat, support register swagger base path with container prefix

2018-07-26 Thread ASF GitHub Bot (JIRA)


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

ASF GitHub Bot commented on SCB-778:


liubao68 opened a new pull request #838: [SCB-778]add container path to base 
path
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/838
 
 
   Follow this checklist to help us incorporate your contribution quickly and 
easily:
   
- [ ] Make sure there is a [JIRA 
issue](https://issues.apache.org/jira/browse/SCB) filed for the change (usually 
before you start working on it).  Trivial changes like typos do not require a 
JIRA issue.  Your pull request should address just this issue, without pulling 
in other changes.
- [ ] Each commit in the pull request should have a meaningful subject line 
and body.
- [ ] Format the pull request title like `[SCB-XXX] Fixes bug in 
ApproximateQuantiles`, where you replace `SCB-XXX` with the appropriate JIRA 
issue.
- [ ] Write a pull request description that is detailed enough to 
understand what the pull request does, how, and why.
- [ ] Run `mvn clean install` to make sure basic checks pass. A more 
thorough check will be performed on your pull request automatically.
- [ ] If this contribution is large, please file an Apache [Individual 
Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   ---
   


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


> In tomcat, support register swagger base path with container prefix
> ---
>
> Key: SCB-778
> URL: https://issues.apache.org/jira/browse/SCB-778
> Project: Apache ServiceComb
>  Issue Type: New Feature
>Reporter: liubao
>Assignee: liubao
>Priority: Major
>
> Current:
>   base path is register with service definition, e.g. /codeFirst/add, and 
> container prefix, e.g. /pojo/rest is not added to swagger. 
>   
>   When using RestTemplate to invoke, users do not need know about container 
> prefix
>  
> Users scenario:
>    They have a lot of client code(old framework and uses full path, e.g. 
> /pojo/rest/codeFirst/add
>  
> Solution:
>    provider give an option to register full path to base path. 



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