From a2a8fcb31c3f845e05502fb5c0bad44ba82a97ed Mon Sep 17 00:00:00 2001 From: Matt Gilman Date: Tue, 2 Jan 2018 14:57:08 -0500 Subject: [PATCH] NIFI-4092: This closes #2365. - Removing direct dependency on jaxb. Signed-off-by: joewitt --- .../src/main/resources/META-INF/NOTICE | 2 - .../nifi-framework-core/pom.xml | 5 --- .../nifi/persistence/TemplateSerializer.java | 12 ++---- .../persistence/TemplateSerializerTest.java | 41 ++++++++++--------- 4 files changed, 24 insertions(+), 36 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework-nar/src/main/resources/META-INF/NOTICE b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework-nar/src/main/resources/META-INF/NOTICE index 1e9c12832f..9efa937ea5 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework-nar/src/main/resources/META-INF/NOTICE +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework-nar/src/main/resources/META-INF/NOTICE @@ -183,8 +183,6 @@ The following binary components are provided under the Common Development and Di (CDDL 1.1) (GPL2 w/ CPE) asm-all-repackaged (org.glassfish.hk2.external:asm-all-repackaged:jar:2.5.0-b42 - https://javaee.github.io/glassfish/) (CDDL 1.1) (GPL2 w/ CPE) aopalliance-repackaged (org.glassfish.hk2.external:aopalliance-repackaged:jar:2.5.0-b42 - https://javaee.github.io/glassfish/) (CDDL 1.1) (GPL2 w/ CPE) javax.inject:1 as OSGi bundle (org.glassfish.hk2.external:javax.inject:jar:2.4.0-b25 - https://hk2.java.net/external/javax.inject) - (CDDL 1.1) (GPL2 w/ CPE) Old JAXB Runtime (com.sun.xml.bind:jaxb-impl:jar:2.2.3-1 - http://jaxb.java.net/) - (CDDL 1.1) (GPL2 w/ CPE) Java Architecture For XML Binding (javax.xml.bind:jaxb-api:jar:2.2.2 - https://jaxb.dev.java.net/) (CDDL 1.1) (GPL2 w/ CPE) MIME Streaming Extension (org.jvnet.mimepull:mimepull:jar:1.9.3 - http://mimepull.java.net) (CDDL 1.1) (GPL2 w/ CPE) JavaMail API (compat) (javax.mail:mail:jar:1.4.7 - http://kenai.com/projects/javamail/mail) (CDDL 1.1) (GPL2 w/ CPE) javax.ws.rs-api (javax.ws.rs:javax.ws.rs-api:jar:2.1 - http://jax-rs-spec.java.net) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml index 0daced4458..d53eb49833 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml @@ -103,11 +103,6 @@ org.bouncycastle bcprov-jdk15on - - com.sun.xml.bind - jaxb-impl - 2.2.3-1 - org.glassfish.jersey.core jersey-client diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/persistence/TemplateSerializer.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/persistence/TemplateSerializer.java index 176dc431b9..8de13165c4 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/persistence/TemplateSerializer.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/persistence/TemplateSerializer.java @@ -25,11 +25,6 @@ import javax.xml.bind.Marshaller; import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; - -import com.sun.xml.txw2.output.IndentingXMLStreamWriter; public final class TemplateSerializer { @@ -46,13 +41,12 @@ public final class TemplateSerializer { JAXBContext context = JAXBContext.newInstance(TemplateDTO.class); Marshaller marshaller = context.createMarshaller(); - XMLOutputFactory xmlof = XMLOutputFactory.newInstance(); - XMLStreamWriter writer = new IndentingXMLStreamWriter(xmlof.createXMLStreamWriter(bos)); - marshaller.marshal(dto, writer); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + marshaller.marshal(dto, bos); bos.flush(); return baos.toByteArray(); //Note: For really large templates this could use a lot of heap space - } catch (final IOException | JAXBException | XMLStreamException e) { + } catch (final IOException | JAXBException e) { throw new FlowSerializationException(e); } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/persistence/TemplateSerializerTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/persistence/TemplateSerializerTest.java index 1683cf7c8a..c04b4ddf95 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/persistence/TemplateSerializerTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/persistence/TemplateSerializerTest.java @@ -16,21 +16,6 @@ */ package org.apache.nifi.persistence; -import static org.junit.Assert.assertEquals; - -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.Unmarshaller; -import javax.xml.stream.XMLStreamReader; import org.apache.nifi.security.xml.XmlUtils; import org.apache.nifi.util.ComponentIdGenerator; import org.apache.nifi.web.api.dto.FlowSnippetDTO; @@ -43,6 +28,22 @@ import org.eclipse.jgit.diff.RawText; import org.eclipse.jgit.diff.RawTextComparator; import org.junit.Test; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.Unmarshaller; +import javax.xml.stream.XMLStreamReader; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertEquals; + public class TemplateSerializerTest { @Test @@ -106,11 +107,11 @@ public class TemplateSerializerTest { List changes = reader.lines().peek(System.out::println) .filter(line -> line.startsWith("+") || line.startsWith("-")).collect(Collectors.toList()); - assertEquals("+ Hello-0", changes.get(0)); - assertEquals("+ Hello-2", changes.get(1)); - assertEquals("+ ", changes.get(2)); - assertEquals("+ ProcessorNew.class", changes.get(4)); - assertEquals("+ ", changes.get(5)); + assertEquals("+ Hello-0", changes.get(0)); + assertEquals("+ Hello-2", changes.get(1)); + assertEquals("+ ", changes.get(2)); + assertEquals("+ ProcessorNew.class", changes.get(4)); + assertEquals("+ ", changes.get(5)); } }