Skip to content

Commit d524c05

Browse files
authored
Merge pull request #11 from mrcsparker/nifi-1.9.0
Updated to NiFi 1.9
2 parents c3483dd + 6e98776 commit d524c05

File tree

13 files changed

+160
-92
lines changed

13 files changed

+160
-92
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ documents into XML using the
2525
```bash
2626
> cd nifi-edireader-processor
2727
> mvn package
28-
> cp nifi-edireader-nar/target/nifi-edireader-nar-0.0.1.nar /NIFI_INSTALL/lib/
28+
> cp nifi-edireader-nar/target/nifi-edireader-nar-1.9.2.nar /NIFI_INSTALL/lib/
2929
```
3030

3131
## License

Diff for: nifi-edireader-nar/pom.xml

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<parent>
66
<artifactId>nifi-edireader-bundle</artifactId>
77
<groupId>org.apache.nifi</groupId>
8-
<version>1.6.0</version>
8+
<version>1.9.2</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

1212
<artifactId>nifi-edireader-nar</artifactId>
13-
<version>1.6.0</version>
13+
<version>1.9.2</version>
1414
<packaging>nar</packaging>
1515
<properties>
1616
<maven.javadoc.skip>true</maven.javadoc.skip>
@@ -21,9 +21,7 @@
2121
<dependency>
2222
<groupId>org.apache.nifi</groupId>
2323
<artifactId>nifi-edireader-processors</artifactId>
24-
<version>1.6.0</version>
24+
<version>1.9.2</version>
2525
</dependency>
2626
</dependencies>
27-
28-
2927
</project>

Diff for: nifi-edireader-processors/pom.xml

+12-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>nifi-edireader-bundle</artifactId>
77
<groupId>org.apache.nifi</groupId>
8-
<version>1.6.0</version>
8+
<version>1.9.2</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -16,33 +16,39 @@
1616
<dependency>
1717
<groupId>org.apache.nifi</groupId>
1818
<artifactId>nifi-api</artifactId>
19-
<version>1.6.0</version>
19+
<version>1.9.2</version>
2020
</dependency>
2121
<dependency>
2222
<groupId>org.apache.nifi</groupId>
2323
<artifactId>nifi-properties</artifactId>
24-
<version>1.6.0</version>
24+
<version>1.9.2</version>
2525
</dependency>
2626
<dependency>
2727
<groupId>org.apache.nifi</groupId>
2828
<artifactId>nifi-processor-utils</artifactId>
29-
<version>1.6.0</version>
29+
<version>1.9.2</version>
3030
</dependency>
3131
<dependency>
3232
<groupId>com.berryworks</groupId>
3333
<artifactId>edireader</artifactId>
34-
<version>5.4.12</version>
34+
<version>5.4.17</version>
3535
</dependency>
3636
<dependency>
3737
<groupId>org.apache.nifi</groupId>
3838
<artifactId>nifi-mock</artifactId>
39-
<version>1.6.0</version>
39+
<version>1.9.2</version>
4040
<scope>test</scope>
4141
</dependency>
4242
<dependency>
4343
<groupId>org.slf4j</groupId>
4444
<artifactId>slf4j-simple</artifactId>
4545
<scope>test</scope>
46+
<exclusions>
47+
<exclusion>
48+
<groupId>org.slf4j</groupId>
49+
<artifactId>slf4j-log4j12</artifactId>
50+
</exclusion>
51+
</exclusions>
4652
</dependency>
4753
<dependency>
4854
<groupId>junit</groupId>
@@ -51,6 +57,4 @@
5157
<scope>test</scope>
5258
</dependency>
5359
</dependencies>
54-
55-
5660
</project>

Diff for: nifi-edireader-processors/src/main/java/org/apache/nifi/processors/edireader/EdiToJSON.java

+24-17
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.apache.nifi.processor.exception.ProcessException;
1313
import org.apache.nifi.processor.util.StandardValidators;
1414
import org.apache.nifi.processors.edireader.json.JSONAdapter;
15-
import org.xml.sax.ContentHandler;
1615
import org.xml.sax.InputSource;
1716
import org.xml.sax.SAXException;
1817

@@ -24,13 +23,14 @@ public class EdiToJSON extends AbstractProcessor {
2423

2524
private List<PropertyDescriptor> properties;
2625
private Set<Relationship> relationships;
26+
private boolean hasError = false;
2727

2828
public static final Relationship REL_SUCCESS = new Relationship.Builder()
2929
.name("success")
3030
.description("success")
3131
.build();
3232

33-
private static final Relationship REL_FAILURE = new Relationship.Builder()
33+
public static final Relationship REL_FAILURE = new Relationship.Builder()
3434
.name("failure")
3535
.description("failure")
3636
.build();
@@ -47,14 +47,14 @@ public class EdiToJSON extends AbstractProcessor {
4747
@Override
4848
public void init(final ProcessorInitializationContext context) {
4949

50-
final List<PropertyDescriptor> properties = new ArrayList<>();
51-
properties.add(PRETTY_PRINT);
52-
this.properties = properties;
50+
final List<PropertyDescriptor> propertyDescriptors = new ArrayList<>();
51+
propertyDescriptors.add(PRETTY_PRINT);
52+
this.properties = propertyDescriptors;
5353

54-
Set<Relationship> relationships = new HashSet<>();
55-
relationships.add(REL_SUCCESS);
56-
relationships.add(REL_FAILURE);
57-
this.relationships = Collections.unmodifiableSet(relationships);
54+
Set<Relationship> relationshipSet = new HashSet<>();
55+
relationshipSet.add(REL_SUCCESS);
56+
relationshipSet.add(REL_FAILURE);
57+
this.relationships = Collections.unmodifiableSet(relationshipSet);
5858
}
5959

6060
@Override
@@ -81,7 +81,7 @@ public void onTrigger(ProcessContext processContext, ProcessSession session) thr
8181
InputSource inputSource = new InputSource(inputStream);
8282

8383
XMLTags xmlTags = new DefaultXMLTags();
84-
ContentHandler handler = new JSONAdapter(xmlTags);
84+
JSONAdapter handler = new JSONAdapter(xmlTags);
8585
EDIReader ediReader;
8686
char[] leftOver = null;
8787

@@ -93,20 +93,27 @@ public void onTrigger(ProcessContext processContext, ProcessSession session) thr
9393
}
9494

9595
if (prettyPrint) {
96-
outputStream.write(((JSONAdapter) handler).toPrettyJsonBytes());
96+
outputStream.write(handler.toPrettyJsonBytes());
9797
} else {
98-
outputStream.write(((JSONAdapter) handler).toJsonBytes());
98+
outputStream.write(handler.toJsonBytes());
9999
}
100100
} catch (SAXException e) {
101101
getLogger().error("SAXException: " + e.getMessage());
102-
session.transfer(flowFile, REL_FAILURE);
102+
hasError = true;
103+
} catch (Exception e) {
104+
getLogger().error("Exception: " + e.getMessage());
105+
hasError = true;
103106
}
104107
}));
105108

106-
session.transfer(flowFileClone, REL_SUCCESS);
107-
session.remove(flowFile);
109+
if (hasError) {
110+
session.transfer(flowFile, REL_FAILURE);
111+
session.remove(flowFileClone);
112+
} else {
113+
session.transfer(flowFileClone, REL_SUCCESS);
114+
session.remove(flowFile);
115+
}
116+
hasError = false;
108117
session.commit();
109118
}
110-
111-
112119
}

Diff for: nifi-edireader-processors/src/main/java/org/apache/nifi/processors/edireader/EdiToXML.java

+15-13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.berryworks.edireader.EDIParserFactory;
44

5+
import com.berryworks.edireader.error.MissingMandatoryElementException;
56
import org.apache.nifi.annotation.documentation.CapabilityDescription;
67
import org.apache.nifi.annotation.documentation.Tags;
78
import org.apache.nifi.components.PropertyDescriptor;
@@ -17,13 +18,11 @@
1718
import org.xml.sax.SAXException;
1819
import org.xml.sax.XMLReader;
1920

21+
import javax.xml.XMLConstants;
2022
import javax.xml.parsers.ParserConfigurationException;
2123
import javax.xml.parsers.SAXParser;
2224
import javax.xml.parsers.SAXParserFactory;
23-
import javax.xml.transform.Transformer;
24-
import javax.xml.transform.TransformerConfigurationException;
25-
import javax.xml.transform.TransformerException;
26-
import javax.xml.transform.TransformerFactory;
25+
import javax.xml.transform.*;
2726
import javax.xml.transform.sax.SAXSource;
2827
import javax.xml.transform.stream.StreamResult;
2928

@@ -46,21 +45,19 @@ public class EdiToXML extends AbstractProcessor {
4645
.description("success")
4746
.build();
4847

49-
private static final Relationship REL_FAILURE = new Relationship.Builder()
48+
public static final Relationship REL_FAILURE = new Relationship.Builder()
5049
.name("failure")
5150
.description("failure")
5251
.build();
5352

5453
@Override
5554
public void init(final ProcessorInitializationContext context) {
55+
this.properties = new ArrayList<>();
5656

57-
final List<PropertyDescriptor> properties = new ArrayList<>();
58-
this.properties = properties;
59-
60-
Set<Relationship> relationships = new HashSet<>();
61-
relationships.add(REL_SUCCESS);
62-
relationships.add(REL_FAILURE);
63-
this.relationships = Collections.unmodifiableSet(relationships);
57+
Set<Relationship> relationshipSet = new HashSet<>();
58+
relationshipSet.add(REL_SUCCESS);
59+
relationshipSet.add(REL_FAILURE);
60+
this.relationships = Collections.unmodifiableSet(relationshipSet);
6461
}
6562

6663
@Override
@@ -95,7 +92,10 @@ public void onTrigger(ProcessContext processContext, ProcessSession session) thr
9592

9693
// Establish an XSL Transformer to generate the XML output.
9794
TransformerFactory transformerFactory = TransformerFactory.newInstance();
95+
transformerFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
96+
9897
Transformer transformer = transformerFactory.newTransformer();
98+
transformer.setOutputProperty(OutputKeys.INDENT, "no");
9999

100100
// The StreamResult to capture the generated XML output.
101101
StreamResult streamResult = new StreamResult(outputStream);
@@ -114,7 +114,9 @@ public void onTrigger(ProcessContext processContext, ProcessSession session) thr
114114
hasError = true;
115115
} catch (TransformerException e) {
116116
getLogger().error("TransformerException: " + e.getMessage());
117-
e.printStackTrace();
117+
hasError = true;
118+
} catch (Exception e) {
119+
getLogger().error("Exception: " + e.getMessage());
118120
hasError = true;
119121
}
120122
}));

Diff for: nifi-edireader-processors/src/main/java/org/apache/nifi/processors/edireader/SplitEdi.java

+24-18
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.apache.nifi.annotation.documentation.Tags;
1111
import org.apache.nifi.components.PropertyDescriptor;
1212
import org.apache.nifi.flowfile.FlowFile;
13-
import org.apache.nifi.flowfile.attributes.CoreAttributes;
1413
import org.apache.nifi.processor.AbstractProcessor;
1514
import org.apache.nifi.processor.ProcessContext;
1615
import org.apache.nifi.processor.ProcessSession;
@@ -26,9 +25,7 @@
2625
import java.util.Collections;
2726
import java.util.HashSet;
2827
import java.util.List;
29-
import java.util.Map;
3028
import java.util.Set;
31-
import java.util.concurrent.atomic.AtomicInteger;
3229

3330
@EventDriven
3431
@SideEffectFree
@@ -49,6 +46,7 @@ public class SplitEdi extends AbstractProcessor {
4946

5047
private List<PropertyDescriptor> properties;
5148
private Set<Relationship> relationships;
49+
private boolean hasError = false;
5250

5351
public static final Relationship REL_ORIGINAL = new Relationship.Builder()
5452
.name("original")
@@ -67,14 +65,13 @@ public class SplitEdi extends AbstractProcessor {
6765
@Override
6866
public void init(final ProcessorInitializationContext context) {
6967

70-
final List<PropertyDescriptor> properties = new ArrayList<>();
71-
this.properties = properties;
68+
this.properties = new ArrayList<>();
7269

73-
Set<Relationship> relationships = new HashSet<>();
74-
relationships.add(REL_ORIGINAL);
75-
relationships.add(REL_SPLIT);
76-
relationships.add(REL_FAILURE);
77-
this.relationships = Collections.unmodifiableSet(relationships);
70+
Set<Relationship> relationshipSet = new HashSet<>();
71+
relationshipSet.add(REL_ORIGINAL);
72+
relationshipSet.add(REL_SPLIT);
73+
relationshipSet.add(REL_FAILURE);
74+
this.relationships = Collections.unmodifiableSet(relationshipSet);
7875
}
7976

8077
@Override
@@ -94,18 +91,27 @@ public void onTrigger(ProcessContext context, ProcessSession session) throws Pro
9491
return;
9592
}
9693

97-
InputStream input = session.read(original);
98-
Splitter ediSplitter = new Splitter(input);
94+
List<FlowFile> splitFlowFiles = new ArrayList<>();
9995

100-
try {
101-
ediSplitter.splitData(session, original);
102-
input.close();
103-
104-
session.transfer(original, REL_ORIGINAL);
105-
session.commit();
96+
try (InputStream input = session.read(original)) {
97+
Splitter ediSplitter = new Splitter(input);
98+
splitFlowFiles = ediSplitter.splitData(session, original);
10699
} catch (IOException e) {
107100
getLogger().error("IOException: " + e.getMessage());
101+
hasError = true;
102+
} catch (Exception e) {
103+
getLogger().error("Exception: " + e.getMessage());
104+
hasError = true;
105+
}
106+
107+
if (hasError) {
108108
session.transfer(original, REL_FAILURE);
109+
session.remove(splitFlowFiles);
110+
} else {
111+
session.transfer(splitFlowFiles, REL_SPLIT);
112+
session.transfer(original, REL_ORIGINAL);
109113
}
114+
hasError = false;
115+
session.commit();
110116
}
111117
}

Diff for: nifi-edireader-processors/src/main/java/org/apache/nifi/processors/edireader/json/JSONAdapter.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public JSONAdapter(XMLTags xmlTags) {
4545
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
4646
super.startElement(uri, localName, qName, attributes);
4747

48-
// logger.info("{}", attributes);
49-
5048
if (localName.startsWith(xmlTags.getInterchangeTag())) {
5149
startInterchange(uri, localName, qName, attributes);
5250
} else if (localName.startsWith(xmlTags.getReceiverTag())) {
@@ -100,7 +98,7 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
10098
}
10199

102100
@Override
103-
public void characters(char ch[], int start, int length) throws SAXException {
101+
public void characters(char[] ch, int start, int length) throws SAXException {
104102
String s = new String(ch, start, length);
105103
if (elementString != null) elementString += s;
106104
}
@@ -126,7 +124,6 @@ public byte[] toPrettyJsonBytes() throws JsonProcessingException {
126124
}
127125

128126
private void startInterchange(String uri, String localName, String qName, Attributes attributes) {
129-
// logger.info("{}", "Starting interchange");
130127
interchange = new Interchange();
131128
interchange.setAuthorizationQualifier(attributes.getValue("AuthorizationQual"));
132129
interchange.setAuthorizationInformation(attributes.getValue("Authorization"));
@@ -228,7 +225,6 @@ private void startSegmentSubElement(String uri, String localName, String qName,
228225
}
229226

230227
private void endSegmentSubElement(String uri, String localName, String qName) {
231-
// logger.info("{} {}", currentElement, elementString);
232228
elements.put(currentSubelementSequence, elementString);
233229
}
234230
}

0 commit comments

Comments
 (0)