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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations