Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2180#discussion_r160452108
  
    --- Diff: 
nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/GetMongo.java
 ---
    @@ -268,32 +248,29 @@ public void onTrigger(final ProcessContext context, 
final ProcessSession session
                                     String payload = buildBatch(batch, 
jsonTypeSetting);
                                     writeBatch(payload, context, session);
                                     batch = new ArrayList<>();
    -                            } catch (IOException ex) {
    +                            } catch (Exception ex) {
                                     getLogger().error("Error building batch", 
ex);
                                 }
                             }
                         }
                         if (batch.size() > 0) {
                             try {
                                 writeBatch(buildBatch(batch, jsonTypeSetting), 
context, session);
    -                        } catch (IOException ex) {
    +                        } catch (Exception ex) {
                                 getLogger().error("Error sending remainder of 
batch", ex);
                             }
                         }
                     } else {
                         while (cursor.hasNext()) {
                             flowFile = session.create();
    -                        flowFile = session.write(flowFile, new 
OutputStreamCallback() {
    -                            @Override
    -                            public void process(OutputStream out) throws 
IOException {
    -                                String json;
    -                                if 
(jsonTypeSetting.equals(JSON_TYPE_STANDARD)) {
    -                                    json = 
mapper.writerWithDefaultPrettyPrinter().writeValueAsString(cursor.next());
    -                                } else {
    -                                    json = cursor.next().toJson();
    -                                }
    -                                IOUtils.write(json, out);
    +                        flowFile = session.write(flowFile, out -> {
    +                            String json;
    +                            if 
(jsonTypeSetting.equals(JSON_TYPE_STANDARD)) {
    +                                json = 
mapper.writerWithDefaultPrettyPrinter().writeValueAsString(cursor.next());
    +                            } else {
    +                                json = cursor.next().toJson();
                                 }
    +                            IOUtils.write(json, out);
    --- End diff --
    
    Similar comment about character sets here, will a user want the flow file 
in a different encoding? If so you may need that Character Set property here 
instead.


---

Reply via email to