Skip to content

Commit

Permalink
merge of the actual master into the 3.x branch
Browse files Browse the repository at this point in the history
  • Loading branch information
senivam authored Jun 30, 2023
2 parents 1d5b4a2 + 3093a7d commit 3e235bd
Show file tree
Hide file tree
Showing 63 changed files with 1,516 additions and 389 deletions.
4 changes: 2 additions & 2 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ aopalliance Version 1
* Project: http://aopalliance.sourceforge.net
* Copyright: Material in the public domain is not protected by copyright

Bean Validation API 3.0.0
Bean Validation API 3.0.2
* License: Apache License, 2.0
* Project: http://beanvalidation.org/1.1/
* Copyright: 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
Expand All @@ -65,7 +65,7 @@ jakarta.inject Version: 1
* License: Apache License, 2.0
* Copyright (C) 2009 The JSR-330 Expert Group

Javassist Version 3.29.0-GA
Javassist Version 3.29.2-GA
* License: Apache License, 2.0
* Project: http://www.javassist.org/
* Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@
<jersey.version>${project.version}</jersey.version>
<jetty.version>11.0.15</jetty.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<surefire.mvn.plugin.version>3.0.0-M7</surefire.mvn.plugin.version>
<surefire.mvn.plugin.version>3.1.2</surefire.mvn.plugin.version>
</properties>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@

<properties>
<jersey.version>${project.version}</jersey.version>
<junit-jupiter.version>5.9.1</junit-jupiter.version>
<junit-jupiter.version>5.9.3</junit-jupiter.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<surefire.mvn.plugin.version>3.0.0-M7</surefire.mvn.plugin.version>
<surefire.mvn.plugin.version>3.1.2</surefire.mvn.plugin.version>
</properties>
</project>
5 changes: 0 additions & 5 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@
<artifactId>jersey-jetty-connector</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-jetty-http2-connector</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-jdk-connector</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bundles/jaxrs-ri/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
<showWarnings>false</showWarnings>
<fork>false</fork>
<excludes>
<exclude>module-info.java</exclude>
<exclude>module-info.java</exclude><exclude>META-INF/versions/11/**</exclude>
</excludes>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2023 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
* 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.helidon.connector;

import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.HttpUrlConnectorProvider;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.ClientRequestContext;
import jakarta.ws.rs.client.ClientRequestFilter;
import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.Response;
import java.io.IOException;

// The Helidon jar has META-INF set
// Test of override
class MetaInfOverrideTest extends JerseyTest {

@Path("/origin")
public static class UserAgentServer {
@GET
public String get(@Context HttpHeaders headers) {
return headers.getHeaderString(HttpHeaders.USER_AGENT);
}
}

@Override
protected Application configure() {
return new ResourceConfig(UserAgentServer.class);
}

@Test
void defaultMetaInfTest() {
try (Response r = target("origin").request().get()) {
Assertions.assertEquals(200, r.getStatus());
Assertions.assertTrue(r.readEntity(String.class).contains("Helidon"));
}
}

@Test
void overrideMetaInfTest() {
ClientConfig config = new ClientConfig();
config.connectorProvider(new HttpUrlConnectorProvider());
try (Response r = ClientBuilder.newClient(config).target(target("origin").getUri()).request().get()) {
Assertions.assertEquals(200, r.getStatus());
r.bufferEntity();
System.out.println(r.readEntity(String.class));
Assertions.assertTrue(r.readEntity(String.class).contains("HttpUrlConnection"));
}
}

@Test
void overrideMetaInfByOtherConfigPropertyTest() {
ClientConfig config = new ClientConfig();
config.property(ClientProperties.CONNECTOR_PROVIDER, "org.glassfish.jersey.client.HttpUrlConnectorProvider");
try (Response r = ClientBuilder.newClient(config).target(target("origin").getUri()).request().get()) {
Assertions.assertEquals(200, r.getStatus());
r.bufferEntity();
System.out.println(r.readEntity(String.class));
Assertions.assertTrue(r.readEntity(String.class).contains("HttpUrlConnection"));
}
}

@Test
void overrideMetaInfByThePropertyTest() {
try (Response r = ClientBuilder.newBuilder()
.property(ClientProperties.CONNECTOR_PROVIDER, "org.glassfish.jersey.client.HttpUrlConnectorProvider")
.build()
.target(target("origin").getUri()).request().get()) {
Assertions.assertEquals(200, r.getStatus());
r.bufferEntity();
System.out.println(r.readEntity(String.class));
Assertions.assertTrue(r.readEntity(String.class).contains("HttpUrlConnection"));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023 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 Down Expand Up @@ -189,6 +189,9 @@ public int read() throws IOException {

if (content.isReadable()) {
content.retain();
if (nis == null) {
nis = new NettyInputStream();
}
nis.publish(content);
}

Expand Down
24 changes: 24 additions & 0 deletions containers/jetty-http2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,42 @@
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-server</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-conscrypt-server</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2023 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 @@ -24,6 +24,8 @@
import org.glassfish.jersey.internal.util.PropertiesHelper;
import org.glassfish.jersey.internal.util.PropertyAlias;

import jakarta.ws.rs.client.ClientBuilder;

/**
* Jersey client implementation configuration properties.
*
Expand Down Expand Up @@ -444,7 +446,7 @@ public final class ClientProperties {
EXPECT_100_CONTINUE_THRESHOLD_SIZE = "jersey.config.client.request.expect.100.continue.threshold.size";

/**
* Default threshold size (64kb) after which which Expect:100-Continue header would be applied before
* Default threshold size (64kb) after which Expect:100-Continue header would be applied before
* the main request.
*
* @since 2.32
Expand All @@ -463,6 +465,22 @@ public final class ClientProperties {
*/
public static final String QUERY_PARAM_STYLE = "jersey.config.client.uri.query.param.style";

/**
* Sets the {@link org.glassfish.jersey.client.spi.ConnectorProvider} class. Overrides the value from META-INF/services.
*
* <p>
* The value MUST be an instance of {@code String}.
* </p>
* <p>
* The property is recognized by {@link ClientBuilder}.
* </p>
* <p>
* The name of the configuration property is <tt>{@value}</tt>.
* </p>
* @since 2.40
*/
public static final String CONNECTOR_PROVIDER = "jersey.config.client.connector.provider";

private ClientProperties() {
// prevents instantiation
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2023 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 @@ -16,6 +16,7 @@

package org.glassfish.jersey.client;

import java.security.AccessController;
import java.security.KeyStore;
import java.util.Collections;
import java.util.LinkedList;
Expand All @@ -32,9 +33,13 @@
import javax.net.ssl.SSLContext;

import org.glassfish.jersey.SslConfigurator;
import org.glassfish.jersey.client.innate.inject.NonInjectionManager;
import org.glassfish.jersey.client.internal.LocalizationMessages;
import org.glassfish.jersey.client.spi.ClientBuilderListener;
import org.glassfish.jersey.client.spi.ConnectorProvider;
import org.glassfish.jersey.internal.ServiceFinder;
import org.glassfish.jersey.internal.config.ExternalPropertiesConfigurationFactory;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.UnsafeValue;
import org.glassfish.jersey.internal.util.collection.Values;
import org.glassfish.jersey.model.internal.RankedComparator;
Expand Down Expand Up @@ -186,6 +191,9 @@ public ClientBuilder readTimeout(long timeout, TimeUnit unit) {

@Override
public JerseyClient build() {
ExternalPropertiesConfigurationFactory.configure(this.config);
setConnectorFromProperties();

if (sslContext != null) {
return new JerseyClient(config, sslContext, hostnameVerifier, null);
} else if (sslConfigurator != null) {
Expand All @@ -204,6 +212,20 @@ public SSLContext get() {
}
}

private void setConnectorFromProperties() {
final Object connectorClass = config.getProperty(ClientProperties.CONNECTOR_PROVIDER);
if (connectorClass != null) {
if (String.class.isInstance(connectorClass)) {
Class<? extends ConnectorProvider> clazz
= AccessController.doPrivileged(ReflectionHelper.classForNamePA((String) connectorClass));
final ConnectorProvider connectorProvider = new NonInjectionManager().justCreate(clazz);
config.connectorProvider(connectorProvider);
} else {
throw new IllegalArgumentException();
}
}
}

@Override
public ClientConfig getConfiguration() {
return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.glassfish.jersey.client.innate.http;

import org.glassfish.jersey.client.internal.LocalizationMessages;

import javax.net.ssl.SNIHostName;
import javax.net.ssl.SNIServerName;
import javax.net.ssl.SSLEngine;
Expand All @@ -27,12 +29,14 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Logger;

/**
* A unified routines to set {@link SNIHostName} for the {@link javax.net.ssl.SSLContext}.
* To be reused in connectors.
*/
final class SniConfigurator {
private static final Logger LOGGER = Logger.getLogger(SniConfigurator.class.getName());
private final String hostName;
private SniConfigurator(String hostName) {
this.hostName = hostName;
Expand Down Expand Up @@ -85,6 +89,7 @@ void setServerNames(SSLEngine sslEngine) {
SSLParameters sslParameters = sslEngine.getSSLParameters();
updateSSLParameters(sslParameters);
sslEngine.setSSLParameters(sslParameters);
LOGGER.fine(LocalizationMessages.SNI_ON_SSLENGINE());
}

/**
Expand All @@ -95,6 +100,7 @@ void setServerNames(SSLSocket sslSocket) {
SSLParameters sslParameters = sslSocket.getSSLParameters();
updateSSLParameters(sslParameters);
sslSocket.setSSLParameters(sslParameters);
LOGGER.fine(LocalizationMessages.SNI_ON_SSLSOCKET());
}

private SSLParameters updateSSLParameters(SSLParameters sslParameters) {
Expand All @@ -103,6 +109,7 @@ private SSLParameters updateSSLParameters(SSLParameters sslParameters) {
serverNames.add(serverName);

sslParameters.setServerNames(serverNames);
LOGGER.finer(LocalizationMessages.SNI_UPDATE_SSLPARAMS(hostName));

return sslParameters;
}
Expand Down
Loading

0 comments on commit 3e235bd

Please sign in to comment.