From cfc86ea9bef19e43c4826759c6e6164405ae9203 Mon Sep 17 00:00:00 2001 From: Jorge Bescos Gascon Date: Thu, 24 Jun 2021 15:22:53 +0200 Subject: [PATCH 1/4] Remove com.sun.org.apache.xml.internal Signed-off-by: Jorge Bescos Gascon --- .../jersey/wadl/doclet/DocletUtils.java | 78 ++++++++++--------- pom.xml | 2 +- 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/ext/wadl-doclet/src/main/java/org/glassfish/jersey/wadl/doclet/DocletUtils.java b/ext/wadl-doclet/src/main/java/org/glassfish/jersey/wadl/doclet/DocletUtils.java index 4dea216a86..8712e989ae 100644 --- a/ext/wadl-doclet/src/main/java/org/glassfish/jersey/wadl/doclet/DocletUtils.java +++ b/ext/wadl-doclet/src/main/java/org/glassfish/jersey/wadl/doclet/DocletUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2021 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 @@ -16,29 +16,37 @@ package org.glassfish.jersey.wadl.doclet; -import com.sun.org.apache.xml.internal.serialize.OutputFormat; -import com.sun.org.apache.xml.internal.serialize.XMLSerializer; - import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; import java.io.FileOutputStream; import java.io.OutputStream; import java.io.StringWriter; import java.lang.reflect.Array; import java.lang.reflect.Field; +import java.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; import org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ResourceDocType; +import org.w3c.dom.CDATASection; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; class DocletUtils { private static final Logger LOG = Logger.getLogger(DocletUtils.class.getName()); private static String[] getCDataElements(DocProcessor docProcessor) { - String[] original = new String[]{"ns1^commentText", "ns2^commentText", "^commentText" }; + String[] original = new String[]{"commentText"}; if (docProcessor == null) { return original; } else { @@ -64,30 +72,6 @@ private static T[] copyOf(U[] original, int newLength) { return copy; } - private static XMLSerializer getXMLSerializer(OutputStream os, String[] cdataElements) - throws InstantiationException, IllegalAccessException, ClassNotFoundException { - // configure an OutputFormat to handle CDATA - OutputFormat of = new OutputFormat(); - - // specify which of your elements you want to be handled as CDATA. - // The use of the '^' between the namespaceURI and the localname - // seems to be an implementation detail of the xerces code. - // When processing xml that doesn't use namespaces, simply omit the - // namespace prefix as shown in the third CDataElement below. - of.setCDataElements(cdataElements); - - // set any other options you'd like - of.setPreserveSpace(true); - of.setIndenting(true); - - // create the serializer - XMLSerializer serializer = new XMLSerializer(of); - - serializer.setOutputByteStream(os); - - return serializer; - } - private static Class[] getJAXBContextClasses(ResourceDocType result, DocProcessor docProcessor) { Class[] clazzes; if (docProcessor == null) { @@ -108,15 +92,39 @@ private static Class[] getJAXBContextClasses(ResourceDocType result, DocProce } static boolean createOutputFile(String filePath, DocProcessor docProcessor, ResourceDocType result) { + String[] cdataElements = getCDataElements(docProcessor); + Class[] classes = getJAXBContextClasses(result, docProcessor); + LOG.info("cdataElements " + Arrays.asList(cdataElements)); + LOG.info("classes " + Arrays.asList(classes)); try (OutputStream out = new BufferedOutputStream(new FileOutputStream(filePath))) { - Class[] clazzes = getJAXBContextClasses(result, docProcessor); - JAXBContext c = JAXBContext.newInstance(clazzes); + JAXBContext c = JAXBContext.newInstance(classes); Marshaller m = c.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - String[] cdataElements = getCDataElements(docProcessor); - XMLSerializer serializer = getXMLSerializer(out, cdataElements); - m.marshal(result, serializer); - LOG.info("Wrote " + result); + StringWriter sw = new StringWriter(); + // Produces XML in memory + m.marshal(result, sw); + // Loads the XML from memory for processing + Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder() + .parse(new ByteArrayInputStream(sw.toString().getBytes())); + for (String cdata : cdataElements) { + NodeList nodes = document.getElementsByTagName(cdata); + LOG.info(nodes.getLength() + " nodes found by " + cdata); + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + CDATASection cdataSection = document.createCDATASection(node.getTextContent()); + // Remove current content + node.setTextContent(null); + // Add it again, but wrapped with CDATA + node.appendChild(cdataSection); + } + document.createCDATASection(cdata); + } + DOMSource source = new DOMSource(document); + StreamResult streamResult = new StreamResult(out); + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + transformer.transform(source, streamResult); + LOG.info("Wrote " + result + " in " + filePath); return true; } catch (Exception e) { LOG.log(Level.SEVERE, "Could not serialize ResourceDoc.", e); diff --git a/pom.xml b/pom.xml index 156cf98b57..673e8efe63 100644 --- a/pom.xml +++ b/pom.xml @@ -2134,7 +2134,7 @@ 6.0.0 1.10.0 5.0.0 - 4.13.1 + 4.13.4 0.7.4 1.2.4 1.2.5 From 1d127e19cd92a10a9376c15104d89e8c5c0d27bb Mon Sep 17 00:00:00 2001 From: Maxim Nesen Date: Tue, 20 Jul 2021 12:55:32 +0200 Subject: [PATCH 2/4] Pax-Exam tests fix Signed-off-by: Maxim Nesen --- pom.xml | 8 ++++++++ tests/osgi/functional/pom.xml | 5 +++++ .../jersey/osgi/test/basic/ApacheOsgiIntegrationTest.java | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 673e8efe63..543789b6bb 100644 --- a/pom.xml +++ b/pom.xml @@ -1799,6 +1799,13 @@ provided + + org.osgi + org.osgi.service.cm + ${osgi.service.cm.version} + provided + + org.glassfish.main.ejb ejb-container @@ -2134,6 +2141,7 @@ 6.0.0 1.10.0 5.0.0 + 1.6.0 4.13.4 0.7.4 1.2.4 diff --git a/tests/osgi/functional/pom.xml b/tests/osgi/functional/pom.xml index c9a5ff1403..fe64512f7e 100644 --- a/tests/osgi/functional/pom.xml +++ b/tests/osgi/functional/pom.xml @@ -100,6 +100,11 @@ jakarta.annotation-api test + + org.osgi + org.osgi.service.cm + test + org.ops4j.pax.exam pax-exam diff --git a/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/ApacheOsgiIntegrationTest.java b/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/ApacheOsgiIntegrationTest.java index 1207b51b71..d6df4e8750 100644 --- a/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/ApacheOsgiIntegrationTest.java +++ b/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/ApacheOsgiIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2021 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,6 +55,7 @@ public static Option[] configuration() { final List + + org.osgi + org.osgi.service.cm + test + org.ops4j.pax.exam pax-exam-junit4 diff --git a/examples/osgi-helloworld-webapp/functional-test/src/test/java/org/glassfish/jersey/examples/helloworld/test/WebAppFelixTest.java b/examples/osgi-helloworld-webapp/functional-test/src/test/java/org/glassfish/jersey/examples/helloworld/test/WebAppFelixTest.java index 4a6c2514cf..44fc5741d2 100644 --- a/examples/osgi-helloworld-webapp/functional-test/src/test/java/org/glassfish/jersey/examples/helloworld/test/WebAppFelixTest.java +++ b/examples/osgi-helloworld-webapp/functional-test/src/test/java/org/glassfish/jersey/examples/helloworld/test/WebAppFelixTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2021 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,7 @@ public class WebAppFelixTest extends AbstractWebAppTest { @Override public List + + org.osgi + org.osgi.service.http + 1.2.1 + test + + + org.osgi + org.osgi.service.cm + test + + + junit junit @@ -200,6 +213,16 @@ test + + + + org.glassfish.jersey.examples.osgihttpservice.test.GrizzlyHttpServiceFelixTest + + diff --git a/examples/osgi-http-service/functional-test/src/test/java/org/glassfish/jersey/examples/osgihttpservice/test/JettyHttpServiceFelixTest.java b/examples/osgi-http-service/functional-test/src/test/java/org/glassfish/jersey/examples/osgihttpservice/test/JettyHttpServiceFelixTest.java index f73bb1195e..0f5ee0cd90 100644 --- a/examples/osgi-http-service/functional-test/src/test/java/org/glassfish/jersey/examples/osgihttpservice/test/JettyHttpServiceFelixTest.java +++ b/examples/osgi-http-service/functional-test/src/test/java/org/glassfish/jersey/examples/osgihttpservice/test/JettyHttpServiceFelixTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2021 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 @@ -27,6 +27,8 @@ public class JettyHttpServiceFelixTest extends AbstractHttpServiceTest { @Override public List