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

Remove com.sun.org.apache.xml.internal #4812

Merged
merged 5 commits into from
Sep 9, 2021
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
5 changes: 5 additions & 0 deletions examples/osgi-helloworld-webapp/functional-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
</dependency>

<!-- JUnit and Pax-Exam dependencies -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.cm</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-junit4</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -37,6 +37,7 @@ public class WebAppFelixTest extends AbstractWebAppTest {
@Override
public List<Option> osgiRuntimeOptions() {
return Arrays.asList(CoreOptions.options(
mavenBundle().groupId("org.osgi").artifactId("org.osgi.service.cm").versionAsInProject(),
mavenBundle()
.groupId("org.apache.felix").artifactId("org.apache.felix.eventadmin")
.versionAsInProject()
Expand Down
23 changes: 23 additions & 0 deletions examples/osgi-http-service/functional-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.http</artifactId>
<version>1.2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.cm</artifactId>
<scope>test</scope>
</dependency>


<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down Expand Up @@ -200,6 +213,16 @@
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<!--
excluded due to javax.servlet-api collision -
more than one version is required, so it is not possible to execute that test.
(since pax-exam version 4.13.4)
-->
<exclude>org.glassfish.jersey.examples.osgihttpservice.test.GrizzlyHttpServiceFelixTest</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -27,6 +27,8 @@ public class JettyHttpServiceFelixTest extends AbstractHttpServiceTest {
@Override
public List<Option> osgiRuntimeOptions() {
return Arrays.asList(CoreOptions.options(
mavenBundle().groupId("org.osgi").artifactId("org.osgi.service.http").versionAsInProject(),
mavenBundle().groupId("org.osgi").artifactId("org.osgi.service.cm").versionAsInProject(),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.eventadmin").versionAsInProject()
));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand All @@ -64,30 +72,6 @@ private static <T, U> 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) {
Expand All @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,13 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.cm</artifactId>
<version>${osgi.service.cm.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.glassfish.main.ejb</groupId>
<artifactId>ejb-container</artifactId>
Expand Down Expand Up @@ -2134,7 +2141,8 @@
<osgi.version>6.0.0</osgi.version>
<osgi.framework.version>1.10.0</osgi.framework.version>
<osgi.compendium.version>5.0.0</osgi.compendium.version>
<pax.exam.version>4.13.1</pax.exam.version>
<osgi.service.cm.version>1.6.0</osgi.service.cm.version>
<pax.exam.version>4.13.4</pax.exam.version>
<pax.web.version>0.7.4</pax.web.version><!-- TODO: UPGRADE! -->
<paxexam.mvn.plugin.version>1.2.4</paxexam.mvn.plugin.version>
<rxjava.version>1.2.5</rxjava.version>
Expand Down
5 changes: 5 additions & 0 deletions tests/osgi/functional/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
<artifactId>jakarta.annotation-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.cm</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -55,6 +55,7 @@ public static Option[] configuration() {
final List<Option> options = Helper.getCommonOsgiOptions();
options.addAll(Helper.expandedList(
mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-api").versionAsInProject(),
mavenBundle().groupId("org.osgi").artifactId("org.osgi.service.cm").versionAsInProject(),
mavenBundle().groupId("org.apache.httpcomponents").artifactId("httpcore-osgi").versionAsInProject(),
mavenBundle().groupId("org.apache.httpcomponents").artifactId("httpclient-osgi").versionAsInProject(),
mavenBundle().groupId("org.glassfish.jersey.connectors").artifactId("jersey-apache-connector")
Expand Down