Skip to content

Commit bb5d0b0

Browse files
committed
Merge remote-tracking branch 'origin/3.0' into 'origin/3.1'
Signed-off-by: Maxim Nesen <[email protected]>
2 parents 2bd5ba2 + e21d0d7 commit bb5d0b0

File tree

34 files changed

+1509
-157
lines changed

34 files changed

+1509
-157
lines changed

core-client/src/main/java/org/glassfish/jersey/client/HttpUrlConnectorProvider.java

+2-15
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
import java.net.Proxy;
2222
import java.net.URL;
2323
import java.util.Map;
24-
import java.util.concurrent.ConcurrentHashMap;
25-
import java.util.concurrent.locks.Lock;
26-
import java.util.concurrent.locks.ReentrantLock;
2724
import java.util.logging.Logger;
2825

2926
import jakarta.ws.rs.client.Client;
@@ -290,16 +287,12 @@ public interface ConnectionFactory {
290287
* @throws java.io.IOException in case the connection cannot be provided.
291288
*/
292289
default HttpURLConnection getConnection(URL url, Proxy proxy) throws IOException {
293-
synchronized (this){
294-
return (proxy == null) ? getConnection(url) : (HttpURLConnection) url.openConnection(proxy);
295-
}
290+
return (proxy == null) ? getConnection(url) : (HttpURLConnection) url.openConnection(proxy);
296291
}
297292
}
298293

299294
private static class DefaultConnectionFactory implements ConnectionFactory {
300295

301-
private final ConcurrentHashMap<URL, Lock> locks = new ConcurrentHashMap<>();
302-
303296
@Override
304297
public HttpURLConnection getConnection(final URL url) throws IOException {
305298
return connect(url, null);
@@ -311,13 +304,7 @@ public HttpURLConnection getConnection(URL url, Proxy proxy) throws IOException
311304
}
312305

313306
private HttpURLConnection connect(URL url, Proxy proxy) throws IOException {
314-
Lock lock = locks.computeIfAbsent(url, u -> new ReentrantLock());
315-
lock.lock();
316-
try {
317-
return (proxy == null) ? (HttpURLConnection) url.openConnection() : (HttpURLConnection) url.openConnection(proxy);
318-
} finally {
319-
lock.unlock();
320-
}
307+
return (proxy == null) ? (HttpURLConnection) url.openConnection() : (HttpURLConnection) url.openConnection(proxy);
321308
}
322309
}
323310

core-client/src/main/java/org/glassfish/jersey/client/innate/inject/NonInjectionManager.java

+161-91
Large diffs are not rendered by default.

core-client/src/main/java/org/glassfish/jersey/client/innate/inject/NonInjectionRequestScope.java

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -20,21 +20,29 @@
2020
import org.glassfish.jersey.internal.util.LazyUid;
2121
import org.glassfish.jersey.process.internal.RequestScope;
2222

23-
import java.util.concurrent.atomic.AtomicInteger;
2423
import java.util.logging.Level;
2524
import java.util.logging.Logger;
2625

2726
public class NonInjectionRequestScope extends RequestScope {
27+
28+
private final NonInjectionManager nonInjectionManager;
29+
30+
public NonInjectionRequestScope(NonInjectionManager nonInjectionManager) {
31+
this.nonInjectionManager = nonInjectionManager;
32+
}
33+
2834
@Override
2935
public org.glassfish.jersey.process.internal.RequestContext createContext() {
30-
return new Instance();
36+
return new Instance(nonInjectionManager);
3137
}
3238

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

44+
private final NonInjectionManager injectionManager;
45+
3846
private static final ExtendedLogger logger = new ExtendedLogger(Logger.getLogger(Instance.class.getName()), Level.FINEST);
3947

4048
/*
@@ -48,10 +56,11 @@ public static final class Instance implements org.glassfish.jersey.process.inter
4856
/**
4957
* Holds the number of snapshots of this scope.
5058
*/
51-
private final AtomicInteger referenceCounter;
59+
private int referenceCounter;
5260

53-
private Instance() {
54-
this.referenceCounter = new AtomicInteger(1);
61+
private Instance(NonInjectionManager injectionManager) {
62+
this.injectionManager = injectionManager;
63+
this.referenceCounter = 1;
5564
}
5665

5766
/**
@@ -65,7 +74,7 @@ private Instance() {
6574
@Override
6675
public NonInjectionRequestScope.Instance getReference() {
6776
// TODO: replace counter with a phantom reference + reference queue-based solution
68-
referenceCounter.incrementAndGet();
77+
referenceCounter++;
6978
return this;
7079
}
7180

@@ -77,7 +86,9 @@ public NonInjectionRequestScope.Instance getReference() {
7786
*/
7887
@Override
7988
public void release() {
80-
referenceCounter.decrementAndGet();
89+
if (0 == --referenceCounter) {
90+
injectionManager.disposeRequestScopedInstances();
91+
}
8192
}
8293

8394
@Override

core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java

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

390+
if (!DEFAULT_SSL_SOCKET_FACTORY.isInitialized() && "HTTPS".equalsIgnoreCase(sniUri.getScheme())) {
391+
DEFAULT_SSL_SOCKET_FACTORY.get();
392+
}
393+
390394
proxy.ifPresent(clientProxy -> ClientProxy.setBasicAuthorizationHeader(request.getHeaders(), proxy.get()));
391395
uc = this.connectionFactory.getConnection(sniUri.toURL(), proxy.isPresent() ? proxy.get().proxy() : null);
392396
uc.setDoInput(true);

core-common/pom.xml

+14-6
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@
418418

419419
<profile>
420420
<id>securityOff</id>
421+
<activation>
422+
<jdk>[24,)</jdk>
423+
</activation>
421424
<properties>
422425
<surefire.security.argline />
423426
</properties>
@@ -426,12 +429,17 @@
426429
<plugin>
427430
<groupId>org.apache.maven.plugins</groupId>
428431
<artifactId>maven-surefire-plugin</artifactId>
429-
<configuration>
430-
<excludes>
431-
<exclude>**/SecurityManagerConfiguredTest.java</exclude>
432-
<exclude>**/ReflectionHelperTest.java</exclude>
433-
</excludes>
434-
</configuration>
432+
<executions>
433+
<execution>
434+
<id>default-test</id>
435+
<configuration>
436+
<excludes>
437+
<exclude>**/SecurityManagerConfiguredTest.java</exclude>
438+
<exclude>**/ReflectionHelperTest.java</exclude>
439+
</excludes>
440+
</configuration>
441+
</execution>
442+
</executions>
435443
</plugin>
436444
</plugins>
437445
</build>

core-common/src/test/java/org/glassfish/jersey/internal/config/ExternalPropertiesConfigurationFactoryTest.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -30,11 +30,14 @@
3030

3131
public class ExternalPropertiesConfigurationFactoryTest {
3232

33+
private static boolean isSecurityManager;
34+
3335
/**
3436
* Predefine some properties to be read from config
3537
*/
3638
@BeforeAll
3739
public static void setUp() {
40+
isSecurityManager = System.getSecurityManager() != null;
3841
System.setProperty(CommonProperties.ALLOW_SYSTEM_PROPERTIES_PROVIDER, Boolean.TRUE.toString());
3942

4043
System.setProperty("jersey.config.server.provider.scanning.recursive", "PASSED");
@@ -53,7 +56,11 @@ public static void tearDown() {
5356
public void readSystemPropertiesTest() {
5457
final Object result =
5558
readExternalPropertiesMap().get("jersey.config.server.provider.scanning.recursive");
56-
Assertions.assertNull(result);
59+
if (isSecurityManager) {
60+
Assertions.assertNull(result);
61+
} else {
62+
Assertions.assertEquals("PASSED", result);
63+
}
5764
Assertions.assertEquals(Boolean.TRUE,
5865
getConfig().isProperty(CommonProperties.JSON_PROCESSING_FEATURE_DISABLE));
5966
Assertions.assertEquals(Boolean.TRUE,
@@ -81,8 +88,11 @@ public void mergePropertiesTest() {
8188
inputProperties.put("org.jersey.microprofile.config.added", "ADDED");
8289
getConfig().mergeProperties(inputProperties);
8390
final Object result = readExternalPropertiesMap().get("jersey.config.server.provider.scanning.recursive");
84-
Assertions.assertNull(result);
85-
Assertions.assertNull(readExternalPropertiesMap().get("org.jersey.microprofile.config.added"));
91+
final Object resultAdded = readExternalPropertiesMap().get("org.jersey.microprofile.config.added");
92+
if (isSecurityManager) {
93+
Assertions.assertNull(result);
94+
Assertions.assertNull(resultAdded);
95+
}
8696
}
8797

8898
}

core-server/pom.xml

+3
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@
260260
<profiles>
261261
<profile>
262262
<id>securityOff</id>
263+
<activation>
264+
<jdk>[24,)</jdk>
265+
</activation>
263266
<properties>
264267
<surefire.security.argline />
265268
</properties>

core-server/src/test/java/org/glassfish/jersey/server/internal/inject/ParamConverterDateTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -40,6 +40,8 @@
4040
import static org.junit.jupiter.api.Assertions.assertEquals;
4141

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

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

6062
assertEquals(200, responseContext.getStatus());
6163
}
@@ -80,8 +82,6 @@ public T fromString(final String value) {
8082
);
8183
}
8284
try {
83-
final String format = "EEE MMM dd HH:mm:ss Z yyyy";
84-
final SimpleDateFormat formatter = new SimpleDateFormat(format, new Locale("US"));
8585
return rawType.cast(formatter.parse(value));
8686
} catch (final ParseException ex) {
8787
throw new ExtractorException(ex);

0 commit comments

Comments
 (0)