Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge of the actual 3.0 into the 3.1 #5824

Merged
merged 12 commits into from
Dec 20, 2024
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
12 changes: 11 additions & 1 deletion examples/groovy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</exclusion>
<exclusion>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
</exclusion>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
Expand Down Expand Up @@ -117,10 +125,12 @@
<goal>removeTestStubs</goal>
<goal>groovydoc</goal>
</goals>
<configuration>
<targetBytecode>11</targetBytecode>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
Expand Down
21 changes: 13 additions & 8 deletions examples/osgi-helloworld-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@
<name>jersey-examples-osgi-helloworld-webapp</name>
<packaging>pom</packaging>

<modules>
<module>war-bundle</module>
<module>functional-test</module>
<module>lib-bundle</module>
<module>additional-bundle</module>
<module>alternate-version-bundle</module>
</modules>

<profiles>
<profile>
<id>securityOn</id>
<activation>
<jdk>[11,24)</jdk>
</activation>
<modules>
<module>war-bundle</module>
<module>functional-test</module>
<module>lib-bundle</module>
<module>additional-bundle</module>
<module>alternate-version-bundle</module>
</modules>
</profile>
<profile>
<id>pre-release</id>
<build>
Expand Down
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) 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 @@ -65,7 +65,7 @@ public void onEvent(RequestEvent event) {

switch (event.getType()) {
case ON_EXCEPTION:
if (!isNotFoundException(event)) {
if (!isClientError(event) || observations.get(containerRequest) != null) {
break;
}
startObservation(event);
Expand Down Expand Up @@ -102,13 +102,14 @@ private void startObservation(RequestEvent event) {
observations.put(event.getContainerRequest(), new ObservationScopeAndContext(scope, jerseyContext));
}

private boolean isNotFoundException(RequestEvent event) {
private boolean isClientError(RequestEvent event) {
Throwable t = event.getException();
if (t == null) {
return false;
}
String className = t.getClass().getCanonicalName();
return className.equals("jakarta.ws.rs.NotFoundException") || className.equals("jakarta.ws.rs.NotFoundException");
String className = t.getClass().getSuperclass().getCanonicalName();
return className.equals("jakarta.ws.rs.ClientErrorException")
|| className.equals("javax.ws.rs.ClientErrorException");
}

private static class ObservationScopeAndContext {
Expand Down
Loading
Loading