Announcement Announcement Module
Collapse
No announcement yet.
How to catch failing connections in classes that implement AbstractCursorItemReader? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

    Code:
    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
    Code:
    <b:job id="my-job" incrementer="jobParametersIncrementer" restartable="false">
            <b:step id="my-step-id" parent="baseStep" > 
                <b:tasklet>
                    <b:chunk reader="myReader" writer="myWriter" />
                    <b:listeners>
                        <b:listener ref="listener" />
                    </b:listeners>
                </b:tasklet>
            </b:step>
    </b:job>
    
    <bean id="listener" class="my.package.MyFailureLoggerListener">
            <property name="errorChannel" ref="errorChannel" /> <!-- spring integration default error channel -->
    </bean>
    
    <bean id="myReader" parent="baseReader" p:procedureName="mystoredprocedure">
            <property name="parameters">
            <list>
                ...
            </list>
            </property>
            <property name="preparedStatementSetter">
                <bean class="my.Package.MyParameterSetter" />
            </property>
    </bean>
    
    <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"/>
            </property>
    </bean>
    Last edited by deebo; Apr 15th, 2010, 07: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

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

    edit:
    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, 02:15 AM.

    Comment

    Working...
    X