Announcement Announcement Module
Collapse
No announcement yet.
Retrieving Error message, skipped record, line number Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Retrieving Error message, skipped record, line number

    Hi,

    I am currently using FlatFileItemReader to read the file, if the format of the line is bad that record will be skipped with help of SkipLimitStepFactoryBean. Also, I am using ValidatingItemReader to validate the business rules once the POJO is created.

    For each of the skipped & POJO Validator rejected records, I would like to know
    1. The line number in the file
    2. Error message generated by the SpringBatch Framework.

    This two information will be passed back to the user in UI.

    Can you please let me know the bestway to capture this in a centralized place, so that I could display/use this.

    Thanks in advance for your help on this.

    Thanks,
    vbforums

  • #2
    FlatFileParseException has the line count and a message about the invalid record. You can capture that information in a SkipListener or ItemReadListener.

    Comment


    • #3
      Dave,

      Thanks for your response. Below is the configuration of my Job and in which I am using existing Spring Validators

      Code:
      <bean id="personReader" class="org.springframework.batch.item.validator.ValidatingItemReader">
          <property name="validator" ref="validator" />
          <property name="itemReader" ref="reader"/> 
      </bean>
      <bean id="personJob" class="org.springframework.batch.core.job.SimpleJob">
          <property name="jobRepository" ref="jobRepository"/>
          <property name="steps">
              <bean id="step1"  parent="skipLimitStep" scope="prototype">     
      	<property name="streams"        ref="reader" />
              <property name="itemReader" ref="personReader" />
              <property name="itemWriter" ref="personItemWriter" />
              <property name="commitInterval" value="1" />
              <property name="listeners" ref="readListener"/>
              </bean>
          </property>
      </bean>
      1. If there is problem with parsing, Spring Batch throws FlatFileParseException, in my case I have associated the reader bean with a validator, if validator throws error, is there is a easy way to identify the line number in the file?(maintaining line count variable in the listener is not an option as reader might not know if the file has header row or not).

      2. In the suggested method(i.e maintaining the errors in the listener), I need to maintain some beans as scope="prototype"(as there will be multiple users who may be importing the file at the same time) and at the end of the Job I have to go thru each of the Step bean, get the listener and collect the error messages which could be done by extending the SimpleJob class. (2a) will I be able to get the error messages successfull from prototype beans to Spring Controller. (2b) which are all the beans which need to be define as prototype(listeners only?)

      p.s: We are having a file format which will be manually imported by the users as well as automatically consumed from a directory. When we get the file from the user we have to provide error message back to the user in the UI. I am trying to use the spring batch for this purpose.
      Last edited by vbforums; Nov 14th, 2008, 12:36 PM.

      Comment


      • #4
        This is a bit of an issue. We've addressed it in 2.0 with the addition of the LineMapper interface, however, it's still a little tricky in 1.1. You either need to keep your own count, allowing for headers. (you're the one configuring the number of skipped rows afterall) Or inspect the ExecutionContext key value.

        Comment

        Working...
        X