diff --git a/core/src/test/java/org/apache/servicecomb/core/transport/TestAbstractTransport.java b/core/src/test/java/org/apache/servicecomb/core/transport/TestAbstractTransport.java index b0fd7ba0c4b..c43ea62b110 100644 --- a/core/src/test/java/org/apache/servicecomb/core/transport/TestAbstractTransport.java +++ b/core/src/test/java/org/apache/servicecomb/core/transport/TestAbstractTransport.java @@ -18,7 +18,6 @@ package org.apache.servicecomb.core.transport; import java.io.UnsupportedEncodingException; -import java.lang.reflect.Method; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.Collections; @@ -26,27 +25,12 @@ import org.apache.servicecomb.core.Invocation; import org.apache.servicecomb.foundation.common.net.IpPort; import org.apache.servicecomb.foundation.vertx.VertxUtils; -import org.apache.servicecomb.registry.RegistrationManager; import org.apache.servicecomb.swagger.invocation.AsyncResponse; import org.junit.AfterClass; import org.junit.Test; import org.junit.jupiter.api.Assertions; -import org.springframework.util.ReflectionUtils; - -import com.netflix.config.DynamicProperty; - -import mockit.Expectations; -import mockit.Mocked; public class TestAbstractTransport { - private final Method updatePropertyMethod = - ReflectionUtils.findMethod(DynamicProperty.class, "updateProperty", String.class, Object.class); - - private void updateProperty(String key, Object value) { - updatePropertyMethod.setAccessible(true); - ReflectionUtils.invokeMethod(updatePropertyMethod, null, key, value); - } - static class MyAbstractTransport extends AbstractTransport { @Override @@ -71,12 +55,6 @@ public static void classTeardown() { @Test public void testSetListenAddressWithoutSchemaChineseSpaceNewSC() throws UnsupportedEncodingException { - new Expectations() { - { - RegistrationManager.getPublishAddress("my", "127.0.0.1:9090"); - } - }; - MyAbstractTransport transport = new MyAbstractTransport(); transport.setListenAddressWithoutSchema("127.0.0.1:9090", Collections.singletonMap("country", "中 国")); Assertions.assertEquals("my://127.0.0.1:9090?country=" + URLEncoder.encode("中 国", StandardCharsets.UTF_8.name()), @@ -113,7 +91,7 @@ public void testMyAbstractTransport() { } @Test(expected = IllegalArgumentException.class) - public void testMyAbstractTransportException(@Mocked TransportManager manager) { + public void testMyAbstractTransportException() { MyAbstractTransport transport = new MyAbstractTransport(); transport.setListenAddressWithoutSchema(":127.0.0.1:9090"); diff --git a/dependencies/default/pom.xml b/dependencies/default/pom.xml index 517c648e605..c8c251de368 100644 --- a/dependencies/default/pom.xml +++ b/dependencies/default/pom.xml @@ -78,7 +78,7 @@ 5.14.0 2.2.0 0.3.0 - 4.1.110.Final + 4.1.112.Final 4.10.0 0.16.0 3.21.12 @@ -98,7 +98,7 @@ 2.7.18 1.6.9 1.3.3 - 4.4.9 + 4.5.9 2.24.0 2.16.3 diff --git a/foundations/foundation-test-scaffolding/src/main/java/io/vertx/core/impl/SyncContext.java b/foundations/foundation-test-scaffolding/src/main/java/io/vertx/core/impl/SyncContext.java index eb25a08f56f..9a6f0ce383c 100644 --- a/foundations/foundation-test-scaffolding/src/main/java/io/vertx/core/impl/SyncContext.java +++ b/foundations/foundation-test-scaffolding/src/main/java/io/vertx/core/impl/SyncContext.java @@ -16,20 +16,39 @@ */ package io.vertx.core.impl; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; + +import io.netty.channel.EventLoop; +import io.vertx.codegen.annotations.Nullable; import io.vertx.core.AsyncResult; +import io.vertx.core.Context; import io.vertx.core.Future; import io.vertx.core.Handler; import io.vertx.core.Promise; +import io.vertx.core.ThreadingModel; +import io.vertx.core.json.JsonObject; +import io.vertx.core.spi.tracing.VertxTracer; + +/** + * This class is created to make vertx unit test easier + */ +@SuppressWarnings({"rawtypes"}) +public class SyncContext extends ContextBase implements ContextInternal { + private static final long serialVersionUID = -6209656149925076980L; -public class SyncContext extends EventLoopContext { protected VertxInternal owner; + protected Executor executor = Executors.newSingleThreadExecutor(); + public SyncContext() { - this(null); + this(0); } - public SyncContext(VertxInternal vertx) { - super(vertx, null, null, null, null, null, null); + public SyncContext(int localsLength) { + super(localsLength); } @Override @@ -37,15 +56,76 @@ public VertxInternal owner() { return owner; } - public void setOwner(VertxInternal owner) { - this.owner = owner; + @Override + public Context exceptionHandler(@Nullable Handler handler) { + return null; + } + + @Override + public @Nullable Handler exceptionHandler() { + return null; + } + + @Override + public boolean inThread() { + return false; + } + + @Override + public void emit(T t, Handler handler) { + + } + + @Override + public void execute(Runnable runnable) { + + } + + @Override + public void execute(T t, Handler handler) { + + } + + @Override + public void reportException(Throwable throwable) { + + } + + @Override + public ConcurrentMap contextData() { + return null; + } + + @Override + public ClassLoader classLoader() { + return null; } @Override - protected void runOnContext(ContextInternal ctx, Handler action) { - action.handle(null); + public WorkerPool workerPool() { + return null; } + @Override + public VertxTracer tracer() { + return null; + } + + @Override + public ContextInternal duplicate() { + return null; + } + + @Override + public CloseFuture closeFuture() { + return null; + } + + public void setOwner(VertxInternal owner) { + this.owner = owner; + } + + public static void syncExecuteBlocking(Handler> blockingCodeHandler, Handler> asyncResultHandler) { Promise res = Promise.promise(); @@ -70,7 +150,6 @@ private static Future syncExecuteBlocking(Handler> blockingCod return res.future(); } - res.complete(); return res.future(); } @@ -80,8 +159,81 @@ public Future executeBlockingInternal(Handler> action) { } @Override + public Future executeBlockingInternal(Callable callable) { + return null; + } + + @Override + public Future executeBlockingInternal(Handler> handler, boolean b) { + return null; + } + + @Override + public Future executeBlockingInternal(Callable callable, boolean b) { + return null; + } + + @Override + public Deployment getDeployment() { + return null; + } + + @Override + public Executor executor() { + return executor; + } + + @Override + public EventLoop nettyEventLoop() { + return null; + } + + @Override + @Deprecated + public Future executeBlocking(Handler> handler, TaskQueue taskQueue) { + return null; + } + + @Override + public Future executeBlocking(Callable callable, TaskQueue taskQueue) { + return null; + } + + @Override + @Deprecated public void executeBlocking(Handler> blockingCodeHandler, boolean ordered, Handler> asyncResultHandler) { syncExecuteBlocking(blockingCodeHandler, asyncResultHandler); } + + @Override + public Future<@Nullable T> executeBlocking(Callable callable, boolean b) { + return null; + } + + @Override + @Deprecated + public Future<@Nullable T> executeBlocking(Handler> handler, boolean b) { + return null; + } + + @Override + public @Nullable JsonObject config() { + return null; + } + + @Override + public boolean isEventLoopContext() { + return false; + } + + @Override + public boolean isWorkerContext() { + return false; + } + + @Override + public ThreadingModel threadingModel() { + return null; + } } 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 4564ba9d465..b26ae3f4bb9 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 @@ -110,7 +110,7 @@ private static TCPSSLOptions buildTCPSSLOptions(SSLOption sslOption, SSLCustom s tcpClientOptions.setSsl(true); if (sslOption.getEngine().equalsIgnoreCase("openssl")) { - tcpClientOptions.setOpenSslEngineOptions(new OpenSSLEngineOptions()); + tcpClientOptions.setSslEngineOptions(new OpenSSLEngineOptions()); } String fullKeyStore = sslCustom.getFullPath(sslOption.getKeyStore()); if (isFileExists(fullKeyStore)) { @@ -118,12 +118,12 @@ private static TCPSSLOptions buildTCPSSLOptions(SSLOption sslOption, SSLCustom s PfxOptions keyPfxOptions = new PfxOptions(); keyPfxOptions.setPath(fullKeyStore); keyPfxOptions.setPassword(new String(sslCustom.decode(sslOption.getKeyStoreValue().toCharArray()))); - tcpClientOptions.setPfxKeyCertOptions(keyPfxOptions); + tcpClientOptions.setKeyCertOptions(keyPfxOptions); } else if (STORE_JKS.equalsIgnoreCase(sslOption.getKeyStoreType())) { JksOptions keyJksOptions = new JksOptions(); keyJksOptions.setPath(fullKeyStore); keyJksOptions.setPassword(new String(sslCustom.decode(sslOption.getKeyStoreValue().toCharArray()))); - tcpClientOptions.setKeyStoreOptions(keyJksOptions); + tcpClientOptions.setKeyCertOptions(keyJksOptions); } else { throw new IllegalArgumentException("invalid key store type."); } @@ -137,13 +137,13 @@ private static TCPSSLOptions buildTCPSSLOptions(SSLOption sslOption, SSLCustom s trustPfxOptions.setPath(fullTrustStore); trustPfxOptions .setPassword(new String(sslCustom.decode(sslOption.getTrustStoreValue().toCharArray()))); - tcpClientOptions.setPfxTrustOptions(trustPfxOptions); + tcpClientOptions.setTrustOptions(trustPfxOptions); } else if (STORE_JKS.equalsIgnoreCase(sslOption.getTrustStoreType())) { JksOptions trustJksOptions = new JksOptions(); trustJksOptions.setPath(fullTrustStore); trustJksOptions .setPassword(new String(sslCustom.decode(sslOption.getTrustStoreValue().toCharArray()))); - tcpClientOptions.setTrustStoreOptions(trustJksOptions); + tcpClientOptions.setTrustOptions(trustJksOptions); } else { throw new IllegalArgumentException("invalid trust store type."); } 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 46608d1212c..972d145ec77 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 @@ -20,7 +20,6 @@ import java.net.InetSocketAddress; 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; @@ -78,7 +77,7 @@ public void init(Vertx vertx, String sslKey, AsyncResultCallback LOGGER.error("Unexpected error in server.{}", ExceptionUtils.getExceptionMessageWithoutTrace(e))); + netServer.exceptionHandler(e -> LOGGER.error("Unexpected error in server.", e)); InetSocketAddress socketAddress = endpointObject.getSocketAddress(); netServer.listen(socketAddress.getPort(), socketAddress.getHostString(), ar -> { if (ar.succeeded()) { diff --git a/foundations/foundation-vertx/src/test/java/io/vertx/ext/web/impl/TestHttpServerRequestUtils.java b/foundations/foundation-vertx/src/test/java/io/vertx/ext/web/impl/TestHttpServerRequestUtils.java index ec8255fdcc9..edf51783c1b 100644 --- a/foundations/foundation-vertx/src/test/java/io/vertx/ext/web/impl/TestHttpServerRequestUtils.java +++ b/foundations/foundation-vertx/src/test/java/io/vertx/ext/web/impl/TestHttpServerRequestUtils.java @@ -17,15 +17,16 @@ package io.vertx.ext.web.impl; -import io.vertx.ext.web.RequestBody; import org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import io.vertx.core.http.impl.HttpServerRequestInternal; +import io.vertx.core.net.HostAndPort; import io.vertx.ext.web.AllowForwardHeaders; +import io.vertx.ext.web.RequestBody; import io.vertx.ext.web.RoutingContext; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; // HttpServerRequestWrapper is a package visible class, so put this test in package io.vertx.ext.web.impl public class TestHttpServerRequestUtils { @@ -36,6 +37,7 @@ public void testVertxServerRequestToHttpServletRequest() { HttpServerRequestWrapper wrapper = new HttpServerRequestWrapper(request, AllowForwardHeaders.NONE); Mockito.when(request.scheme()).thenReturn("http"); Mockito.when(context.request()).thenReturn(wrapper); + Mockito.when(request.authority()).thenReturn(HostAndPort.create("localhost", 8080)); RequestBody requestBody = Mockito.mock(RequestBody.class); Mockito.when(context.body()).thenReturn(requestBody); diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestPumpFromPart.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestPumpFromPart.java index dd391c4f91d..c4c14b50b00 100644 --- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestPumpFromPart.java +++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestPumpFromPart.java @@ -25,23 +25,28 @@ import javax.servlet.http.Part; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.RandomStringUtils; +import org.apache.commons.lang3.RandomStringUtils; import org.apache.servicecomb.foundation.common.part.InputStreamPart; import org.apache.servicecomb.foundation.vertx.stream.InputStreamToReadStream.ReadResult; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; +import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.Assertions; import io.vertx.core.Context; import io.vertx.core.Promise; +import io.vertx.core.Vertx; import io.vertx.core.impl.SyncContext; +import io.vertx.core.impl.VertxInternal; import mockit.Expectations; import mockit.Mock; import mockit.MockUp; -import org.junit.jupiter.api.Assertions; public class TestPumpFromPart { - String src = RandomStringUtils.random(100); + static Vertx vertx = Vertx.vertx(); + + String src = RandomStringUtils.random(100, true, true); boolean inputStreamClosed; @@ -61,7 +66,12 @@ public void close() throws IOException { IOException error = new IOException(); - Context context = new SyncContext(); + SyncContext context = new SyncContext(); + + @Before + public void setup() throws IOException { + context.setOwner((VertxInternal) vertx); + } private void run(Context context, boolean closeOutput) throws Throwable { inputStream.reset(); diff --git a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClient.java b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClient.java index 4afe98a1f2a..1493fea1b7f 100644 --- a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClient.java +++ b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClient.java @@ -87,7 +87,11 @@ TcpClientConfig createTcpClientConfig() { } SSLCustom sslCustom = SSLCustom.createSSLCustom(sslOption.getSslCustomClass()); VertxTLSBuilder.buildClientOptionsBase(sslOption, sslCustom, tcpClientConfig); - + if (!sslOption.isCheckCNHost()) { + tcpClientConfig.setHostnameVerificationAlgorithm(""); + } else { + tcpClientConfig.setHostnameVerificationAlgorithm("HTTPS"); + } return tcpClientConfig; }