From 8fed3c64d1dc3aae5e4cbd0405cf3420f0461fa1 Mon Sep 17 00:00:00 2001 From: jbescos Date: Fri, 17 Sep 2021 15:14:39 +0200 Subject: [PATCH 1/4] NettyConnectorProvider (jersey-netty-connector) is throwing an exception with inactive_pooled_connection_handler error Signed-off-by: Jorge Bescos Gascon --- .../jersey/netty/connector/NettyConnector.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyConnector.java b/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyConnector.java index f941e66572..056ef31802 100644 --- a/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyConnector.java +++ b/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyConnector.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.NoSuchElementException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.ExecutorService; @@ -102,7 +103,7 @@ class NettyConnector implements Connector { private final Integer maxPoolSizeTotal; //either from Jersey config, or default private final Integer maxPoolIdle; // either from Jersey config, or default - private static final String INACTIVE_POOLED_CONNECTION_HANDLER = "inactive_pooled_connection_handler"; + static final String INACTIVE_POOLED_CONNECTION_HANDLER = "inactive_pooled_connection_handler"; private static final String PRUNE_INACTIVE_POOL = "prune_inactive_pool"; private static final String READ_TIMEOUT_HANDLER = "read_timeout_handler"; private static final String REQUEST_HANDLER = "request_handler"; @@ -190,10 +191,18 @@ protected CompletableFuture execute(final ClientRequest jerseyRe synchronized (conns) { while (chan == null && !conns.isEmpty()) { chan = conns.remove(conns.size() - 1); - chan.pipeline().remove(INACTIVE_POOLED_CONNECTION_HANDLER); - chan.pipeline().remove(PRUNE_INACTIVE_POOL); + try { + chan.pipeline().remove(INACTIVE_POOLED_CONNECTION_HANDLER); + chan.pipeline().remove(PRUNE_INACTIVE_POOL); + } catch (NoSuchElementException e) { + /* + * Eat it. + * It could happen that the channel was closed, pipeline cleared and + * then it will fail to remove the names with this exception. + */ + } if (!chan.isOpen()) { - chan = null; + chan = null; } } } From 611ec4b9133e75e5df7ce7ca042e0d0a9144b409 Mon Sep 17 00:00:00 2001 From: Maxim Nesen <24524084+senivam@users.noreply.github.com> Date: Mon, 11 Oct 2021 16:31:59 +0200 Subject: [PATCH 2/4] modulelist maven plugin refactoring (#4887) Signed-off-by: Maxim Nesen --- .../pom.xml | 29 +++++++++++++++++++ .../plugins/GenerateJerseyModuleListMojo.java | 21 +++++++++++--- .../jersey/tools/plugins/HelpMojo.java | 11 ++++--- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/tools/jersey-doc-modulelist-maven-plugin/pom.xml b/tools/jersey-doc-modulelist-maven-plugin/pom.xml index 06ae2466c3..e09245b0a4 100644 --- a/tools/jersey-doc-modulelist-maven-plugin/pom.xml +++ b/tools/jersey-doc-modulelist-maven-plugin/pom.xml @@ -21,6 +21,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 + + org.eclipse.ee4j + project + 1.0.7 + + org.glassfish.jersey.tools.plugins jersey-doc-modulelist-maven-plugin maven-plugin @@ -53,6 +59,12 @@ maven-dependency-tree ${maven.shared.version} + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.6.1 + provided + @@ -74,6 +86,23 @@ false + + org.apache.maven.plugins + maven-plugin-plugin + 3.6.0 + + true + + + + default-descriptor + + descriptor + + process-classes + + + diff --git a/tools/jersey-doc-modulelist-maven-plugin/src/main/java/org/glassfish/jersey/tools/plugins/GenerateJerseyModuleListMojo.java b/tools/jersey-doc-modulelist-maven-plugin/src/main/java/org/glassfish/jersey/tools/plugins/GenerateJerseyModuleListMojo.java index da1de2c175..f284074e60 100644 --- a/tools/jersey-doc-modulelist-maven-plugin/src/main/java/org/glassfish/jersey/tools/plugins/GenerateJerseyModuleListMojo.java +++ b/tools/jersey-doc-modulelist-maven-plugin/src/main/java/org/glassfish/jersey/tools/plugins/GenerateJerseyModuleListMojo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -21,6 +21,10 @@ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import java.io.BufferedReader; @@ -41,10 +45,11 @@ * The plugins main MOJO class. * Walks through the maven dependency tree and creates the docbook output file. * - * @goal generate - * @phase process-sources - * @aggregator + * goal: generate + * phase: process-sources + * aggregator */ +@Mojo(name = "generate", aggregator = true, defaultPhase = LifecyclePhase.PROCESS_SOURCES) public class GenerateJerseyModuleListMojo extends AbstractMojo { /** @@ -82,6 +87,7 @@ public class GenerateJerseyModuleListMojo extends AbstractMojo { * @required * @readonly */ + @Parameter(defaultValue = "${project.basedir}") private MavenProject mavenProject; /** @@ -89,11 +95,13 @@ public class GenerateJerseyModuleListMojo extends AbstractMojo { * @required * @readonly */ + @Parameter( defaultValue = "${session}", readonly = true ) private MavenSession mavenSession; /** * @parameter default-value="modules.xml" */ + @Parameter(defaultValue = "modules.xml") private String outputFileName; /** @@ -103,6 +111,7 @@ public class GenerateJerseyModuleListMojo extends AbstractMojo { * * @parameter */ + @Parameter private String templateFileName; /** @@ -112,6 +121,7 @@ public class GenerateJerseyModuleListMojo extends AbstractMojo { * * @parameter */ + @Parameter private String tableHeaderFileName; /** @@ -120,6 +130,7 @@ public class GenerateJerseyModuleListMojo extends AbstractMojo { * * @parameter */ + @Parameter private String tableFooterFileName; /** @@ -129,11 +140,13 @@ public class GenerateJerseyModuleListMojo extends AbstractMojo { * * @parameter */ + @Parameter private String tableRowFileName; /** * @parameter default-value="false" */ + @Parameter(defaultValue = "false") private boolean outputUnmatched; private Configuration configuration; diff --git a/tools/jersey-doc-modulelist-maven-plugin/src/main/java/org/glassfish/jersey/tools/plugins/HelpMojo.java b/tools/jersey-doc-modulelist-maven-plugin/src/main/java/org/glassfish/jersey/tools/plugins/HelpMojo.java index c8c8b5680d..ccbdadd8ba 100644 --- a/tools/jersey-doc-modulelist-maven-plugin/src/main/java/org/glassfish/jersey/tools/plugins/HelpMojo.java +++ b/tools/jersey-doc-modulelist-maven-plugin/src/main/java/org/glassfish/jersey/tools/plugins/HelpMojo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -20,14 +20,17 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; /** * Displays the plugin help message. * - * @goal help - * @phase process-sources - * @aggregator + * goal: help + * phase: process-sources + * aggregator */ +@Mojo(name = "help", aggregator = true, defaultPhase = LifecyclePhase.PROCESS_SOURCES) public class HelpMojo extends AbstractMojo { private Log log; From 3716939adb721351e01b78bc54845b97bb6c836d Mon Sep 17 00:00:00 2001 From: jansupol Date: Wed, 6 Oct 2021 22:55:31 +0200 Subject: [PATCH 3/4] Update Directory Maven Plugin to work with maven 3.8.x Signed-off-by: jansupol --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 58d87c269c..ccc8e59c90 100644 --- a/pom.xml +++ b/pom.xml @@ -807,7 +807,7 @@ org.commonjava.maven.plugins directory-maven-plugin - 0.3.1 + 1.0 directories From aea2d4b87ddd0eb68b2d7b899ba48508be42205f Mon Sep 17 00:00:00 2001 From: Andrew Pielage Date: Thu, 2 Dec 2021 15:14:37 +0000 Subject: [PATCH 4/4] Better handling of MicroProfile Rest Client Proxies (#4918) Signed-off-by: Andrew Pielage --- .../restclient/RestClientBuilderImpl.java | 36 ++++++++++++++++++- .../restclient/RestClientBuilderImplTest.java | 33 +++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 ext/microprofile/mp-rest-client/src/test/java/org/glassfish/jersey/microprofile/restclient/RestClientBuilderImplTest.java diff --git a/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/RestClientBuilderImpl.java b/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/RestClientBuilderImpl.java index f157e7ba6b..3e3d129091 100644 --- a/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/RestClientBuilderImpl.java +++ b/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/RestClientBuilderImpl.java @@ -36,6 +36,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.annotation.Priority; import javax.net.ssl.HostnameVerifier; @@ -445,10 +447,42 @@ public RestClientBuilder proxyAddress(String proxyHost, int proxyPort) { if (proxyPort <= 0 || proxyPort > 65535) { throw new IllegalArgumentException("Invalid proxy port"); } - property(ClientProperties.PROXY_URI, proxyHost + ":" + proxyPort); + + // If proxyString is something like "localhost:8765" we need to add a scheme since the connectors expect one + String proxyString = createProxyString(proxyHost, proxyPort); + + property(ClientProperties.PROXY_URI, proxyString); return this; } + static String createProxyString(String proxyHost, int proxyPort) { + boolean prependScheme = false; + String proxyString = proxyHost + ":" + proxyPort; + + if (proxyString.split(":").length == 2) { + // Check if first character is a number to account for if proxyHost is given as an IP rather than a name + // URI.create("127.0.0.1:8765") will lead to an IllegalArgumentException + if (proxyString.matches("\\d.*")) { + prependScheme = true; + } else { + // "localhost:8765" will set the scheme as "localhost" and the host as "null" + URI proxyURI = URI.create(proxyString); + if (proxyURI.getHost() == null && proxyURI.getScheme().equals(proxyHost)) { + prependScheme = true; + } + } + } + + if (prependScheme) { + proxyString = "http://" + proxyString; + Logger.getLogger(RestClientBuilderImpl.class.getName()).log(Level.FINE, + "No scheme provided with proxyHost: " + proxyHost + ". Defaulting to HTTP, proxy address = " + + proxyString); + } + + return proxyString; + } + @Override public RestClientBuilder queryParamStyle(QueryParamStyle queryParamStyle) { if (queryParamStyle != null) { diff --git a/ext/microprofile/mp-rest-client/src/test/java/org/glassfish/jersey/microprofile/restclient/RestClientBuilderImplTest.java b/ext/microprofile/mp-rest-client/src/test/java/org/glassfish/jersey/microprofile/restclient/RestClientBuilderImplTest.java new file mode 100644 index 0000000000..685e53a32a --- /dev/null +++ b/ext/microprofile/mp-rest-client/src/test/java/org/glassfish/jersey/microprofile/restclient/RestClientBuilderImplTest.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021 Payara Foundation and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.microprofile.restclient; + +import org.junit.Assert; +import org.junit.Test; + +import static org.glassfish.jersey.microprofile.restclient.RestClientBuilderImpl.createProxyString; + +public class RestClientBuilderImplTest { + + @Test + public void createProxyStringTest() { + Assert.assertTrue(createProxyString("localhost", 8765).equals("http://localhost:8765")); + Assert.assertTrue(createProxyString("http://localhost", 8765).equals("http://localhost:8765")); + Assert.assertTrue(createProxyString("127.0.0.1", 8765).equals("http://127.0.0.1:8765")); + Assert.assertTrue(createProxyString("http://192.168.1.1", 8765).equals("http://192.168.1.1:8765")); + } +}