public void testMessageInputLineCount() throws Exception { FlatFileParseException exception = new FlatFileParseException("foo", "bar", 100); assertEquals("foo", exception.getMessage()); assertEquals("bar", exception.getInput()); assertEquals(100, exception.getLineNumber()); }
assertEquals(3, e.getLineNumber()); assertEquals("testLine3", e.getInput());
assertEquals(2, expected.getLineNumber()); assertEquals("testLine2", expected.getInput()); assertEquals("Couldn't map line 2", expected.getCause().getMessage()); assertThat(expected.getMessage(), startsWith("Parsing error at line: 2 in resource=[")); assertThat(expected.getMessage(), endsWith("], input=[testLine2]"));
@Override public Exception getException(String msg, Throwable t) throws Exception { return new FlatFileParseException(msg, t, "bar", 100); }
@Override public void onSkipInRead(Throwable t) { if(t instanceof FlatFileParseException) { FlatFileParseException ffpe = (FlatFileParseException) t; jdbcTemplate.update( "insert into skipped_product (line,line_number) values (?,?)", ffpe.getInput(),ffpe.getLineNumber() //multiResourceItemReader.getCurrentResource().getFilename(), ffpe.getInput(),ffpe.getLineNumber() ); } }
@Override public Exception getException(String msg) throws Exception { return new FlatFileParseException(msg, "bar"); }
@Override public void onReadError(Exception ex) { if (ex instanceof FlatFileParseException) { FlatFileParseException ffpe = (FlatFileParseException) ex; logger.error(String.format("Error reading data on line '%s' - data: '%s'", ffpe.getLineNumber(), ffpe.getInput())); } chunkNotificationsChannel.send(MessageBuilder.withPayload(new Notification(ex.getMessage(),true)).build()); }
private String applyRecordSeparatorPolicy(String line) throws IOException { String record = line; while (line != null && !recordSeparatorPolicy.isEndOfRecord(record)) { line = this.reader.readLine(); if (line == null) { if (StringUtils.hasText(record)) { // A record was partially complete since it hasn't ended but // the line is null throw new FlatFileParseException("Unexpected end of file before record complete", record, lineCount); } else { // Record has no text but it might still be post processed // to something (skipping preProcess since that was already // done) break; } } else { lineCount++; } record = recordSeparatorPolicy.preProcess(record) + line; } return recordSeparatorPolicy.postProcess(record); }
@Override public void onReadError(Exception ex) { if (ex instanceof FlatFileParseException) { FlatFileParseException ffpe = (FlatFileParseException) ex; logger.error(String.format("Error reading data on line '%s' - data: '%s'", ffpe.getLineNumber(), ffpe.getInput())); } chunkNotificationsChannel.send(MessageBuilder.withPayload(new Notification(ex.getMessage(),true)).build()); }
/** * @return string corresponding to logical record according to * {@link #setRecordSeparatorPolicy(RecordSeparatorPolicy)} (might span multiple lines in file). */ @Override protected T doRead() throws Exception { if (noInput) { return null; } String line = readLine(); if (line == null) { return null; } else { try { return lineMapper.mapLine(line, lineCount); } catch (Exception ex) { throw new FlatFileParseException("Parsing error at line: " + lineCount + " in resource=[" + resource.getDescription() + "], input=[" + line + "]", ex, line, lineCount); } } }
@Override public void onReadError(Exception ex) { if (ex instanceof FlatFileParseException) { FlatFileParseException ffpe = (FlatFileParseException) ex; logger.error(String.format("Error reading data on line '%s' - data: '%s'", ffpe.getLineNumber(), ffpe.getInput())); } chunkNotificationsChannel.send(MessageBuilder.withPayload(new Notification(ex.getMessage(),true)).build()); }
@Test public void testLimitExceed() { try { failurePolicy.shouldSkip(new FlatFileParseException("", ""), 2); fail(); } catch (SkipLimitExceededException ex) { // expected } }
@Override public void onReadError(Exception ex) { if (ex instanceof FlatFileParseException) { FlatFileParseException ffpe = (FlatFileParseException) ex; logger.error(String.format("Error reading data on line '%s' - data: '%s'", ffpe.getLineNumber(), ffpe.getInput())); } chunkNotificationsChannel.send(MessageBuilder.withPayload(new Notification(ex.getMessage(),true)).build()); }
@Test public void testSkip() { assertTrue(failurePolicy.shouldSkip(new FlatFileParseException("", ""), 0)); }
private String applyRecordSeparatorPolicy(String line) throws IOException { String record = line; while (line != null && !recordSeparatorPolicy.isEndOfRecord(record)) { line = this.reader.readLine(); if (line == null) { if (StringUtils.hasText(record)) { // A record was partially complete since it hasn't ended but // the line is null throw new FlatFileParseException("Unexpected end of file before record complete", record, lineCount); } else { // Record has no text but it might still be post processed // to something (skipping preProcess since that was already // done) break; } } else { lineCount++; } record = recordSeparatorPolicy.preProcess(record) + line; } return recordSeparatorPolicy.postProcess(record); }
/** * @return string corresponding to logical record according to * {@link #setRecordSeparatorPolicy(RecordSeparatorPolicy)} (might span multiple lines in file). */ @Override protected T doRead() throws Exception { if (noInput) { return null; } String line = readLine(); if (line == null) { return null; } else { try { return lineMapper.mapLine(line, lineCount); } catch (Exception ex) { throw new FlatFileParseException("Parsing error at line: " + lineCount + " in resource=[" + resource.getDescription() + "], input=[" + line + "]", ex, line, lineCount); } } }
@Override @SuppressWarnings("unchecked") protected T doRead() throws Exception { if (reader == null) { return null; } try { return (T) reader.read(); } catch (BeanReaderIOException ex) { throw ex.getCause(); } catch (BeanReaderException ex) { if (useSpringExceptions) { RecordContext ctx = ex.getRecordContext(); if (ctx != null) { throw new FlatFileParseException(ex.getMessage(), ex, ctx.getRecordText(), ctx.getLineNumber()); } else { throw new FlatFileParseException(ex.getMessage(), ex, null, 0); } } else { throw ex; } } }