Skip to content

Commit 7d7998d

Browse files
authored
Merge pull request #4958 from senivam/31_merged
merge actual master into 3.1
2 parents 37d112c + ad11709 commit 7d7998d

File tree

5 files changed

+57
-16
lines changed

5 files changed

+57
-16
lines changed

core-common/src/main/java/org/glassfish/jersey/internal/util/ReflectionHelper.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2022 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
@@ -56,7 +56,9 @@
5656
import org.glassfish.jersey.internal.LocalizationMessages;
5757
import org.glassfish.jersey.internal.OsgiRegistry;
5858
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
59-
59+
import org.glassfish.jersey.internal.util.collection.LazyValue;
60+
import org.glassfish.jersey.internal.util.collection.Value;
61+
import org.glassfish.jersey.internal.util.collection.Values;
6062
import org.osgi.framework.Bundle;
6163
import org.osgi.framework.FrameworkUtil;
6264

@@ -1469,22 +1471,25 @@ private static boolean checkTypeBounds(final Class type, final Type[] bounds) {
14691471

14701472
private static final Class<?> bundleReferenceClass = AccessController.doPrivileged(
14711473
classForNamePA("org.osgi.framework.BundleReference", null));
1472-
1473-
/**
1474-
* Returns an {@link OsgiRegistry} instance.
1475-
*
1476-
* @return an {@link OsgiRegistry} instance or {@code null} if the class cannot be instantiated (not in OSGi environment).
1477-
*/
1478-
public static OsgiRegistry getOsgiRegistryInstance() {
1474+
private static final LazyValue<Object> osgiInstance = Values.lazy((Value<Object>) () -> {
14791475
try {
14801476
if (bundleReferenceClass != null) {
14811477
return OsgiRegistry.getInstance();
14821478
}
1483-
} catch (final Exception e) {
1479+
} catch (final Throwable e) {
14841480
// Do nothing - instance is null.
14851481
}
14861482

14871483
return null;
1484+
});
1485+
1486+
/**
1487+
* Returns an {@link OsgiRegistry} instance.
1488+
*
1489+
* @return an {@link OsgiRegistry} instance or {@code null} if the class cannot be instantiated (not in OSGi environment).
1490+
*/
1491+
public static OsgiRegistry getOsgiRegistryInstance() {
1492+
return (OsgiRegistry) osgiInstance.get();
14881493
}
14891494

14901495
/**

examples/osgi-helloworld-webapp/functional-test/src/test/java/org/glassfish/jersey/examples/helloworld/test/AbstractWebAppTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2022 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 Distribution License v. 1.0, which is available at
@@ -122,6 +122,11 @@ public List<Option> genericOsgiOptions() {
122122

123123
// do not remove the following line
124124
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("FINEST"),
125+
126+
JdkVersion.getJdkVersion().getMajor() > 16
127+
? vmOption("--add-opens=java.base/java.net=ALL-UNNAMED")
128+
: null,
129+
125130
// uncomment the following 4 lines should you need to debug from th felix console
126131
// mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.gogo.runtime").version(gogoVersion),
127132
// mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.gogo.shell").version(gogoVersion),

examples/osgi-http-service/functional-test/src/test/java/org/glassfish/jersey/examples/osgihttpservice/test/AbstractHttpServiceTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2022 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 Distribution License v. 1.0, which is available at
@@ -47,6 +47,7 @@
4747
import static org.ops4j.pax.exam.CoreOptions.options;
4848
import static org.ops4j.pax.exam.CoreOptions.systemPackage;
4949
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
50+
import static org.ops4j.pax.exam.CoreOptions.vmOption;
5051

5152
/**
5253
* @author Jakub Podlesak
@@ -90,6 +91,10 @@ public List<Option> genericOsgiOptions() {
9091
systemProperty(JAXRS_RUNTIME_DELEGATE_PROPERTY).value("org.glassfish.jersey.internal.RuntimeDelegateImpl"),
9192
systemProperty(JAXRS_CLIENT_BUILDER).value("org.glassfish.jersey.client.JerseyClientBuilder"),
9293

94+
JdkVersion.getJdkVersion().getMajor() > 16
95+
? vmOption("--add-opens=java.base/java.net=ALL-UNNAMED")
96+
: null,
97+
9398
// do not remove the following line
9499
// systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("FINEST"),
95100

ext/microprofile/mp-config/pom.xml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright (c) 2019, 2021 Oracle and/or its affiliates. All rights reserved.
4+
Copyright (c) 2019, 2022 Oracle and/or its affiliates. All rights reserved.
55
66
This program and the accompanying materials are made available under the
77
terms of the Eclipse Public License v. 2.0, which is available at
@@ -83,5 +83,27 @@
8383
</dependency>
8484

8585
</dependencies>
86+
<build>
87+
<plugins>
88+
<plugin>
89+
<groupId>org.apache.felix</groupId>
90+
<artifactId>maven-bundle-plugin</artifactId>
91+
<inherited>true</inherited>
92+
<extensions>true</extensions>
93+
<configuration>
94+
<instructions>
95+
<Export-Package>
96+
org.glassfish.jersey.microprofile.config.*;version=${project.version}
97+
</Export-Package>
98+
<Import-Package>
99+
org.eclipse.microprofile.config.*;version="!",
100+
*
101+
</Import-Package>
102+
</instructions>
103+
<unpackBundle>true</unpackBundle>
104+
</configuration>
105+
</plugin>
106+
</plugins>
107+
</build>
86108

87109
</project>

tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/PackageScanningTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2022 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
@@ -27,6 +27,8 @@
2727

2828
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
2929
import org.glassfish.jersey.grizzly2.servlet.GrizzlyWebContainerFactory;
30+
import org.glassfish.jersey.internal.Version;
31+
import org.glassfish.jersey.internal.util.JdkVersion;
3032
import org.glassfish.jersey.osgi.test.util.Helper;
3133
import org.glassfish.jersey.server.ResourceConfig;
3234
import org.glassfish.jersey.server.ServerProperties;
@@ -41,10 +43,9 @@
4143
import org.ops4j.pax.exam.junit.PaxExam;
4244
import static org.junit.Assert.assertEquals;
4345
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
46+
import static org.ops4j.pax.exam.CoreOptions.vmOption;
4447

4548
/**
46-
* NOTE: This test is excluded on JDK6 as it requires Servlet 3.1 API that is built against JDK 7.
47-
*
4849
* @author Jakub Podlesak
4950
* @author Michal Gajdos
5051
*/
@@ -64,6 +65,9 @@ public static Option[] configuration() {
6465

6566
options.addAll(Helper.expandedList(
6667
// vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
68+
JdkVersion.getJdkVersion().getMajor() > 16
69+
? vmOption("--add-opens=java.base/java.net=ALL-UNNAMED")
70+
: null,
6771

6872
mavenBundle().groupId("org.glassfish.jersey.media").artifactId("jersey-media-sse").versionAsInProject(),
6973

0 commit comments

Comments
 (0)