From fe9829bb5abc89f09c92bbce1613d31331939eae Mon Sep 17 00:00:00 2001 From: hs536 Date: Thu, 17 Mar 2022 20:23:33 +0100 Subject: [PATCH 1/2] Bump JAXB from 3.0.X to 4.0.X --- .../jersey/jettison/JettisonJaxbContext.java | 14 +------------- .../internal/JettisonJaxbMarshaller.java | 8 ++++---- .../internal/JettisonJaxbUnmarshaller.java | 18 ++++-------------- 3 files changed, 9 insertions(+), 31 deletions(-) diff --git a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/JettisonJaxbContext.java b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/JettisonJaxbContext.java index f76ab53b5d..6d6b039a4e 100644 --- a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/JettisonJaxbContext.java +++ b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/JettisonJaxbContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2022 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 @@ -22,7 +22,6 @@ import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.Marshaller; import jakarta.xml.bind.Unmarshaller; -import jakarta.xml.bind.Validator; import org.glassfish.jersey.jettison.internal.BaseJsonMarshaller; import org.glassfish.jersey.jettison.internal.BaseJsonUnmarshaller; @@ -300,15 +299,4 @@ public Unmarshaller createUnmarshaller() throws JAXBException { public Marshaller createMarshaller() throws JAXBException { return new JettisonJaxbMarshaller(jaxbContext, getJSONConfiguration()); } - - /** - * Simply delegates to underlying JAXBContext implementation. - * - * @return what underlying JAXBContext returns - * @throws jakarta.xml.bind.JAXBException - */ - @Override - public Validator createValidator() throws JAXBException { - return jaxbContext.createValidator(); - } } diff --git a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/JettisonJaxbMarshaller.java b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/JettisonJaxbMarshaller.java index cd78fc9d44..4603572ae0 100644 --- a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/JettisonJaxbMarshaller.java +++ b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/JettisonJaxbMarshaller.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2022 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 @@ -128,17 +128,17 @@ public ValidationEventHandler getEventHandler() throws JAXBException { } @Override - public void setAdapter(XmlAdapter adapter) { + public > void setAdapter(A adapter) { jaxbMarshaller.setAdapter(adapter); } @Override - public void setAdapter(Class type, A adapter) { + public > void setAdapter(Class type, A adapter) { jaxbMarshaller.setAdapter(type, adapter); } @Override - public A getAdapter(Class type) { + public > A getAdapter(Class type) { return jaxbMarshaller.getAdapter(type); } diff --git a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/JettisonJaxbUnmarshaller.java b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/JettisonJaxbUnmarshaller.java index 3d24d5032e..377e37ae59 100644 --- a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/JettisonJaxbUnmarshaller.java +++ b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/JettisonJaxbUnmarshaller.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2022 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 @@ -122,16 +122,6 @@ public UnmarshallerHandler getUnmarshallerHandler() { return this.jaxbUnmarshaller.getUnmarshallerHandler(); } - @Override - public void setValidating(boolean validating) throws JAXBException { - this.jaxbUnmarshaller.setValidating(validating); - } - - @Override - public boolean isValidating() throws JAXBException { - return this.jaxbUnmarshaller.isValidating(); - } - @Override public void setEventHandler(ValidationEventHandler validationEventHandler) throws JAXBException { this.jaxbUnmarshaller.setEventHandler(validationEventHandler); @@ -163,17 +153,17 @@ public Schema getSchema() { } @Override - public void setAdapter(XmlAdapter xmlAdapter) { + public > void setAdapter(A xmlAdapter) { this.jaxbUnmarshaller.setAdapter(xmlAdapter); } @Override - public void setAdapter(Class type, A adapter) { + public > void setAdapter(Class type, A adapter) { this.jaxbUnmarshaller.setAdapter(type, adapter); } @Override - public A getAdapter(Class type) { + public > A getAdapter(Class type) { return this.jaxbUnmarshaller.getAdapter(type); } From 44d62202133097bae57ee98e5fd3c4c7a0c0fdba Mon Sep 17 00:00:00 2001 From: jansupol Date: Fri, 18 Mar 2022 12:58:04 +0100 Subject: [PATCH 2/2] Update versions of JAX-B, Moxy, JSON-B, JSON-P Signed-off-by: jansupol --- pom.xml | 39 +++++++++---------- .../AnotherContactBean.java | 7 ++-- .../ValidateOnExecutionBasicTest.java | 37 +++++++++++++++++- .../e2e/server/wadl/WadlBeanParamTest.java | 12 ++++-- .../e2e/server/wadl/WadlResourceTest.java | 9 ++++- .../osgi/test/basic/JsonJacksonTest.java | 3 ++ .../jersey/osgi/test/basic/JsonMoxyTest.java | 4 +- .../osgi/test/basic/PackageScanningTest.java | 2 +- .../jersey/osgi/test/util/Helper.java | 6 +-- 9 files changed, 82 insertions(+), 37 deletions(-) diff --git a/pom.xml b/pom.xml index 39b9360f6c..e37eba9579 100644 --- a/pom.xml +++ b/pom.xml @@ -2120,12 +2120,9 @@ 1.3 1.0.3 1.6 - org.glassfish.hk2.*;version="[3.0,4)" - org.jvnet.hk2.*;version="[3.0,4)" - 6.0.0 4.5.13 2.13.0 - 3.25.0-GA + 3.28.0-GA 3.3.0.Final 1.19.3 ${jersey1.version} @@ -2159,7 +2156,6 @@ 4.0.2.Final - 3.1.7.SP1 7.0.1.Final 2.11.0 @@ -2168,43 +2164,46 @@ 20.3.2 - 6.0.0 + 7.0.0-M2 3.0.0 4.0.0 3.0.1 2.0.0 - 3.0.2 - 3.0.0 - 2.0.0 + 3.0.3 + org.glassfish.hk2.*;version="[3.0,4)" + org.jvnet.hk2.*;version="[3.0,4)" + 7.0.0-M2 + 3.1.0 + 3.0.0 2.0.0 5.0.0 6.0.0 5.0.0 4.0.0 - 2.0.1 + 2.1.0 2.0.1 4.0.0 4.0.2 jakarta.annotation.*;version="[2.0,3)" - 2.0.0 + 2.1.0 2.0.1 - 2.0.0 + 2.1.0 2.1.0 - 3.0.0 + 3.1.0 3.0.1 - 3.0.1 - 3.0.2 + 4.0.0 + 4.0.0-M3 3.1 3.1.0 11.0.7 11.0.7 6.1.14 - 2.0.0 - 1.0.0 - 1.0.0 - 3.0.2 - 2.0.3 + 3.0.0 + 1.1.0 + 1.1.0 + 4.0.0-M3 + 3.0.0-RC1 1.3.2 diff --git a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/validation/validateonexecution/AnotherContactBean.java b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/validation/validateonexecution/AnotherContactBean.java index fa65eae744..2d88b34ad0 100644 --- a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/validation/validateonexecution/AnotherContactBean.java +++ b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/validation/validateonexecution/AnotherContactBean.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2022 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 @@ -18,6 +18,8 @@ import java.io.Serializable; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Pattern; import jakarta.validation.executable.ExecutableType; @@ -26,9 +28,6 @@ import org.glassfish.jersey.tests.e2e.server.validation.Extended; -import org.hibernate.validator.constraints.Email; -import org.hibernate.validator.constraints.NotBlank; - /** * @author Michal Gajdos */ diff --git a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/validation/validateonexecution/ValidateOnExecutionBasicTest.java b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/validation/validateonexecution/ValidateOnExecutionBasicTest.java index 3c3c946340..f3ecf18de9 100644 --- a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/validation/validateonexecution/ValidateOnExecutionBasicTest.java +++ b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/validation/validateonexecution/ValidateOnExecutionBasicTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2022 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 @@ -32,12 +32,22 @@ import jakarta.validation.executable.ExecutableType; import jakarta.validation.executable.ValidateOnExecution; +import jakarta.ws.rs.ext.ContextResolver; +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBException; +import org.eclipse.persistence.jaxb.BeanValidationMode; +import org.eclipse.persistence.jaxb.MarshallerProperties; +import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.server.ServerProperties; import org.glassfish.jersey.test.TestProperties; import org.glassfish.jersey.test.util.runner.RunSeparately; import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; @@ -289,6 +299,28 @@ public String getNull() { } } + /** + * Do not validate the bean by Moxy, validate just by Jersey + */ + public static class MoxyNotValidateContextResolver implements ContextResolver { + @Override + public JAXBContext getContext(Class type) { + Map properties = new HashMap<>(); + properties.put(MarshallerProperties.BEAN_VALIDATION_MODE, BeanValidationMode.NONE); + try { + return JAXBContext.newInstance(new Class[]{type}, properties); + } catch (JAXBException e) { + throw new RuntimeException(e); + } + } + } + + @Override + protected void configureClient(ClientConfig config) { + config.register(MoxyNotValidateContextResolver.class); + super.configureClient(config); + } + @Override protected Application configure() { enable(TestProperties.LOG_TRAFFIC); @@ -309,7 +341,8 @@ protected Application configure() { ValidateGetterExecutableOnTypeMatch.class, ValidateGetterExecutableOnBeans.class, ValidateGetterResourceMethod.class, - ValidateExecutableResource.class) + ValidateExecutableResource.class, + MoxyNotValidateContextResolver.class) .property(ServerProperties.BV_DISABLE_VALIDATE_ON_EXECUTABLE_OVERRIDE_CHECK, true); } diff --git a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/wadl/WadlBeanParamTest.java b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/wadl/WadlBeanParamTest.java index 195c6755aa..481c20c3b7 100644 --- a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/wadl/WadlBeanParamTest.java +++ b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/wadl/WadlBeanParamTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2022 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 @@ -22,6 +22,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import java.util.Properties; import jakarta.ws.rs.BeanParam; import jakarta.ws.rs.CookieParam; @@ -38,9 +39,13 @@ import jakarta.ws.rs.core.Request; import jakarta.ws.rs.core.Response; +import javax.xml.transform.ErrorListener; +import javax.xml.transform.Result; +import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; +import javax.xml.transform.URIResolver; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import javax.xml.xpath.XPath; @@ -89,8 +94,9 @@ public class WadlBeanParamTest extends JerseyTest { */ @Override public boolean qualifyForComparison(final Element control, final Element test) { - if (test != null && !"param".equals(test.getNodeName())) { - return super.qualifyForComparison(control, test); + if (test != null && !"param".equals(test.getNodeName()) && !"ns0:param".equals(test.getNodeName())) { + boolean spr = super.qualifyForComparison(control, test); + return spr; } if (!(control != null && test != null && equalsNamespace(control, test) diff --git a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/wadl/WadlResourceTest.java b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/wadl/WadlResourceTest.java index 72371288ed..da2d78749a 100644 --- a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/wadl/WadlResourceTest.java +++ b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/wadl/WadlResourceTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2022 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 @@ -1009,7 +1009,12 @@ public void testGetWithPathAndLeadingSlash() throws Exception { final String document = response.readEntity(String.class); // check that the resulting document contains a method element with id="fooX" - assertTrue(document.replaceAll("\n", " ").matches(".*]+id=\"foo" + i + "\"[^>]*>.*")); + assertTrue(document + .replaceAll("\n", " ") + .replaceAll("\r", "") + .replaceAll("ns0:", "") + .matches(".*]+id=\"foo" + i + "\"[^>]*>.*") + ); } } } diff --git a/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/JsonJacksonTest.java b/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/JsonJacksonTest.java index 7d06f02d48..7aebd55951 100644 --- a/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/JsonJacksonTest.java +++ b/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/JsonJacksonTest.java @@ -41,6 +41,9 @@ public static Option[] configuration() { options.addAll(Helper.expandedList( // vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"), + // TODO - remove when jackson-module-jakarta-xmlbind-annotations supports JAX-B/4 + mavenBundle().groupId("jakarta.xml.bind").artifactId("jakarta.xml.bind-api").version("3.0.1"), + mavenBundle().groupId("org.glassfish.jersey.media").artifactId("jersey-media-json-jackson").versionAsInProject(), mavenBundle().groupId("org.glassfish.jersey.ext").artifactId("jersey-entity-filtering").versionAsInProject(), diff --git a/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/JsonMoxyTest.java b/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/JsonMoxyTest.java index 0f7eb6f968..c4558a8c4c 100644 --- a/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/JsonMoxyTest.java +++ b/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/JsonMoxyTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2022 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 @@ -57,7 +57,7 @@ public static Option[] configuration() { mavenBundle().groupId("org.eclipse.persistence").artifactId("org.eclipse.persistence.moxy").versionAsInProject(), mavenBundle().groupId("org.eclipse.persistence").artifactId("org.eclipse.persistence.core").versionAsInProject(), mavenBundle().groupId("org.eclipse.persistence").artifactId("org.eclipse.persistence.asm").versionAsInProject(), - mavenBundle().groupId("org.glassfish").artifactId("jakarta.json").versionAsInProject(), + mavenBundle().groupId("jakarta.json").artifactId("jakarta.json-api").versionAsInProject(), // validation mavenBundle().groupId("org.hibernate.validator").artifactId("hibernate-validator").versionAsInProject(), diff --git a/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/PackageScanningTest.java b/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/PackageScanningTest.java index 424b1babfb..c3a2fcaef7 100644 --- a/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/PackageScanningTest.java +++ b/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/PackageScanningTest.java @@ -79,7 +79,7 @@ public static Option[] configuration() { .versionAsInProject(), // MBR/MBW for JSON-P is on the classpath. - mavenBundle().groupId("org.glassfish").artifactId("jakarta.json").versionAsInProject() + mavenBundle().groupId("jakarta.json").artifactId("jakarta.json-api").versionAsInProject() )); options = Helper.addPaxExamMavenLocalRepositoryProperty(options); diff --git a/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/util/Helper.java b/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/util/Helper.java index 76a1515b0a..4be49dd0e3 100644 --- a/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/util/Helper.java +++ b/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/util/Helper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2022 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 @@ -183,9 +183,9 @@ public static List