Skip to content

Commit e97da04

Browse files
jbescossenivam
andauthored
Remove com.sun.org.apache.xml.internal (#4812)
* Remove com.sun.org.apache.xml.internal Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com> Co-authored-by: Maxim Nesen <maxim.nesen@oracle.com>
1 parent 9ce03df commit e97da04

File tree

8 files changed

+92
-39
lines changed

8 files changed

+92
-39
lines changed

examples/osgi-helloworld-webapp/functional-test/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@
9090
</dependency>
9191

9292
<!-- JUnit and Pax-Exam dependencies -->
93+
<dependency>
94+
<groupId>org.osgi</groupId>
95+
<artifactId>org.osgi.service.cm</artifactId>
96+
<scope>test</scope>
97+
</dependency>
9398
<dependency>
9499
<groupId>org.ops4j.pax.exam</groupId>
95100
<artifactId>pax-exam-junit4</artifactId>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2021 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
@@ -37,6 +37,7 @@ public class WebAppFelixTest extends AbstractWebAppTest {
3737
@Override
3838
public List<Option> osgiRuntimeOptions() {
3939
return Arrays.asList(CoreOptions.options(
40+
mavenBundle().groupId("org.osgi").artifactId("org.osgi.service.cm").versionAsInProject(),
4041
mavenBundle()
4142
.groupId("org.apache.felix").artifactId("org.apache.felix.eventadmin")
4243
.versionAsInProject()

examples/osgi-http-service/functional-test/pom.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@
106106
<scope>test</scope>
107107
</dependency>
108108

109+
<dependency>
110+
<groupId>org.osgi</groupId>
111+
<artifactId>org.osgi.service.http</artifactId>
112+
<version>1.2.1</version>
113+
<scope>test</scope>
114+
</dependency>
115+
<dependency>
116+
<groupId>org.osgi</groupId>
117+
<artifactId>org.osgi.service.cm</artifactId>
118+
<scope>test</scope>
119+
</dependency>
120+
121+
109122
<dependency>
110123
<groupId>junit</groupId>
111124
<artifactId>junit</artifactId>
@@ -200,6 +213,16 @@
200213
<goals>
201214
<goal>test</goal>
202215
</goals>
216+
<configuration>
217+
<excludes>
218+
<!--
219+
excluded due to javax.servlet-api collision -
220+
more than one version is required, so it is not possible to execute that test.
221+
(since pax-exam version 4.13.4)
222+
-->
223+
<exclude>org.glassfish.jersey.examples.osgihttpservice.test.GrizzlyHttpServiceFelixTest</exclude>
224+
</excludes>
225+
</configuration>
203226
</execution>
204227
</executions>
205228
</plugin>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2021 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
@@ -27,6 +27,8 @@ public class JettyHttpServiceFelixTest extends AbstractHttpServiceTest {
2727
@Override
2828
public List<Option> osgiRuntimeOptions() {
2929
return Arrays.asList(CoreOptions.options(
30+
mavenBundle().groupId("org.osgi").artifactId("org.osgi.service.http").versionAsInProject(),
31+
mavenBundle().groupId("org.osgi").artifactId("org.osgi.service.cm").versionAsInProject(),
3032
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.eventadmin").versionAsInProject()
3133
));
3234
}

ext/wadl-doclet/src/main/java/org/glassfish/jersey/wadl/doclet/DocletUtils.java

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021 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
@@ -16,29 +16,37 @@
1616

1717
package org.glassfish.jersey.wadl.doclet;
1818

19-
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
20-
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
21-
2219
import java.io.BufferedOutputStream;
20+
import java.io.ByteArrayInputStream;
2321
import java.io.FileOutputStream;
2422
import java.io.OutputStream;
2523
import java.io.StringWriter;
2624
import java.lang.reflect.Array;
2725
import java.lang.reflect.Field;
26+
import java.util.Arrays;
2827
import java.util.logging.Level;
2928
import java.util.logging.Logger;
3029

3130
import javax.xml.bind.JAXBContext;
3231
import javax.xml.bind.Marshaller;
32+
import javax.xml.parsers.DocumentBuilderFactory;
33+
import javax.xml.transform.Transformer;
34+
import javax.xml.transform.TransformerFactory;
35+
import javax.xml.transform.dom.DOMSource;
36+
import javax.xml.transform.stream.StreamResult;
3337

3438
import org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ResourceDocType;
39+
import org.w3c.dom.CDATASection;
40+
import org.w3c.dom.Document;
41+
import org.w3c.dom.Node;
42+
import org.w3c.dom.NodeList;
3543

3644
class DocletUtils {
3745

3846
private static final Logger LOG = Logger.getLogger(DocletUtils.class.getName());
3947

4048
private static String[] getCDataElements(DocProcessor docProcessor) {
41-
String[] original = new String[]{"ns1^commentText", "ns2^commentText", "^commentText" };
49+
String[] original = new String[]{"commentText"};
4250
if (docProcessor == null) {
4351
return original;
4452
} else {
@@ -64,30 +72,6 @@ private static <T, U> T[] copyOf(U[] original, int newLength) {
6472
return copy;
6573
}
6674

67-
private static XMLSerializer getXMLSerializer(OutputStream os, String[] cdataElements)
68-
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
69-
// configure an OutputFormat to handle CDATA
70-
OutputFormat of = new OutputFormat();
71-
72-
// specify which of your elements you want to be handled as CDATA.
73-
// The use of the '^' between the namespaceURI and the localname
74-
// seems to be an implementation detail of the xerces code.
75-
// When processing xml that doesn't use namespaces, simply omit the
76-
// namespace prefix as shown in the third CDataElement below.
77-
of.setCDataElements(cdataElements);
78-
79-
// set any other options you'd like
80-
of.setPreserveSpace(true);
81-
of.setIndenting(true);
82-
83-
// create the serializer
84-
XMLSerializer serializer = new XMLSerializer(of);
85-
86-
serializer.setOutputByteStream(os);
87-
88-
return serializer;
89-
}
90-
9175
private static Class<?>[] getJAXBContextClasses(ResourceDocType result, DocProcessor docProcessor) {
9276
Class<?>[] clazzes;
9377
if (docProcessor == null) {
@@ -108,15 +92,39 @@ private static Class<?>[] getJAXBContextClasses(ResourceDocType result, DocProce
10892
}
10993

11094
static boolean createOutputFile(String filePath, DocProcessor docProcessor, ResourceDocType result) {
95+
String[] cdataElements = getCDataElements(docProcessor);
96+
Class<?>[] classes = getJAXBContextClasses(result, docProcessor);
97+
LOG.info("cdataElements " + Arrays.asList(cdataElements));
98+
LOG.info("classes " + Arrays.asList(classes));
11199
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(filePath))) {
112-
Class<?>[] clazzes = getJAXBContextClasses(result, docProcessor);
113-
JAXBContext c = JAXBContext.newInstance(clazzes);
100+
JAXBContext c = JAXBContext.newInstance(classes);
114101
Marshaller m = c.createMarshaller();
115102
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
116-
String[] cdataElements = getCDataElements(docProcessor);
117-
XMLSerializer serializer = getXMLSerializer(out, cdataElements);
118-
m.marshal(result, serializer);
119-
LOG.info("Wrote " + result);
103+
StringWriter sw = new StringWriter();
104+
// Produces XML in memory
105+
m.marshal(result, sw);
106+
// Loads the XML from memory for processing
107+
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder()
108+
.parse(new ByteArrayInputStream(sw.toString().getBytes()));
109+
for (String cdata : cdataElements) {
110+
NodeList nodes = document.getElementsByTagName(cdata);
111+
LOG.info(nodes.getLength() + " nodes found by " + cdata);
112+
for (int i = 0; i < nodes.getLength(); i++) {
113+
Node node = nodes.item(i);
114+
CDATASection cdataSection = document.createCDATASection(node.getTextContent());
115+
// Remove current content
116+
node.setTextContent(null);
117+
// Add it again, but wrapped with CDATA
118+
node.appendChild(cdataSection);
119+
}
120+
document.createCDATASection(cdata);
121+
}
122+
DOMSource source = new DOMSource(document);
123+
StreamResult streamResult = new StreamResult(out);
124+
TransformerFactory transformerFactory = TransformerFactory.newInstance();
125+
Transformer transformer = transformerFactory.newTransformer();
126+
transformer.transform(source, streamResult);
127+
LOG.info("Wrote " + result + " in " + filePath);
120128
return true;
121129
} catch (Exception e) {
122130
LOG.log(Level.SEVERE, "Could not serialize ResourceDoc.", e);

pom.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,13 @@
17991799
<scope>provided</scope>
18001800
</dependency>
18011801

1802+
<dependency>
1803+
<groupId>org.osgi</groupId>
1804+
<artifactId>org.osgi.service.cm</artifactId>
1805+
<version>${osgi.service.cm.version}</version>
1806+
<scope>provided</scope>
1807+
</dependency>
1808+
18021809
<dependency>
18031810
<groupId>org.glassfish.main.ejb</groupId>
18041811
<artifactId>ejb-container</artifactId>
@@ -2140,7 +2147,8 @@
21402147
<osgi.version>6.0.0</osgi.version>
21412148
<osgi.framework.version>1.10.0</osgi.framework.version>
21422149
<osgi.compendium.version>5.0.0</osgi.compendium.version>
2143-
<pax.exam.version>4.13.1</pax.exam.version>
2150+
<osgi.service.cm.version>1.6.0</osgi.service.cm.version>
2151+
<pax.exam.version>4.13.4</pax.exam.version>
21442152
<pax.web.version>0.7.4</pax.web.version><!-- TODO: UPGRADE! -->
21452153
<paxexam.mvn.plugin.version>1.2.4</paxexam.mvn.plugin.version>
21462154
<rxjava.version>1.2.5</rxjava.version>

tests/osgi/functional/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@
100100
<artifactId>jakarta.annotation-api</artifactId>
101101
<scope>test</scope>
102102
</dependency>
103+
<dependency>
104+
<groupId>org.osgi</groupId>
105+
<artifactId>org.osgi.service.cm</artifactId>
106+
<scope>test</scope>
107+
</dependency>
103108
<dependency>
104109
<groupId>org.ops4j.pax.exam</groupId>
105110
<artifactId>pax-exam</artifactId>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021 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
@@ -55,6 +55,7 @@ public static Option[] configuration() {
5555
final List<Option> options = Helper.getCommonOsgiOptions();
5656
options.addAll(Helper.expandedList(
5757
mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-api").versionAsInProject(),
58+
mavenBundle().groupId("org.osgi").artifactId("org.osgi.service.cm").versionAsInProject(),
5859
mavenBundle().groupId("org.apache.httpcomponents").artifactId("httpcore-osgi").versionAsInProject(),
5960
mavenBundle().groupId("org.apache.httpcomponents").artifactId("httpclient-osgi").versionAsInProject(),
6061
mavenBundle().groupId("org.glassfish.jersey.connectors").artifactId("jersey-apache-connector")

0 commit comments

Comments
 (0)