Search in sources :

Example 1 with TooMuchDataException

use of org.subethamail.smtp.TooMuchDataException in project nifi by apache.

the class SmtpConsumer method data.

@Override
public void data(final InputStream data) throws RejectException, TooMuchDataException, IOException {
    final ProcessSession processSession = sessionFactory.createSession();
    final StopWatch watch = new StopWatch();
    watch.start();
    try {
        FlowFile flowFile = processSession.create();
        final AtomicBoolean limitExceeded = new AtomicBoolean(false);
        flowFile = processSession.write(flowFile, (OutputStream out) -> {
            final LimitingInputStream lis = new LimitingInputStream(data, maxMessageSize);
            IOUtils.copy(lis, out);
            if (lis.hasReachedLimit()) {
                limitExceeded.set(true);
            }
        });
        if (limitExceeded.get()) {
            throw new TooMuchDataException("Maximum message size limit reached - client must send smaller messages");
        }
        flowFile = processSession.putAllAttributes(flowFile, extractMessageAttributes());
        watch.stop();
        processSession.getProvenanceReporter().receive(flowFile, "smtp://" + host + ":" + port + "/", watch.getDuration(TimeUnit.MILLISECONDS));
        processSession.transfer(flowFile, ListenSMTP.REL_SUCCESS);
        processSession.commit();
    } catch (FlowFileAccessException | IllegalStateException | RejectException | IOException ex) {
        log.error("Unable to fully process input due to " + ex.getMessage(), ex);
        throw ex;
    } finally {
        // make sure this happens no matter what - is safe
        processSession.rollback();
    }
}
Also used : ProcessSession(org.apache.nifi.processor.ProcessSession) FlowFile(org.apache.nifi.flowfile.FlowFile) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TooMuchDataException(org.subethamail.smtp.TooMuchDataException) FlowFileAccessException(org.apache.nifi.processor.exception.FlowFileAccessException) OutputStream(java.io.OutputStream) RejectException(org.subethamail.smtp.RejectException) LimitingInputStream(org.apache.nifi.stream.io.LimitingInputStream) IOException(java.io.IOException) StopWatch(org.apache.nifi.util.StopWatch)

Aggregations

IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 FlowFile (org.apache.nifi.flowfile.FlowFile)1 ProcessSession (org.apache.nifi.processor.ProcessSession)1 FlowFileAccessException (org.apache.nifi.processor.exception.FlowFileAccessException)1 LimitingInputStream (org.apache.nifi.stream.io.LimitingInputStream)1 StopWatch (org.apache.nifi.util.StopWatch)1 RejectException (org.subethamail.smtp.RejectException)1 TooMuchDataException (org.subethamail.smtp.TooMuchDataException)1