You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2020/02/24 03:18:48 UTC

[servicecomb-java-chassis] branch master updated (c1853c1 -> 89d4c4b)

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git.


    from c1853c1  [SCB-1783] prepare 2.0.1-SNAPSHOT
     new fde9fb1  [SCB-1785] Run java-chassis in spring boot with external tomcat
     new 89d4c4b  [SCB-1785] fix integration test will fail sometimes

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../it/testcase/TestRestVertxTransportConfig.java  |  8 +++----
 .../starter/servlet/RestServletInitializer.java    | 25 ++++++++++++++--------
 2 files changed, 20 insertions(+), 13 deletions(-)


[servicecomb-java-chassis] 02/02: [SCB-1785] fix integration test will fail sometimes

Posted by li...@apache.org.
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/servicecomb-java-chassis.git

commit 89d4c4b53e147948cb8e2838dda3964168d3de87
Author: liubao <bi...@qq.com>
AuthorDate: Fri Feb 21 17:25:16 2020 +0800

    [SCB-1785] fix integration test will fail sometimes
---
 .../servicecomb/it/testcase/TestRestVertxTransportConfig.java     | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRestVertxTransportConfig.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRestVertxTransportConfig.java
index c5f0904..63615f5 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRestVertxTransportConfig.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRestVertxTransportConfig.java
@@ -19,15 +19,15 @@ package org.apache.servicecomb.it.testcase;
 
 import static org.junit.Assert.fail;
 
+import org.apache.servicecomb.foundation.common.utils.ExceptionUtils;
 import org.apache.servicecomb.it.Consumers;
 import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.hamcrest.CoreMatchers;
 import org.junit.Assert;
 import org.junit.Test;
 
 import com.google.common.base.Strings;
 
-import io.netty.handler.codec.TooLongFrameException;
-
 public class TestRestVertxTransportConfig {
   // GET /v1/restServerConfig/testMaxInitialLineLength?q=...... HTTP/1.1
   private static final String INITIAL_LINE_SUFFIX = " HTTP/1.1";
@@ -85,8 +85,8 @@ public class TestRestVertxTransportConfig {
       consumers.getIntf().testClientReceiveHeaderSize(100001 - RESPONSE_HEADER.length());
       fail("an exception is expected!");
     } catch (InvocationException e) {
-      Assert.assertEquals(TooLongFrameException.class, e.getCause().getClass());
-      Assert.assertEquals("HTTP header is larger than 10000 bytes.", e.getCause().getMessage());
+      Assert.assertThat(ExceptionUtils.getExceptionMessageWithoutTrace(e),
+          CoreMatchers.containsString("HTTP header is larger than 10000 bytes."));
     }
   }
 }


[servicecomb-java-chassis] 01/02: [SCB-1785] Run java-chassis in spring boot with external tomcat

Posted by li...@apache.org.
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/servicecomb-java-chassis.git

commit fde9fb1e4d782b8b2e851d84806a29b8363e565e
Author: liubao <bi...@qq.com>
AuthorDate: Fri Feb 21 16:41:07 2020 +0800

    [SCB-1785] Run java-chassis in spring boot with external tomcat
---
 .../starter/servlet/RestServletInitializer.java    | 25 ++++++++++++++--------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/spring-boot/spring-boot-starters/java-chassis-spring-boot-starter-servlet/src/main/java/org/apache/servicecomb/springboot2/starter/servlet/RestServletInitializer.java b/spring-boot/spring-boot-starters/java-chassis-spring-boot-starter-servlet/src/main/java/org/apache/servicecomb/springboot2/starter/servlet/RestServletInitializer.java
index 8d518ef..8a0ff03 100644
--- a/spring-boot/spring-boot-starters/java-chassis-spring-boot-starter-servlet/src/main/java/org/apache/servicecomb/springboot2/starter/servlet/RestServletInitializer.java
+++ b/spring-boot/spring-boot-starters/java-chassis-spring-boot-starter-servlet/src/main/java/org/apache/servicecomb/springboot2/starter/servlet/RestServletInitializer.java
@@ -41,7 +41,7 @@ public class RestServletInitializer
     implements WebServerFactoryCustomizer<AbstractConfigurableWebServerFactory>, ServletContextInitializer {
   private static final Logger LOGGER = LoggerFactory.getLogger(RestServletInitializer.class);
 
-  private AbstractConfigurableWebServerFactory factory;
+  private AbstractConfigurableWebServerFactory factory = null;
 
   @Override
   public void customize(AbstractConfigurableWebServerFactory factory) {
@@ -51,21 +51,28 @@ public class RestServletInitializer
   @Override
   @SuppressWarnings("try")
   public void onStartup(ServletContext servletContext) throws ServletException {
+    if (StringUtils.isEmpty(ServletConfig.getServletUrlPattern())) {
+      // ensure the servlet will be instantiated
+      Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
+      configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, ServletConfig.DEFAULT_URL_PATTERN);
+    }
+
+    if (this.factory == null) {
+      // when running in external tomcat, WebServerFactoryCustomizer will not be available, but now tomcat
+      // is already listening and we can call ServletUtils.init directly.
+      ServletUtils.init(servletContext);
+      return;
+    }
+
     if (factory.getPort() == 0) {
       LOGGER.warn(
-          "spring boot embed web container listen port is 0, serviceComb will not use container's port to handler RESTful request.");
+          "spring boot embedded web container listen port is 0, ServiceComb will not use container's port to handler REST request.");
       return;
     }
 
-    // web container did not did listen now.
+    // when running in embedded tomcat, web container did not listen now. Call ServletUtils.init needs server is ready,
     // so mock to listen, and then close.
     try (ServerSocket ss = new ServerSocket(factory.getPort(), 0, factory.getAddress())) {
-      if (StringUtils.isEmpty(ServletConfig.getServletUrlPattern())) {
-        // ensure the servlet will be instantiated
-        Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
-        configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, ServletConfig.DEFAULT_URL_PATTERN);
-      }
-
       ServletUtils.init(servletContext);
     } catch (IOException e) {
       throw new ServletException(e);