Announcement Announcement Module
No announcement yet.
How to catch failing connections in classes that implement AbstractCursorItemReader? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to catch failing connections in classes that implement AbstractCursorItemReader?

    edit: hmpf can't edit the nonsensical thread title

    I am using a StoredProcedureItemReader to read data from an Oracle stored procedure.

    The problem is the connection will be over a vpn, and when the vpn is not up, the error that happens is not available to a step listener via onReadError(), but this happens:

    ERROR 15.04.2010 13:53:58: -- org.springframework.batch.core.step.AbstractStep - Encountered an error executing the step
    org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
    Caused by: java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
    It seems the reader opens the connection during initializing, which means the exception wont end up in a StepListener.

    so how to solve this? I need to catch basically all exceptions and make sure they're properly logged and notified about via email.

    edit: current config if it helps any:

    all this works fine if the connection is up when the job starts, if its down, the exceptions go unnoticed by the listener
    <b:job id="my-job" incrementer="jobParametersIncrementer" restartable="false">
            <b:step id="my-step-id" parent="baseStep" > 
                    <b:chunk reader="myReader" writer="myWriter" />
                        <b:listener ref="listener" />
    <bean id="listener" class="my.package.MyFailureLoggerListener">
            <property name="errorChannel" ref="errorChannel" /> <!-- spring integration default error channel -->
    <bean id="myReader" parent="baseReader" p:procedureName="mystoredprocedure">
            <property name="parameters">
            <property name="preparedStatementSetter">
                <bean class="my.Package.MyParameterSetter" />
    <bean id="baseReader" class="org.springframework.batch.item.database.StoredProcedureItemReader" abstract="true">
            <property name="dataSource" ref="myDataSource"/>
            <property name="refCursorPosition" value="3"/>
            <property name="rowMapper">
                <!-- preserves column order -->
                <bean class="org.springframework.jdbc.core.ColumnMapRowMapper"/>
    Last edited by deebo; Apr 15th, 2010, 06:41 AM.

  • #2
    OK since noone answered me, I went throught the listener interfaces and found that this job is better done via a JobListener anyhow

        public void afterJob(JobExecution exec) {
            if (exec.getExitStatus().equals(ExitStatus.FAILED) {
                for (Throwable t : exec.getAllFailureExceptions()) {
          "ERROR HAPPENED: ",t);

    Except the problem with this is that i don't have access to the chunk data in case of write errors...
    Anyone know what kind of errors go outside the scope of ItemReadListener and ItemWriteListener so I can come to some kind of a compromise?
    Last edited by deebo; Apr 19th, 2010, 01:15 AM.