Skip to content

Commit

Permalink
merge of the actual 2.x into the 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
senivam authored Dec 19, 2024
2 parents 6ab1ad1 + f16b653 commit e21d0d7
Show file tree
Hide file tree
Showing 34 changed files with 1,359 additions and 165 deletions.
25 changes: 18 additions & 7 deletions bundles/examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,6 @@
<classifier>gf-project-src</classifier>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.examples</groupId>
<artifactId>groovy</artifactId>
<version>${project.version}</version>
<classifier>project-src</classifier>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.examples</groupId>
<artifactId>helloworld</artifactId>
Expand Down Expand Up @@ -736,4 +729,22 @@
</plugins>
</build>

<profiles>
<profile>
<id>groovy_jdk_11</id>
<activation>
<jdk>[11,)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.examples</groupId>
<artifactId>groovy</artifactId>
<version>${project.version}</version>
<classifier>project-src</classifier>
<type>zip</type>
</dependency>
</dependencies>
</profile>
</profiles>

</project>
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 @@ -846,6 +846,9 @@

<profile>
<id>securityOff</id>
<activation>
<jdk>[24,)</jdk>
</activation>
<properties>
<surefire.security.argline />
</properties>
Expand All @@ -854,12 +857,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 @@ -264,6 +264,9 @@
</profile>
<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>[1.8,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
11 changes: 9 additions & 2 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
<!--<module>feed-combiner-java8-webapp</module>-->
<module>freemarker-webapp</module>
<!--<module>flight-mgmt-webapp</module>-->
<module>groovy</module>
<module>helloworld</module>
<module>helloworld-benchmark</module>
<module>helloworld-cdi2-se</module>
Expand Down Expand Up @@ -278,8 +277,16 @@
</resource>
</resources>
</build>

<profiles>
<profile>
<id>GROOVY-EXAMPLE</id>
<activation>
<jdk>[11,)</jdk>
</activation>
<modules>
<module>groovy</module>
</modules>
</profile>
<profile>
<id>jdk17</id>
<activation>
Expand Down
Loading

0 comments on commit e21d0d7

Please sign in to comment.