Search in sources :

Example 1 with FlowSerializationException

use of org.apache.nifi.controller.serialization.FlowSerializationException in project nifi by apache.

the class StandardFlowServiceTest method testLoadExistingFlowWithCorruptFlow.

@Test
public void testLoadExistingFlowWithCorruptFlow() throws IOException {
    byte[] originalBytes = IOUtils.toByteArray(StandardFlowServiceTest.class.getResourceAsStream("/conf/all-flow.xml"));
    flowService.load(new StandardDataFlow(originalBytes, null, null, new HashSet<>()));
    try {
        byte[] updatedBytes = IOUtils.toByteArray(StandardFlowServiceTest.class.getResourceAsStream("/conf/all-flow-corrupt.xml"));
        flowService.load(new StandardDataFlow(updatedBytes, null, null, new HashSet<>()));
        fail("should have thrown " + FlowSerializationException.class);
    } catch (FlowSerializationException ufe) {
        FlowSerializer serializer = new StandardFlowSerializer(mockEncryptor);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        serializer.serialize(flowController, baos, ScheduledStateLookup.IDENTITY_LOOKUP);
        String expectedFlow = new String(originalBytes).trim();
        String actualFlow = new String(baos.toByteArray()).trim();
        Assert.assertEquals(expectedFlow, actualFlow);
    }
}
Also used : StandardDataFlow(org.apache.nifi.cluster.protocol.StandardDataFlow) StandardFlowSerializer(org.apache.nifi.controller.serialization.StandardFlowSerializer) FlowSerializationException(org.apache.nifi.controller.serialization.FlowSerializationException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StandardFlowSerializer(org.apache.nifi.controller.serialization.StandardFlowSerializer) FlowSerializer(org.apache.nifi.controller.serialization.FlowSerializer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with FlowSerializationException

use of org.apache.nifi.controller.serialization.FlowSerializationException in project nifi by apache.

the class StandardSnippetDeserializer method deserialize.

public static StandardSnippet deserialize(final InputStream inStream) {
    try {
        JAXBContext context = JAXBContext.newInstance(StandardSnippet.class);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        XMLStreamReader xsr = XmlUtils.createSafeReader(inStream);
        JAXBElement<StandardSnippet> snippetElement = unmarshaller.unmarshal(xsr, StandardSnippet.class);
        return snippetElement.getValue();
    } catch (final JAXBException | XMLStreamException e) {
        throw new FlowSerializationException(e);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(javax.xml.bind.JAXBException) FlowSerializationException(org.apache.nifi.controller.serialization.FlowSerializationException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) StandardSnippet(org.apache.nifi.controller.StandardSnippet)

Example 3 with FlowSerializationException

use of org.apache.nifi.controller.serialization.FlowSerializationException in project nifi by apache.

the class StandardSnippetSerializer method serialize.

public static byte[] serialize(final StandardSnippet snippet) {
    try {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final BufferedOutputStream bos = new BufferedOutputStream(baos);
        JAXBContext context = JAXBContext.newInstance(StandardSnippet.class);
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.marshal(snippet, bos);
        bos.flush();
        return baos.toByteArray();
    } catch (final IOException | JAXBException e) {
        throw new FlowSerializationException(e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBException(javax.xml.bind.JAXBException) FlowSerializationException(org.apache.nifi.controller.serialization.FlowSerializationException) JAXBContext(javax.xml.bind.JAXBContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 4 with FlowSerializationException

use of org.apache.nifi.controller.serialization.FlowSerializationException in project nifi by apache.

the class StandardXMLFlowConfigurationDAO method save.

@Override
public synchronized void save(final FlowController flow, final OutputStream os) throws IOException {
    try {
        final StandardFlowSerializer xmlTransformer = new StandardFlowSerializer(encryptor);
        flow.serialize(xmlTransformer, os);
    } catch (final FlowSerializationException fse) {
        throw new IOException(fse);
    }
}
Also used : StandardFlowSerializer(org.apache.nifi.controller.serialization.StandardFlowSerializer) FlowSerializationException(org.apache.nifi.controller.serialization.FlowSerializationException) IOException(java.io.IOException)

Example 5 with FlowSerializationException

use of org.apache.nifi.controller.serialization.FlowSerializationException in project nifi by apache.

the class TemplateDeserializer method deserialize.

public static TemplateDTO deserialize(final StreamSource source) {
    try {
        JAXBContext context = JAXBContext.newInstance(TemplateDTO.class);
        XMLStreamReader xsr = XmlUtils.createSafeReader(source);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        JAXBElement<TemplateDTO> templateElement = unmarshaller.unmarshal(xsr, TemplateDTO.class);
        return templateElement.getValue();
    } catch (final JAXBException | XMLStreamException e) {
        throw new FlowSerializationException(e);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) JAXBException(javax.xml.bind.JAXBException) FlowSerializationException(org.apache.nifi.controller.serialization.FlowSerializationException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

FlowSerializationException (org.apache.nifi.controller.serialization.FlowSerializationException)12 IOException (java.io.IOException)9 FlowSynchronizationException (org.apache.nifi.controller.serialization.FlowSynchronizationException)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 StandardDataFlow (org.apache.nifi.cluster.protocol.StandardDataFlow)4 StandardFlowSerializer (org.apache.nifi.controller.serialization.StandardFlowSerializer)4 JAXBContext (javax.xml.bind.JAXBContext)3 JAXBException (javax.xml.bind.JAXBException)3 DataFlow (org.apache.nifi.cluster.protocol.DataFlow)3 LifeCycleStartException (org.apache.nifi.lifecycle.LifeCycleStartException)3 BufferedOutputStream (java.io.BufferedOutputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Path (java.nio.file.Path)2 HashSet (java.util.HashSet)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2