Skip to content

Commit

Permalink
Merge pull request #4922 from senivam/31_merged
Browse files Browse the repository at this point in the history
merge actual master into 3.1
  • Loading branch information
jansupol authored Dec 3, 2021
2 parents b7a3946 + 2267fb7 commit e8f32c3
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -190,10 +191,18 @@ protected CompletableFuture<ClientResponse> 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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ private boolean bind(final Class<?> clazz, final Set<Class<?>> providerContracts
final boolean isJaxRsResource = runtimeSpecifics.isJaxRsResource(clazz);

if (isJaxRsResource && !runtimeSpecifics.isAcceptableResource(clazz)) {
LOGGER.warning(LocalizationMessages.CDI_NON_INSTANTIABLE_COMPONENT(clazz));
LOGGER.log(clazz.isInterface() ? Level.FINE : Level.WARNING,
LocalizationMessages.CDI_NON_INSTANTIABLE_COMPONENT(clazz));
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 jakarta.annotation.Priority;
import javax.net.ssl.HostnameVerifier;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}
}
29 changes: 29 additions & 0 deletions tools/jersey-doc-modulelist-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.ee4j</groupId>
<artifactId>project</artifactId>
<version>1.0.7</version>
</parent>

<groupId>org.glassfish.jersey.tools.plugins</groupId>
<artifactId>jersey-doc-modulelist-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
Expand Down Expand Up @@ -53,6 +59,12 @@
<artifactId>maven-dependency-tree</artifactId>
<version>${maven.shared.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.1</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -74,6 +86,23 @@
<fork>false</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>default-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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 {

/**
Expand Down Expand Up @@ -82,18 +87,21 @@ public class GenerateJerseyModuleListMojo extends AbstractMojo {
* @required
* @readonly
*/
@Parameter(defaultValue = "${project.basedir}")
private MavenProject mavenProject;

/**
* @component
* @required
* @readonly
*/
@Parameter( defaultValue = "${session}", readonly = true )
private MavenSession mavenSession;

/**
* @parameter default-value="modules.xml"
*/
@Parameter(defaultValue = "modules.xml")
private String outputFileName;

/**
Expand All @@ -103,6 +111,7 @@ public class GenerateJerseyModuleListMojo extends AbstractMojo {
*
* @parameter
*/
@Parameter
private String templateFileName;

/**
Expand All @@ -112,6 +121,7 @@ public class GenerateJerseyModuleListMojo extends AbstractMojo {
*
* @parameter
*/
@Parameter
private String tableHeaderFileName;

/**
Expand All @@ -120,6 +130,7 @@ public class GenerateJerseyModuleListMojo extends AbstractMojo {
*
* @parameter
*/
@Parameter
private String tableFooterFileName;

/**
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down

0 comments on commit e8f32c3

Please sign in to comment.