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 2018/09/26 11:34:19 UTC

[incubator-servicecomb-java-chassis] 02/04: [SCB-931]several bug fixes and changes related to new vert.x version

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 eb0a2e32b56a4021912b04a4dee8562252b9034e
Author: liubao <ba...@huawei.com>
AuthorDate: Thu Sep 20 20:57:52 2018 +0800

    [SCB-931]several bug fixes and changes related to new vert.x version
---
 .../apache/servicecomb/foundation/vertx/VertxTLSBuilder.java  | 10 +++++++---
 .../apache/servicecomb/foundation/vertx/server/TcpServer.java |  9 ++++++++-
 .../transport/rest/client/http/RestClientInvocation.java      | 11 +++++++----
 .../test/java/io/vertx/core/http/impl/VertxImplTestUtils.java |  4 ++--
 .../servicecomb/transport/rest/vertx/RestServerVerticle.java  |  5 ++++-
 5 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxTLSBuilder.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxTLSBuilder.java
index bd6642b..ddc4709 100644
--- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxTLSBuilder.java
+++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxTLSBuilder.java
@@ -18,6 +18,9 @@
 package org.apache.servicecomb.foundation.vertx;
 
 import java.io.File;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.apache.servicecomb.foundation.ssl.SSLCustom;
 import org.apache.servicecomb.foundation.ssl.SSLManager;
@@ -135,9 +138,10 @@ public final class VertxTLSBuilder {
     } else {
       LOGGER.warn("trustStore [" + fullTrustStore + "] file not exist, please check!");
     }
-    for (String protocol : sslOption.getProtocols().split(",")) {
-      tcpClientOptions.addEnabledSecureTransportProtocol(protocol);
-    }
+
+    tcpClientOptions
+        .setEnabledSecureTransportProtocols(new HashSet<String>(Arrays.asList(sslOption.getProtocols().split(","))));
+
     for (String cipher : SSLManager.getEnalbedCiphers(sslOption.getCiphers())) {
       tcpClientOptions.addEnabledCipherSuite(cipher);
     }
diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/server/TcpServer.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/server/TcpServer.java
index 7fc3f24..be0ff46 100644
--- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/server/TcpServer.java
+++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/server/TcpServer.java
@@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.servicecomb.foundation.common.event.EventManager;
 import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
+import org.apache.servicecomb.foundation.common.utils.ExceptionUtils;
 import org.apache.servicecomb.foundation.ssl.SSLCustom;
 import org.apache.servicecomb.foundation.ssl.SSLOption;
 import org.apache.servicecomb.foundation.ssl.SSLOptionFactory;
@@ -30,6 +31,8 @@ import org.apache.servicecomb.foundation.vertx.ClientEvent;
 import org.apache.servicecomb.foundation.vertx.ConnectionEvent;
 import org.apache.servicecomb.foundation.vertx.TransportType;
 import org.apache.servicecomb.foundation.vertx.VertxTLSBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.netflix.config.DynamicPropertyFactory;
 
@@ -38,6 +41,8 @@ import io.vertx.core.net.NetServer;
 import io.vertx.core.net.NetServerOptions;
 
 public class TcpServer {
+  private static final Logger LOGGER = LoggerFactory.getLogger(TcpServer.class);
+
   private URIEndpointObject endpointObject;
 
   private final AtomicInteger connectedCounter;
@@ -81,7 +86,9 @@ public class TcpServer {
       EventManager.post(new ClientEvent(netSocket.remoteAddress().toString(),
           ConnectionEvent.Connected, TransportType.Highway, connectedCount));
     });
-
+    netServer.exceptionHandler(e -> {
+      LOGGER.error("Unexpected error in server.{}", ExceptionUtils.getExceptionMessageWithoutTrace(e));
+    });
     InetSocketAddress socketAddress = endpointObject.getSocketAddress();
     netServer.listen(socketAddress.getPort(), socketAddress.getHostString(), ar -> {
       if (ar.succeeded()) {
diff --git a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java
index a7b422d..dc0f86b 100644
--- a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java
+++ b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java
@@ -221,10 +221,13 @@ public class RestClientInvocation {
     }
 
     InvocationStageTrace stageTrace = invocation.getInvocationStageTrace();
-    DefaultHttpSocketMetric httpSocketMetric = (DefaultHttpSocketMetric) ((ConnectionBase) clientRequest.connection())
-        .metric();
-    stageTrace.finishGetConnection(httpSocketMetric.getRequestBeginTime());
-    stageTrace.finishWriteToBuffer(httpSocketMetric.getRequestEndTime());
+    ConnectionBase connection = (ConnectionBase) clientRequest.connection();
+    // connection maybe null when exception happens such as ssl handshake failure
+    if (connection != null) {
+      DefaultHttpSocketMetric httpSocketMetric = (DefaultHttpSocketMetric) connection.metric();
+      stageTrace.finishGetConnection(httpSocketMetric.getRequestBeginTime());
+      stageTrace.finishWriteToBuffer(httpSocketMetric.getRequestEndTime());
+    }
 
     stageTrace.finishClientFiltersResponse();
     asyncResp.fail(invocation.getInvocationType(), e);
diff --git a/transports/transport-rest/transport-rest-client/src/test/java/io/vertx/core/http/impl/VertxImplTestUtils.java b/transports/transport-rest/transport-rest-client/src/test/java/io/vertx/core/http/impl/VertxImplTestUtils.java
index cb2631f..5fb03b1 100644
--- a/transports/transport-rest/transport-rest-client/src/test/java/io/vertx/core/http/impl/VertxImplTestUtils.java
+++ b/transports/transport-rest/transport-rest-client/src/test/java/io/vertx/core/http/impl/VertxImplTestUtils.java
@@ -19,7 +19,7 @@ package io.vertx.core.http.impl;
 import org.mockito.Mockito;
 
 public class VertxImplTestUtils {
-  public static ClientConnection mockClientConnection() {
-    return Mockito.mock(ClientConnection.class);
+  public static Http1xConnectionBase mockClientConnection() {
+    return Mockito.mock(Http1xConnectionBase.class);
   }
 }
diff --git a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java
index caeaa1b..e93c561 100644
--- a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java
+++ b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java
@@ -30,6 +30,7 @@ import org.apache.servicecomb.core.Endpoint;
 import org.apache.servicecomb.core.transport.AbstractTransport;
 import org.apache.servicecomb.foundation.common.event.EventManager;
 import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
+import org.apache.servicecomb.foundation.common.utils.ExceptionUtils;
 import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
 import org.apache.servicecomb.foundation.ssl.SSLCustom;
 import org.apache.servicecomb.foundation.ssl.SSLOption;
@@ -118,7 +119,9 @@ public class RestServerVerticle extends AbstractVerticle {
               ConnectionEvent.Closed, TransportType.Rest, connectedCounter.decrementAndGet())));
         }
       });
-
+      httpServer.exceptionHandler(e -> {
+        LOGGER.error("Unexpected error in server.{}", ExceptionUtils.getExceptionMessageWithoutTrace(e));
+      });
       startListen(httpServer, startFuture);
     } catch (Throwable e) {
       // vert.x got some states that not print error and execute call back in VertexUtils.blockDeploy, we add a log our self.