Skip to content

Commit 804fada

Browse files
committed
Merge remote-tracking branch 'origin/2.x' into 'origin/3.0'
Signed-off-by: Maxim Nesen <[email protected]>
2 parents 6ab1ad1 + c312e20 commit 804fada

File tree

32 files changed

+1292
-156
lines changed

32 files changed

+1292
-156
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

+162-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
@@ -846,6 +846,9 @@
846846

847847
<profile>
848848
<id>securityOff</id>
849+
<activation>
850+
<jdk>[24,)</jdk>
851+
</activation>
849852
<properties>
850853
<surefire.security.argline />
851854
</properties>
@@ -854,12 +857,17 @@
854857
<plugin>
855858
<groupId>org.apache.maven.plugins</groupId>
856859
<artifactId>maven-surefire-plugin</artifactId>
857-
<configuration>
858-
<excludes>
859-
<exclude>**/SecurityManagerConfiguredTest.java</exclude>
860-
<exclude>**/ReflectionHelperTest.java</exclude>
861-
</excludes>
862-
</configuration>
860+
<executions>
861+
<execution>
862+
<id>default-test</id>
863+
<configuration>
864+
<excludes>
865+
<exclude>**/SecurityManagerConfiguredTest.java</exclude>
866+
<exclude>**/ReflectionHelperTest.java</exclude>
867+
</excludes>
868+
</configuration>
869+
</execution>
870+
</executions>
863871
</plugin>
864872
</plugins>
865873
</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
@@ -264,6 +264,9 @@
264264
</profile>
265265
<profile>
266266
<id>securityOff</id>
267+
<activation>
268+
<jdk>[24,)</jdk>
269+
</activation>
267270
<properties>
268271
<surefire.security.argline />
269272
</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);

examples/groovy/pom.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@
117117
<goal>removeTestStubs</goal>
118118
<goal>groovydoc</goal>
119119
</goals>
120+
<configuration>
121+
<targetBytecode>11</targetBytecode>
122+
</configuration>
120123
</execution>
121124
</executions>
122125
</plugin>
123-
124126
<plugin>
125127
<groupId>org.apache.maven.plugins</groupId>
126128
<artifactId>maven-antrun-plugin</artifactId>

examples/osgi-helloworld-webapp/pom.xml

+13-8
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,20 @@
2525
<name>jersey-examples-osgi-helloworld-webapp</name>
2626
<packaging>pom</packaging>
2727

28-
<modules>
29-
<module>war-bundle</module>
30-
<module>functional-test</module>
31-
<module>lib-bundle</module>
32-
<module>additional-bundle</module>
33-
<module>alternate-version-bundle</module>
34-
</modules>
35-
3628
<profiles>
29+
<profile>
30+
<id>securityOn</id>
31+
<activation>
32+
<jdk>[1.8,24)</jdk>
33+
</activation>
34+
<modules>
35+
<module>war-bundle</module>
36+
<module>functional-test</module>
37+
<module>lib-bundle</module>
38+
<module>additional-bundle</module>
39+
<module>alternate-version-bundle</module>
40+
</modules>
41+
</profile>
3742
<profile>
3843
<id>pre-release</id>
3944
<build>

examples/pom.xml

+9-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
<!--<module>feed-combiner-java8-webapp</module>-->
7171
<module>freemarker-webapp</module>
7272
<!--<module>flight-mgmt-webapp</module>-->
73-
<module>groovy</module>
7473
<module>helloworld</module>
7574
<module>helloworld-benchmark</module>
7675
<module>helloworld-cdi2-se</module>
@@ -278,8 +277,16 @@
278277
</resource>
279278
</resources>
280279
</build>
281-
282280
<profiles>
281+
<profile>
282+
<id>GROOVY-EXAMPLE</id>
283+
<activation>
284+
<jdk>[11,)</jdk>
285+
</activation>
286+
<modules>
287+
<module>groovy</module>
288+
</modules>
289+
</profile>
283290
<profile>
284291
<id>jdk17</id>
285292
<activation>

ext/micrometer/src/main/java/org/glassfish/jersey/micrometer/server/ObservationRequestEventListener.java

+6-5
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) 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
@@ -65,7 +65,7 @@ public void onEvent(RequestEvent event) {
6565

6666
switch (event.getType()) {
6767
case ON_EXCEPTION:
68-
if (!isNotFoundException(event)) {
68+
if (!isClientError(event) || observations.get(containerRequest) != null) {
6969
break;
7070
}
7171
startObservation(event);
@@ -102,13 +102,14 @@ private void startObservation(RequestEvent event) {
102102
observations.put(event.getContainerRequest(), new ObservationScopeAndContext(scope, jerseyContext));
103103
}
104104

105-
private boolean isNotFoundException(RequestEvent event) {
105+
private boolean isClientError(RequestEvent event) {
106106
Throwable t = event.getException();
107107
if (t == null) {
108108
return false;
109109
}
110-
String className = t.getClass().getCanonicalName();
111-
return className.equals("jakarta.ws.rs.NotFoundException") || className.equals("jakarta.ws.rs.NotFoundException");
110+
String className = t.getClass().getSuperclass().getCanonicalName();
111+
return className.equals("jakarta.ws.rs.ClientErrorException")
112+
|| className.equals("javax.ws.rs.ClientErrorException");
112113
}
113114

114115
private static class ObservationScopeAndContext {

0 commit comments

Comments
 (0)