Make JAX-B API optional (#4634)
* Make JAX-B API optional
Signed-off-by: Jan Supol <jan.supol@oracle.com>
diff --git a/bundles/jaxrs-ri/pom.xml b/bundles/jaxrs-ri/pom.xml
index da85a1e..96dc73b 100644
--- a/bundles/jaxrs-ri/pom.xml
+++ b/bundles/jaxrs-ri/pom.xml
@@ -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>
diff --git a/connectors/jetty-connector/pom.xml b/connectors/jetty-connector/pom.xml
index e05131b..f227294 100644
--- a/connectors/jetty-connector/pom.xml
+++ b/connectors/jetty-connector/pom.xml
@@ -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
@@ -41,6 +41,12 @@
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
</dependency>
+ <dependency>
+ <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>
diff --git a/core-common/pom.xml b/core-common/pom.xml
index 6869ea7..c35cb1e 100644
--- a/core-common/pom.xml
+++ b/core-common/pom.xml
@@ -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>
@@ -297,6 +311,8 @@
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>jakarta.activation</artifactId>
+ <scope>provided</scope>
+ <optional>true</optional>
</dependency>
</dependencies>
<build>
@@ -686,7 +702,6 @@
</plugins>
</build>
</profile>
-
</profiles>
<properties>
diff --git a/core-common/src/main/java/org/glassfish/jersey/CommonProperties.java b/core-common/src/main/java/org/glassfish/jersey/CommonProperties.java
index b6adbcc..94c54ed 100644
--- a/core-common/src/main/java/org/glassfish/jersey/CommonProperties.java
+++ b/core-common/src/main/java/org/glassfish/jersey/CommonProperties.java
@@ -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
@@ -230,13 +230,15 @@
* 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
diff --git a/core-common/src/main/java/org/glassfish/jersey/internal/util/ReflectionHelper.java b/core-common/src/main/java/org/glassfish/jersey/internal/util/ReflectionHelper.java
index b0a0447..e4a202b 100644
--- a/core-common/src/main/java/org/glassfish/jersey/internal/util/ReflectionHelper.java
+++ b/core-common/src/main/java/org/glassfish/jersey/internal/util/ReflectionHelper.java
@@ -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
@@ -1557,4 +1557,20 @@
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;
+ }
}
diff --git a/core-common/src/main/java/org/glassfish/jersey/message/internal/MessagingBinders.java b/core-common/src/main/java/org/glassfish/jersey/message/internal/MessagingBinders.java
index c01da3d..8c5e67d 100644
--- a/core-common/src/main/java/org/glassfish/jersey/message/internal/MessagingBinders.java
+++ b/core-common/src/main/java/org/glassfish/jersey/message/internal/MessagingBinders.java
@@ -80,7 +80,7 @@
// Message body providers (both readers & writers)
bindSingletonWorker(ByteArrayProvider.class);
- bindSingletonWorker(DataSourceProvider.class);
+ // bindSingletonWorker(DataSourceProvider.class);
bindSingletonWorker(FileProvider.class);
bindSingletonWorker(FormMultivaluedMapProvider.class);
bindSingletonWorker(FormProvider.class);
@@ -158,6 +158,7 @@
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"),
@@ -200,6 +201,9 @@
for (Provider provider : enabledProviders) {
if (isClass(provider.className)) {
switch (provider) {
+ case DATASOURCE:
+ providerBinder = new DataSourceBinder();
+ break;
case DOMSOURCE:
providerBinder = new DomSourceBinder();
break;
@@ -226,6 +230,7 @@
"MessageBodyReader<" + provider.className + ">")
);
break;
+ case DATASOURCE:
case RENDEREDIMAGE:
case SOURCE:
LOGGER.warning(LocalizationMessages.DEPENDENT_CLASS_OF_DEFAULT_PROVIDER_NOT_FOUND(provider.className,
@@ -241,11 +246,18 @@
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) {
diff --git a/core-server/pom.xml b/core-server/pom.xml
index 277307b..527229e 100644
--- a/core-server/pom.xml
+++ b/core-server/pom.xml
@@ -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
@@ -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>
@@ -173,12 +181,6 @@
</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>
</dependency>
@@ -198,7 +200,18 @@
<artifactId>org.osgi.core</artifactId>
<scope>provided</scope>
</dependency>
-
+ <dependency>
+ <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>
@@ -233,10 +246,6 @@
</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>
<scope>test</scope>
diff --git a/core-server/src/main/java/org/glassfish/jersey/server/wadl/WadlFeature.java b/core-server/src/main/java/org/glassfish/jersey/server/wadl/WadlFeature.java
index 1afb644..422638c 100644
--- a/core-server/src/main/java/org/glassfish/jersey/server/wadl/WadlFeature.java
+++ b/core-server/src/main/java/org/glassfish/jersey/server/wadl/WadlFeature.java
@@ -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;
@@ -53,7 +52,17 @@
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;
}
@@ -68,12 +77,4 @@
return true;
}
-
- private static boolean isJaxB() {
- try {
- return null != WadlApplicationContextImpl.getJAXBContextFromWadlGenerator(new WadlGeneratorJAXBGrammarGenerator());
- } catch (JAXBException je) {
- return false;
- }
- }
}
diff --git a/core-server/src/main/java/org/glassfish/jersey/server/wadl/internal/WadlApplicationContextImpl.java b/core-server/src/main/java/org/glassfish/jersey/server/wadl/internal/WadlApplicationContextImpl.java
index 462edec..9f31dd8 100644
--- a/core-server/src/main/java/org/glassfish/jersey/server/wadl/internal/WadlApplicationContextImpl.java
+++ b/core-server/src/main/java/org/glassfish/jersey/server/wadl/internal/WadlApplicationContextImpl.java
@@ -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.
@@ -263,4 +264,12 @@
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;
+ }
+ }
}
diff --git a/core-server/src/main/resources/org/glassfish/jersey/server/internal/localization.properties b/core-server/src/main/resources/org/glassfish/jersey/server/internal/localization.properties
index 8629298..4311fee 100644
--- a/core-server/src/main/resources/org/glassfish/jersey/server/internal/localization.properties
+++ b/core-server/src/main/resources/org/glassfish/jersey/server/internal/localization.properties
@@ -185,6 +185,8 @@
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: \
diff --git a/examples/bookstore-webapp/pom.xml b/examples/bookstore-webapp/pom.xml
index 8ad0c6a..6453578 100644
--- a/examples/bookstore-webapp/pom.xml
+++ b/examples/bookstore-webapp/pom.xml
@@ -63,6 +63,10 @@
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
<version>${jstl.version}</version>
</dependency>
+ <dependency>
+ <groupId>jakarta.xml.bind</groupId>
+ <artifactId>jakarta.xml.bind-api</artifactId>
+ </dependency>
</dependencies>
<build>
diff --git a/examples/https-clientserver-grizzly/pom.xml b/examples/https-clientserver-grizzly/pom.xml
index 23f4125..354f286 100644
--- a/examples/https-clientserver-grizzly/pom.xml
+++ b/examples/https-clientserver-grizzly/pom.xml
@@ -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
@@ -50,6 +50,10 @@
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
+ <groupId>jakarta.xml.bind</groupId>
+ <artifactId>jakarta.xml.bind-api</artifactId>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
diff --git a/examples/jaxb/pom.xml b/examples/jaxb/pom.xml
index 976c82b..e4b8c01 100644
--- a/examples/jaxb/pom.xml
+++ b/examples/jaxb/pom.xml
@@ -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
@@ -68,6 +68,10 @@
</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>
<scope>test</scope>
diff --git a/examples/json-jackson1/pom.xml b/examples/json-jackson1/pom.xml
index 5f70a2a..666f155 100644
--- a/examples/json-jackson1/pom.xml
+++ b/examples/json-jackson1/pom.xml
@@ -40,7 +40,10 @@
<artifactId>jersey-media-json-jackson1</artifactId>
<version>${project.version}</version>
</dependency>
-
+ <dependency>
+ <groupId>jakarta.xml.bind</groupId>
+ <artifactId>jakarta.xml.bind-api</artifactId>
+ </dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-bundle</artifactId>
diff --git a/examples/multipart-webapp/pom.xml b/examples/multipart-webapp/pom.xml
index 5ba57a3..f7f2421 100644
--- a/examples/multipart-webapp/pom.xml
+++ b/examples/multipart-webapp/pom.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2012, 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
@@ -37,6 +37,10 @@
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
+ <dependency>
+ <groupId>jakarta.xml.bind</groupId>
+ <artifactId>jakarta.xml.bind-api</artifactId>
+ </dependency>
</dependencies>
<build>
diff --git a/ext/bean-validation/pom.xml b/ext/bean-validation/pom.xml
index b33e994..30da28d 100644
--- a/ext/bean-validation/pom.xml
+++ b/ext/bean-validation/pom.xml
@@ -98,6 +98,11 @@
</exclusions>
</dependency>
<dependency>
+ <groupId>jakarta.xml.bind</groupId>
+ <artifactId>jakarta.xml.bind-api</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<optional>true</optional>
diff --git a/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/ValidationError.java b/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/ValidationError.java
index cf2f1c4..a737399 100644
--- a/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/ValidationError.java
+++ b/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/ValidationError.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -25,15 +25,7 @@
*/
@XmlRootElement
@SuppressWarnings("UnusedDeclaration")
-public final class ValidationError {
-
- private String message;
-
- private String messageTemplate;
-
- private String path;
-
- private String invalidValue;
+public final class ValidationError extends ValidationErrorData {
/**
* Create a {@code ValidationError} instance. Constructor for JAXB providers.
@@ -50,81 +42,6 @@
* @param invalidValue value that failed to pass constraints.
*/
public ValidationError(final String message, final String messageTemplate, final String path, final String invalidValue) {
- this.message = message;
- this.messageTemplate = messageTemplate;
- this.path = path;
- this.invalidValue = invalidValue;
- }
-
- /**
- * Return the interpolated error message for this validation error.
- *
- * @return the interpolated error message for this validation error.
- */
- public String getMessage() {
- return message;
- }
-
- /**
- * Return the interpolated error message for this validation error.
- *
- * @param message the interpolated error message for this validation error.
- */
- public void setMessage(final String message) {
- this.message = message;
- }
-
- /**
- * Return the string representation of the property path to the value.
- *
- * @return the string representation of the property path to the value.
- */
- public String getPath() {
- return path;
- }
-
- /**
- * Set the string representation of the property path to the value.
- *
- * @param path the string representation of the property path to the value.
- */
- public void setPath(final String path) {
- this.path = path;
- }
-
- /**
- * Returns the string representation of the value failing to pass the constraint.
- *
- * @return the value failing to pass the constraint.
- */
- public String getInvalidValue() {
- return invalidValue;
- }
-
- /**
- * Set the value failing to pass the constraint.
- *
- * @param invalidValue the value failing to pass the constraint.
- */
- public void setInvalidValue(final String invalidValue) {
- this.invalidValue = invalidValue;
- }
-
- /**
- * Return the non-interpolated error message for this validation error.
- *
- * @return the non-interpolated error message for this validation error.
- */
- public String getMessageTemplate() {
- return messageTemplate;
- }
-
- /**
- * Set the non-interpolated error message for this validation error.
- *
- * @param messageTemplate the non-interpolated error message for this validation error.
- */
- public void setMessageTemplate(final String messageTemplate) {
- this.messageTemplate = messageTemplate;
+ super(message, messageTemplate, path, invalidValue);
}
}
diff --git a/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/ValidationErrorData.java b/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/ValidationErrorData.java
new file mode 100644
index 0000000..5c2abe6
--- /dev/null
+++ b/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/ValidationErrorData.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.server.validation;
+
+
+import org.glassfish.jersey.internal.util.ReflectionHelper;
+
+/**
+ * Validation error entity to be included in {@code Response} if JAX-B API is not available
+ */
+@SuppressWarnings("UnusedDeclaration")
+public class ValidationErrorData {
+
+ protected String message;
+
+ protected String messageTemplate;
+
+ protected String path;
+
+ protected String invalidValue;
+
+ /* package */ ValidationErrorData() {
+ }
+
+ /**
+ * Create a {@code ValidationError} instance.
+ *
+ * @param message interpolated error message.
+ * @param messageTemplate non-interpolated error message.
+ * @param path property path.
+ * @param invalidValue value that failed to pass constraints.
+ */
+ /* package */
+ ValidationErrorData(final String message, final String messageTemplate, final String path, final String invalidValue) {
+ this.message = message;
+ this.messageTemplate = messageTemplate;
+ this.path = path;
+ this.invalidValue = invalidValue;
+ }
+
+ /**
+ * Return the interpolated error message for this validation error.
+ *
+ * @return the interpolated error message for this validation error.
+ */
+ public String getMessage() {
+ return message;
+ }
+
+ /**
+ * Return the interpolated error message for this validation error.
+ *
+ * @param message the interpolated error message for this validation error.
+ */
+ public void setMessage(final String message) {
+ this.message = message;
+ }
+
+ /**
+ * Return the string representation of the property path to the value.
+ *
+ * @return the string representation of the property path to the value.
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
+ * Set the string representation of the property path to the value.
+ *
+ * @param path the string representation of the property path to the value.
+ */
+ public void setPath(final String path) {
+ this.path = path;
+ }
+
+ /**
+ * Returns the string representation of the value failing to pass the constraint.
+ *
+ * @return the value failing to pass the constraint.
+ */
+ public String getInvalidValue() {
+ return invalidValue;
+ }
+
+ /**
+ * Set the value failing to pass the constraint.
+ *
+ * @param invalidValue the value failing to pass the constraint.
+ */
+ public void setInvalidValue(final String invalidValue) {
+ this.invalidValue = invalidValue;
+ }
+
+ /**
+ * Return the non-interpolated error message for this validation error.
+ *
+ * @return the non-interpolated error message for this validation error.
+ */
+ public String getMessageTemplate() {
+ return messageTemplate;
+ }
+
+ /**
+ * Set the non-interpolated error message for this validation error.
+ *
+ * @param messageTemplate the non-interpolated error message for this validation error.
+ */
+ public void setMessageTemplate(final String messageTemplate) {
+ this.messageTemplate = messageTemplate;
+ }
+
+ /*
+ * Cache the information
+ */
+ private static Boolean isJaxbAvailable = null;
+
+ private static boolean isJaxbAvailable() {
+ if (isJaxbAvailable == null) {
+ isJaxbAvailable = ReflectionHelper.isJaxbAvailable();
+ }
+ return isJaxbAvailable;
+ }
+
+ /**
+ * A factory method that creates either JAX-B annotated data if JAX-B is available or POJO data otherwise.
+ * @param message interpolated error message.
+ * @param messageTemplate non-interpolated error message.
+ * @param path property path.
+ * @param invalidValue value that failed to pass constraints.
+ * @return ValidationErrorData subclass or itself
+ */
+ public static ValidationErrorData createValidationError(
+ final String message, final String messageTemplate, final String path, final String invalidValue) {
+ if (isJaxbAvailable()) {
+ return new ValidationError(message, messageTemplate, path, invalidValue);
+ } else {
+ return new ValidationErrorData(message, messageTemplate, path, invalidValue);
+ }
+ }
+}
diff --git a/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/internal/ValidationErrorMessageBodyWriter.java b/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/internal/ValidationErrorMessageBodyWriter.java
index 84e2a00..4c91fc5 100644
--- a/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/internal/ValidationErrorMessageBodyWriter.java
+++ b/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/internal/ValidationErrorMessageBodyWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -30,10 +30,10 @@
import javax.ws.rs.ext.MessageBodyWriter;
import org.glassfish.jersey.message.MessageUtils;
-import org.glassfish.jersey.server.validation.ValidationError;
+import org.glassfish.jersey.server.validation.ValidationErrorData;
/**
- * {@link MessageBodyWriter} providing support for (collections of) {@link ValidationError}
+ * {@link MessageBodyWriter} providing support for (collections of) {@link ValidationErrorData}
* that is able to output instances to {@code text/plain}/{@code text/html}.
*
* @author Michal Gajdos
@@ -49,10 +49,10 @@
}
private static boolean isSupportedType(final Class<?> type, final Type genericType) {
- if (ValidationError.class.isAssignableFrom(type)) {
+ if (ValidationErrorData.class.isAssignableFrom(type)) {
return true;
} else if (Collection.class.isAssignableFrom(type) && (genericType instanceof ParameterizedType)) {
- return ValidationError.class
+ return ValidationErrorData.class
.isAssignableFrom((Class) ((ParameterizedType) genericType).getActualTypeArguments()[0]);
}
return false;
@@ -79,13 +79,13 @@
final MediaType mediaType,
final MultivaluedMap<String, Object> httpHeaders,
final OutputStream entityStream) throws IOException, WebApplicationException {
- final Collection<ValidationError> errors;
+ final Collection<ValidationErrorData> errors;
- if (entity instanceof ValidationError) {
- errors = Collections.singleton((ValidationError) entity);
+ if (entity instanceof ValidationErrorData) {
+ errors = Collections.singleton((ValidationErrorData) entity);
} else {
//noinspection unchecked
- errors = (Collection<ValidationError>) entity;
+ errors = (Collection<ValidationErrorData>) entity;
}
final boolean isPlain = MediaType.TEXT_PLAIN_TYPE.getSubtype().equals(mediaType.getSubtype());
@@ -97,7 +97,7 @@
builder.append("<div class=\"validation-errors\">");
}
- for (final ValidationError error : errors) {
+ for (final ValidationErrorData error : errors) {
if (!isPlain) {
builder.append("<div class=\"validation-error\">");
}
diff --git a/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/internal/ValidationExceptionMapper.java b/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/internal/ValidationExceptionMapper.java
index b569607..5e44507 100644
--- a/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/internal/ValidationExceptionMapper.java
+++ b/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/internal/ValidationExceptionMapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -35,12 +35,12 @@
import javax.validation.ValidationException;
import org.glassfish.jersey.server.ServerProperties;
-import org.glassfish.jersey.server.validation.ValidationError;
+import org.glassfish.jersey.server.validation.ValidationErrorData;
/**
* {@link ExceptionMapper} for {@link ValidationException}.
* <p/>
- * If {@value ServerProperties#BV_SEND_ERROR_IN_RESPONSE} property is enabled then a list of {@link ValidationError}
+ * If {@value ServerProperties#BV_SEND_ERROR_IN_RESPONSE} property is enabled then a list of {@link ValidationErrorData}
* instances is sent in {@link Response} as well (in addition to HTTP 400/500 status code). Supported media types are:
* {@code application/json}/{@code application/xml} (in appropriate provider is registered on server) or
* {@code text/html}/{@code text/plain} (via custom {@link ValidationErrorMessageBodyWriter}).
@@ -85,7 +85,7 @@
response.entity(
new GenericEntity<>(
ValidationHelper.constraintViolationToValidationErrors(cve),
- new GenericType<List<ValidationError>>() {}.getType()
+ new GenericType<List<ValidationErrorData>>() {}.getType()
)
);
}
diff --git a/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/internal/ValidationHelper.java b/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/internal/ValidationHelper.java
index 5e92de9..0722dd4 100644
--- a/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/internal/ValidationHelper.java
+++ b/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/internal/ValidationHelper.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2018 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
@@ -27,7 +27,7 @@
import javax.validation.Path;
import javax.ws.rs.core.Response;
-import org.glassfish.jersey.server.validation.ValidationError;
+import org.glassfish.jersey.server.validation.ValidationErrorData;
/**
* Utility methods for Bean Validation processing.
@@ -39,13 +39,13 @@
/**
* Extract {@link ConstraintViolation constraint violations} from given exception and transform them into a list of
- * {@link ValidationError validation errors}.
+ * {@link ValidationErrorData validation errors}.
*
* @param violation exception containing constraint violations.
* @return list of validation errors (not {@code null}).
*/
- public static List<ValidationError> constraintViolationToValidationErrors(final ConstraintViolationException violation) {
- return violation.getConstraintViolations().stream().map(violation1 -> new ValidationError(
+ public static List<ValidationErrorData> constraintViolationToValidationErrors(final ConstraintViolationException violation) {
+ return violation.getConstraintViolations().stream().map(violation1 -> ValidationErrorData.createValidationError(
violation1.getMessage(),
violation1.getMessageTemplate(),
getViolationPath(violation1),
diff --git a/ext/entity-filtering/pom.xml b/ext/entity-filtering/pom.xml
index 60b5b98..9e90d30 100644
--- a/ext/entity-filtering/pom.xml
+++ b/ext/entity-filtering/pom.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
- 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
@@ -35,6 +35,11 @@
<dependencies>
<dependency>
+ <groupId>jakarta.xml.bind</groupId>
+ <artifactId>jakarta.xml.bind-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${project.version}</version>
diff --git a/ext/wadl-doclet/pom.xml b/ext/wadl-doclet/pom.xml
index dab9887..2282eef 100644
--- a/ext/wadl-doclet/pom.xml
+++ b/ext/wadl-doclet/pom.xml
@@ -44,21 +44,6 @@
<profiles>
<profile>
- <id>jdk1.7</id>
- <activation>
- <jdk>1.7</jdk>
- </activation>
- <dependencies>
- <dependency>
- <groupId>com.sun</groupId>
- <artifactId>tools</artifactId>
- <version>1.7.0</version>
- <scope>system</scope>
- <systemPath>${java.home}/../lib/tools.jar</systemPath>
- </dependency>
- </dependencies>
- </profile>
- <profile>
<id>jdk1.8</id>
<activation>
<jdk>1.8</jdk>
@@ -201,29 +186,19 @@
</plugins>
</build>
</profile>
- <profile>
- <id>tools.jar</id>
- <activation>
- <!-- Activation should be done with <file>${java.home}/../lib/tools.jar</file But this is not working with maven as the property is not expansed. -->
- <property>
- <name>java.vendor</name>
- <value>Sun Microsystems Inc.</value>
- </property>
- </activation>
- <dependencies>
- <dependency>
- <groupId>com.sun</groupId>
- <artifactId>tools</artifactId>
- <version>1.6</version>
- <scope>system</scope>
- <systemPath>${java.home}/../lib/tools.jar</systemPath>
- </dependency>
- </dependencies>
- </profile>
</profiles>
<dependencies>
<dependency>
+ <groupId>jakarta.xml.bind</groupId>
+ <artifactId>jakarta.xml.bind-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-jaxb</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</dependency>
diff --git a/incubator/declarative-linking/pom.xml b/incubator/declarative-linking/pom.xml
index 29cc7f1..62a49c3 100644
--- a/incubator/declarative-linking/pom.xml
+++ b/incubator/declarative-linking/pom.xml
@@ -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
@@ -47,7 +47,11 @@
<artifactId>jersey-server</artifactId>
<version>${project.version}</version>
</dependency>
-
+ <dependency>
+ <groupId>jakarta.xml.bind</groupId>
+ <artifactId>jakarta.xml.bind-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
diff --git a/test-framework/core/pom.xml b/test-framework/core/pom.xml
index 8a7e08e..44b5fa4 100644
--- a/test-framework/core/pom.xml
+++ b/test-framework/core/pom.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2010, 2018 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
@@ -34,21 +34,30 @@
<dependencies>
<dependency>
+ <groupId>jakarta.xml.bind</groupId>
+ <artifactId>jakarta.xml.bind-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.servlet</groupId>
+ <artifactId>jakarta.servlet-api</artifactId>
+ <version>${servlet4.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-jaxb</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>jakarta.servlet</groupId>
- <artifactId>jakarta.servlet-api</artifactId>
- <version>${servlet4.version}</version>
- </dependency>
- <dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${project.version}</version>
diff --git a/tests/e2e-server/pom.xml b/tests/e2e-server/pom.xml
index bd8a99a..50d0d46 100644
--- a/tests/e2e-server/pom.xml
+++ b/tests/e2e-server/pom.xml
@@ -199,6 +199,11 @@
</activation>
<dependencies>
<dependency>
+ <groupId>jakarta.xml.bind</groupId>
+ <artifactId>jakarta.xml.bind-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-osgi</artifactId>
<scope>test</scope>
diff --git a/tests/integration/jersey-2637/pom.xml b/tests/integration/jersey-2637/pom.xml
index 6c90d10..d9b1de0 100644
--- a/tests/integration/jersey-2637/pom.xml
+++ b/tests/integration/jersey-2637/pom.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2015, 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
@@ -50,7 +50,6 @@
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-external</artifactId>
- <scope>test</scope>
</dependency>
</dependencies>
diff --git a/tests/integration/servlet-2.5-mvc-1/pom.xml b/tests/integration/servlet-2.5-mvc-1/pom.xml
index 4d2bb59..943d091 100644
--- a/tests/integration/servlet-2.5-mvc-1/pom.xml
+++ b/tests/integration/servlet-2.5-mvc-1/pom.xml
@@ -55,7 +55,6 @@
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-external</artifactId>
- <scope>test</scope>
</dependency>
</dependencies>
diff --git a/tests/integration/servlet-2.5-mvc-2/pom.xml b/tests/integration/servlet-2.5-mvc-2/pom.xml
index f8221c2..d0ac2e4 100644
--- a/tests/integration/servlet-2.5-mvc-2/pom.xml
+++ b/tests/integration/servlet-2.5-mvc-2/pom.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- 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
@@ -55,7 +55,6 @@
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-external</artifactId>
- <scope>test</scope>
</dependency>
</dependencies>
diff --git a/tests/integration/servlet-2.5-mvc-3/pom.xml b/tests/integration/servlet-2.5-mvc-3/pom.xml
index d1531c6..03e4194 100644
--- a/tests/integration/servlet-2.5-mvc-3/pom.xml
+++ b/tests/integration/servlet-2.5-mvc-3/pom.xml
@@ -55,7 +55,6 @@
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-external</artifactId>
- <scope>test</scope>
</dependency>
</dependencies>
diff --git a/tests/integration/servlet-tests/pom.xml b/tests/integration/servlet-tests/pom.xml
index 6b2d519..c6c5e33 100644
--- a/tests/integration/servlet-tests/pom.xml
+++ b/tests/integration/servlet-tests/pom.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- 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
@@ -47,7 +47,6 @@
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-external</artifactId>
- <scope>test</scope>
</dependency>
</dependencies>