Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.0' into 'origin/3.1'
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
  • Loading branch information
senivam committed Dec 19, 2024
2 parents 2bd5ba2 + e21d0d7 commit bb5d0b0
Show file tree
Hide file tree
Showing 34 changed files with 1,509 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
import java.net.Proxy;
import java.net.URL;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;

import jakarta.ws.rs.client.Client;
Expand Down Expand Up @@ -290,16 +287,12 @@ public interface ConnectionFactory {
* @throws java.io.IOException in case the connection cannot be provided.
*/
default HttpURLConnection getConnection(URL url, Proxy proxy) throws IOException {
synchronized (this){
return (proxy == null) ? getConnection(url) : (HttpURLConnection) url.openConnection(proxy);
}
return (proxy == null) ? getConnection(url) : (HttpURLConnection) url.openConnection(proxy);
}
}

private static class DefaultConnectionFactory implements ConnectionFactory {

private final ConcurrentHashMap<URL, Lock> locks = new ConcurrentHashMap<>();

@Override
public HttpURLConnection getConnection(final URL url) throws IOException {
return connect(url, null);
Expand All @@ -311,13 +304,7 @@ public HttpURLConnection getConnection(URL url, Proxy proxy) throws IOException
}

private HttpURLConnection connect(URL url, Proxy proxy) throws IOException {
Lock lock = locks.computeIfAbsent(url, u -> new ReentrantLock());
lock.lock();
try {
return (proxy == null) ? (HttpURLConnection) url.openConnection() : (HttpURLConnection) url.openConnection(proxy);
} finally {
lock.unlock();
}
return (proxy == null) ? (HttpURLConnection) url.openConnection() : (HttpURLConnection) url.openConnection(proxy);
}
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024 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,21 +20,29 @@
import org.glassfish.jersey.internal.util.LazyUid;
import org.glassfish.jersey.process.internal.RequestScope;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;

public class NonInjectionRequestScope extends RequestScope {

private final NonInjectionManager nonInjectionManager;

public NonInjectionRequestScope(NonInjectionManager nonInjectionManager) {
this.nonInjectionManager = nonInjectionManager;
}

@Override
public org.glassfish.jersey.process.internal.RequestContext createContext() {
return new Instance();
return new Instance(nonInjectionManager);
}

/**
* Implementation of the request scope instance.
*/
public static final class Instance implements org.glassfish.jersey.process.internal.RequestContext {

private final NonInjectionManager injectionManager;

private static final ExtendedLogger logger = new ExtendedLogger(Logger.getLogger(Instance.class.getName()), Level.FINEST);

/*
Expand All @@ -48,10 +56,11 @@ public static final class Instance implements org.glassfish.jersey.process.inter
/**
* Holds the number of snapshots of this scope.
*/
private final AtomicInteger referenceCounter;
private int referenceCounter;

private Instance() {
this.referenceCounter = new AtomicInteger(1);
private Instance(NonInjectionManager injectionManager) {
this.injectionManager = injectionManager;
this.referenceCounter = 1;
}

/**
Expand All @@ -65,7 +74,7 @@ private Instance() {
@Override
public NonInjectionRequestScope.Instance getReference() {
// TODO: replace counter with a phantom reference + reference queue-based solution
referenceCounter.incrementAndGet();
referenceCounter++;
return this;
}

Expand All @@ -77,7 +86,9 @@ public NonInjectionRequestScope.Instance getReference() {
*/
@Override
public void release() {
referenceCounter.decrementAndGet();
if (0 == --referenceCounter) {
injectionManager.disposeRequestScopedInstances();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class HttpUrlConnector implements Connector {
private static final String ALLOW_RESTRICTED_HEADERS_SYSTEM_PROPERTY = "sun.net.http.allowRestrictedHeaders";
// Avoid multi-thread uses of HttpsURLConnection.getDefaultSSLSocketFactory() because it does not implement a
// proper lazy-initialization. See https://github.com/jersey/jersey/issues/3293
private static final Value<SSLSocketFactory> DEFAULT_SSL_SOCKET_FACTORY =
private static final LazyValue<SSLSocketFactory> DEFAULT_SSL_SOCKET_FACTORY =
Values.lazy((Value<SSLSocketFactory>) () -> HttpsURLConnection.getDefaultSSLSocketFactory());
// The list of restricted headers is extracted from sun.net.www.protocol.http.HttpURLConnection
private static final String[] restrictedHeaders = {
Expand Down Expand Up @@ -387,6 +387,10 @@ private ClientResponse _apply(final ClientRequest request) throws IOException {
sniUri = request.getUri();
}

if (!DEFAULT_SSL_SOCKET_FACTORY.isInitialized() && "HTTPS".equalsIgnoreCase(sniUri.getScheme())) {
DEFAULT_SSL_SOCKET_FACTORY.get();
}

proxy.ifPresent(clientProxy -> ClientProxy.setBasicAuthorizationHeader(request.getHeaders(), proxy.get()));
uc = this.connectionFactory.getConnection(sniUri.toURL(), proxy.isPresent() ? proxy.get().proxy() : null);
uc.setDoInput(true);
Expand Down
20 changes: 14 additions & 6 deletions core-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@

<profile>
<id>securityOff</id>
<activation>
<jdk>[24,)</jdk>
</activation>
<properties>
<surefire.security.argline />
</properties>
Expand All @@ -426,12 +429,17 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/SecurityManagerConfiguredTest.java</exclude>
<exclude>**/ReflectionHelperTest.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>default-test</id>
<configuration>
<excludes>
<exclude>**/SecurityManagerConfiguredTest.java</exclude>
<exclude>**/ReflectionHelperTest.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2024 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 @@ -30,11 +30,14 @@

public class ExternalPropertiesConfigurationFactoryTest {

private static boolean isSecurityManager;

/**
* Predefine some properties to be read from config
*/
@BeforeAll
public static void setUp() {
isSecurityManager = System.getSecurityManager() != null;
System.setProperty(CommonProperties.ALLOW_SYSTEM_PROPERTIES_PROVIDER, Boolean.TRUE.toString());

System.setProperty("jersey.config.server.provider.scanning.recursive", "PASSED");
Expand All @@ -53,7 +56,11 @@ public static void tearDown() {
public void readSystemPropertiesTest() {
final Object result =
readExternalPropertiesMap().get("jersey.config.server.provider.scanning.recursive");
Assertions.assertNull(result);
if (isSecurityManager) {
Assertions.assertNull(result);
} else {
Assertions.assertEquals("PASSED", result);
}
Assertions.assertEquals(Boolean.TRUE,
getConfig().isProperty(CommonProperties.JSON_PROCESSING_FEATURE_DISABLE));
Assertions.assertEquals(Boolean.TRUE,
Expand Down Expand Up @@ -81,8 +88,11 @@ public void mergePropertiesTest() {
inputProperties.put("org.jersey.microprofile.config.added", "ADDED");
getConfig().mergeProperties(inputProperties);
final Object result = readExternalPropertiesMap().get("jersey.config.server.provider.scanning.recursive");
Assertions.assertNull(result);
Assertions.assertNull(readExternalPropertiesMap().get("org.jersey.microprofile.config.added"));
final Object resultAdded = readExternalPropertiesMap().get("org.jersey.microprofile.config.added");
if (isSecurityManager) {
Assertions.assertNull(result);
Assertions.assertNull(resultAdded);
}
}

}
3 changes: 3 additions & 0 deletions core-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@
<profiles>
<profile>
<id>securityOff</id>
<activation>
<jdk>[24,)</jdk>
</activation>
<properties>
<surefire.security.argline />
</properties>
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, 2024 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 @@ -40,6 +40,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

public class ParamConverterDateTest extends AbstractTest {
private final String format = "EEE MMM dd HH:mm:ss Z yyyy";
private final SimpleDateFormat formatter = new SimpleDateFormat(format, new Locale("US"));

@Path("/")
public static class DateResource {
Expand All @@ -55,7 +57,7 @@ public String doGet(@QueryParam("d") final Date d) {
public void testDateResource() throws ExecutionException, InterruptedException {
initiateWebApplication(getBinder(), ParamConverterDateTest.DateResource.class);
final ContainerResponse responseContext = getResponseContext(UriBuilder.fromPath("/")
.queryParam("d", new Date()).build().toString());
.queryParam("d", formatter.format(new Date())).build().toString());

assertEquals(200, responseContext.getStatus());
}
Expand All @@ -80,8 +82,6 @@ public T fromString(final String value) {
);
}
try {
final String format = "EEE MMM dd HH:mm:ss Z yyyy";
final SimpleDateFormat formatter = new SimpleDateFormat(format, new Locale("US"));
return rawType.cast(formatter.parse(value));
} catch (final ParseException ex) {
throw new ExtractorException(ex);
Expand Down
Loading

0 comments on commit bb5d0b0

Please sign in to comment.