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

Make JAX-B API optional #4634

Merged
merged 2 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions bundles/jaxrs-ri/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,21 @@
javax.persistence.*;resolution:=optional,
javax.validation.*;resolution:=optional;version="${range;[==,3);${javax.validation.api.version}}",
sun.misc.*;resolution:=optional,
javax.activation.*;version="!";resolution:=optional,
javax.imageio;resolution:=optional,
javax.imageio.spi;resolution:=optional,
javax.imageio.stream;resolution:=optional,
javax.xml.bind;version="!";resolution:=optional,
javax.xml.bind.annotation;version="!";resolution:=optional,
javax.xml.bind.annotation.adapters;version="!";resolution:=optional,
javax.xml.namespace;resolution:=optional,
javax.xml.parsers;resolution:=optional,
javax.xml.transform;resolution:=optional,
javax.xml.transform.dom;resolution:=optional,
javax.xml.transform.sax;resolution:=optional,
javax.xml.transform.stream;resolution:=optional,
org.w3c.dom;resolution:=optional,
org.xml.sax;resolution:=optional,
${hk2.osgi.version},
*
]]></Import-Package>
Expand Down
8 changes: 7 additions & 1 deletion connectors/jetty-connector/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--

Copyright (c) 2011, 2019 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2011, 2020 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 @@ -41,6 +41,12 @@
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
</dependency>
<dependency>
senivam marked this conversation as resolved.
Show resolved Hide resolved
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
Expand Down
19 changes: 17 additions & 2 deletions core-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,21 @@
<!-- Note: When you're changing these properties change them also in bundles/jaxrs-ri/pom.xml. -->
<Import-Package>
sun.misc.*;resolution:=optional,
javax.activation.*;version="!",
javax.activation.*;version="!";resolution:=optional,
javax.imageio;resolution:=optional,
javax.imageio.spi;resolution:=optional,
javax.imageio.stream;resolution:=optional,
javax.xml.bind;version="!";resolution:=optional,
javax.xml.bind.annotation;version="!";resolution:=optional,
javax.xml.bind.annotation.adapters;version="!";resolution:=optional,
javax.xml.namespace;resolution:=optional,
javax.xml.parsers;resolution:=optional,
javax.xml.transform;resolution:=optional,
javax.xml.transform.dom;resolution:=optional,
javax.xml.transform.sax;resolution:=optional,
javax.xml.transform.stream;resolution:=optional,
org.w3c.dom;resolution:=optional,
org.xml.sax;resolution:=optional,
${javax.annotation.osgi.version},
*
</Import-Package>
Expand Down Expand Up @@ -297,6 +311,8 @@
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>jakarta.activation</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
</dependencies>
<build>
Expand Down Expand Up @@ -686,7 +702,6 @@
</plugins>
</build>
</profile>

</profiles>

<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020 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 @@ -230,13 +230,15 @@ public final class CommonProperties {
* Disable some of the default providers from being loaded. The following providers extend application footprint
* by XML dependencies, which is too heavy for native image, or by AWT which may possibly be not available by JDK 11 desktop:
* <ul>
* <li>javax.activation.DataSource</li>
* <li>java.awt.image.RenderedImage</li>
* <li>javax.xml.transform.Source</li>
* <li>javax.xml.transform.dom.DOMSource</li>
* <li>javax.xml.transform.sax.SAXSource</li>
* <li>javax.xml.transform.stream.StreamSource</li>
* </ul>
* The following are the options to disable the provides: {@code DOMSOURCE, RENDEREDIMAGE, SAXSOURCE, SOURCE, STREAMSOURCE},
* The following are the options to disable the provides:
* {@code DATASOURCE, DOMSOURCE, RENDEREDIMAGE, SAXSOURCE, SOURCE, STREAMSOURCE},
* or to disable all: {@code ALL}. Multiple options can be disabled by adding multiple comma separated values.
*
* @since 2.30
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2020 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 @@ -1557,4 +1557,20 @@ public static Class<?> getRawClass(Type type) {

return null;
}

/**
* Returns true iff JAX-B API is available on classpath.
*/
public static boolean isJaxbAvailable() {
final Class<?> aClass = AccessController.doPrivileged(ReflectionHelper.classForNamePA("javax.xml.bind.JAXBException"));
return aClass != null;
}

/**
* Returns true iff javax.xml.transform package is available on classpath.
*/
public static boolean isXmlTransformAvailable() {
final Class<?> aClass = AccessController.doPrivileged(ReflectionHelper.classForNamePA("javax.xml.transform.Source"));
return aClass != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected void configure() {

// Message body providers (both readers & writers)
bindSingletonWorker(ByteArrayProvider.class);
bindSingletonWorker(DataSourceProvider.class);
// bindSingletonWorker(DataSourceProvider.class);
bindSingletonWorker(FileProvider.class);
bindSingletonWorker(FormMultivaluedMapProvider.class);
bindSingletonWorker(FormProvider.class);
Expand Down Expand Up @@ -158,6 +158,7 @@ public Set<HeaderDelegateProvider> getHeaderDelegateProviders() {

private static final class EnabledProvidersBinder {
private enum Provider {
DATASOURCE("javax.activation.DataSource"),
DOMSOURCE("javax.xml.transform.dom.DOMSource"),
RENDEREDIMAGE("java.awt.image.RenderedImage"),
SAXSOURCE("javax.xml.transform.sax.SAXSource"),
Expand Down Expand Up @@ -200,6 +201,9 @@ private void bindToBinder(AbstractBinder binder) {
for (Provider provider : enabledProviders) {
if (isClass(provider.className)) {
switch (provider) {
case DATASOURCE:
providerBinder = new DataSourceBinder();
break;
case DOMSOURCE:
providerBinder = new DomSourceBinder();
break;
Expand All @@ -226,6 +230,7 @@ private void bindToBinder(AbstractBinder binder) {
"MessageBodyReader<" + provider.className + ">")
);
break;
case DATASOURCE:
case RENDEREDIMAGE:
case SOURCE:
LOGGER.warning(LocalizationMessages.DEPENDENT_CLASS_OF_DEFAULT_PROVIDER_NOT_FOUND(provider.className,
Expand All @@ -241,11 +246,18 @@ private static boolean isClass(String className) {
return null != AccessController.doPrivileged(ReflectionHelper.classForNamePA(className));
}


private interface ProviderBinder {
void bind(AbstractBinder binder, Provider provider);
}

private static class DataSourceBinder implements ProviderBinder {
@Override
public void bind(AbstractBinder binder, Provider provider) {
binder.bind(DataSourceProvider.class)
.to(MessageBodyReader.class).to(MessageBodyWriter.class).in(Singleton.class);
}
}

private static class DomSourceBinder implements ProviderBinder {
@Override
public void bind(AbstractBinder binder, Provider provider) {
Expand Down
33 changes: 21 additions & 12 deletions core-server/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2010, 2020 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 @@ -95,6 +95,14 @@
</Export-Package>
<Import-Package>
${javax.annotation.osgi.version},
javax.xml.bind;version="!";resolution:=optional,
javax.xml.bind.annotation;version="!";resolution:=optional,
javax.xml.bind.annotation.adapters;version="!";resolution:=optional,
javax.xml.namespace;resolution:=optional,
javax.xml.parsers;resolution:=optional,
javax.xml.transform;resolution:=optional,
javax.xml.transform.sax;resolution:=optional,
javax.xml.transform.stream;resolution:=optional,
javax.validation.*;resolution:=optional;version="${range;[==,3);${javax.validation.api.version}}",
*
</Import-Package>
Expand Down Expand Up @@ -172,12 +180,6 @@
<artifactId>jakarta.ws.rs-api</artifactId>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
Expand All @@ -198,7 +200,18 @@
<artifactId>org.osgi.core</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
senivam marked this conversation as resolved.
Show resolved Hide resolved
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down Expand Up @@ -232,10 +245,6 @@
<jdk>[11,)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-osgi</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
import javax.ws.rs.core.FeatureContext;

import javax.inject.Singleton;
import javax.xml.bind.JAXBException;

import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.internal.util.PropertiesHelper;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.server.ServerProperties;
import org.glassfish.jersey.server.internal.LocalizationMessages;
import org.glassfish.jersey.server.model.ModelProcessor;
import org.glassfish.jersey.server.wadl.internal.WadlApplicationContextImpl;
import org.glassfish.jersey.server.wadl.internal.generators.WadlGeneratorJAXBGrammarGenerator;
import org.glassfish.jersey.server.wadl.processor.WadlModelProcessor;

import java.util.logging.Logger;
Expand All @@ -53,7 +52,17 @@ public boolean configure(FeatureContext context) {
return false;
}

if (!isJaxB()) {
if (!ReflectionHelper.isJaxbAvailable()) {
LOGGER.warning(LocalizationMessages.WADL_FEATURE_DISABLED_NOJAXB());
return false;
}

if (!ReflectionHelper.isXmlTransformAvailable()) {
LOGGER.warning(LocalizationMessages.WADL_FEATURE_DISABLED_NOTRANSFORM());
return false;
}

if (!WadlApplicationContextImpl.isJaxbImplAvailable()) {
LOGGER.warning(LocalizationMessages.WADL_FEATURE_DISABLED());
return false;
}
Expand All @@ -68,12 +77,4 @@ protected void configure() {

return true;
}

private static boolean isJaxB() {
try {
return null != WadlApplicationContextImpl.getJAXBContextFromWadlGenerator(new WadlGeneratorJAXBGrammarGenerator());
} catch (JAXBException je) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.sun.research.ws.wadl.Include;
import com.sun.research.ws.wadl.Resource;
import com.sun.research.ws.wadl.Resources;
import org.glassfish.jersey.server.wadl.internal.generators.WadlGeneratorJAXBGrammarGenerator;

/**
* WADL application context implementation.
Expand Down Expand Up @@ -263,4 +264,12 @@ private void attachExternalGrammar(
throw new ProcessingException(LocalizationMessages.ERROR_WADL_EXTERNAL_GRAMMAR(), e);
}
}

public static boolean isJaxbImplAvailable() {
try {
return null != WadlApplicationContextImpl.getJAXBContextFromWadlGenerator(new WadlGeneratorJAXBGrammarGenerator());
} catch (JAXBException je) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ unsupported.uri.injection.type="@Uri"-based injection of "{0}" type is not suppo
user.not.authorized=User not authorized.
wadl.doc.extended.wadl=This is full WADL including extended resources. To get simplified WADL with users resources only do not use the query parameter {0}. Link: {1}
wadl.doc.simple.wadl=This is simplified WADL with user and core resources only. To get full WADL with extended resources use the query parameter {0}. Link: {1}
wadl.feature.disabled.nojaxb=JAX-B API not found . WADL feature is disabled.
wadl.feature.disabled.notransform=javax.xml.transform package could not be found. WADL feature is disabled.
wadl.feature.disabled=JAXBContext implementation could not be found. WADL feature is disabled.
wadl.jaxb.context.fallback=Error creating a JAXBContext for wadl serialization. Trying a fallback solution for osgi environments.
wadl.resourcedoc.ambiguous.method.entries=Ambiguous resource documentation detected: \
Expand Down
4 changes: 4 additions & 0 deletions examples/bookstore-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
<version>${jstl.version}</version>
</dependency>
<dependency>
senivam marked this conversation as resolved.
Show resolved Hide resolved
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
6 changes: 5 additions & 1 deletion examples/https-clientserver-grizzly/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.

This program and the accompanying materials are made available under the
terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -49,6 +49,10 @@
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
senivam marked this conversation as resolved.
Show resolved Hide resolved
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
6 changes: 5 additions & 1 deletion examples/jaxb/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.

This program and the accompanying materials are made available under the
terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -67,6 +67,10 @@
<jdk>[11,)</jdk>
</activation>
<dependencies>
<dependency>
senivam marked this conversation as resolved.
Show resolved Hide resolved
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-osgi</artifactId>
Expand Down
Loading