Announcement Announcement Module
Collapse
No announcement yet.
Xml writer exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Xml writer exception

    I am using Xml Writer to generate xml files and I am getting this error

    I am using MultiResourceItemWriter to generate multiple files

    org.springframework.batch.support.transaction.Flus hFailedException: Could not write to output buffer
    at org.springframework.batch.support.transaction.Tran sactionAwareBufferedWriter$1.afterCompletion(Trans actionAwareBufferedWriter.java:71)
    at org.springframework.transaction.support.Transactio nSynchronizationUtils.invokeAfterCompletion(Transa ctionSynchronizationUtils.java:157)
    at


    Caused by: java.io.IOException: Bad file descriptor
    at java.io.FileOutputStream.writeBytes(Native Method)

  • #2
    I'm getting the same error.

    I am using the org.springframework.batch.item.xml.StaxEventItemWr iter to write to an XML file. The problem for me seems to be linked to transactions. I get different behaviour based on whether I use transactions.

    If I use a transaction I get a FlushFailedException caused by an IOException: Bad File Descriptor.

    If I execute without a transaction, I don't get these errors, but I have to make sure that commit-interval on my step is higher than the complete item count or I get "org.postgresql.util.PSQLException: This ResultSet is closed."

    None of this occurs if I run spring batch directly in a test case. But as soon as I call it from a service level code operating within a separate transaction I get the errors above. This leads me to believe that the problem is with my transaction configuration but I have other batch jobs that run in the same way (albeit they all write from database to database, not to a file) and this is the first job I've had a problem with.

    Does anyone have a clue as to what I can look at to understand what I'm doing wrong?

    Here is the stack trace:

    Code:
    org.springframework.batch.support.transaction.FlushFailedException: Could not write to output buffer
    	at org.springframework.batch.support.transaction.TransactionAwareBufferedWriter$1.afterCompletion(TransactionAwareBufferedWriter.java:71)
    	at org.springframework.transaction.support.TransactionSynchronizationUtils.invokeAfterCompletion(TransactionSynchronizationUtils.java:157)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.invokeAfterCompletion(AbstractPlatformTransactionManager.java:974)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCompletion(AbstractPlatformTransactionManager.java:949)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:777)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701)
    	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
    	at com.xxx.AbstractSpringBatchService.runJob(AbstractSpringBatchService.java:x)
    	at com.xxx.ServiceBatch.generate(ServiceBatch.java:x)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    	at $Proxy50.generate(Unknown Source)
    	at com.xxx.test.BatchTest.testGenerate(BatchTest.java:x)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:160)
    	at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:233)
    	at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333)
    	at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
    	at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
    	at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:160)
    	at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
    	at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
    	at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
    	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
    	at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
    	at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
    	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
    	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
    	at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
    	at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
    Caused by: java.io.IOException: Bad file descriptor
    	at java.io.FileOutputStream.writeBytes(Native Method)
    	at java.io.FileOutputStream.write(FileOutputStream.java:260)
    	at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:202)
    	at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:272)
    	at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:276)
    	at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:122)
    	at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:212)
    	at org.springframework.batch.support.transaction.TransactionAwareBufferedWriter$1.afterCompletion(TransactionAwareBufferedWriter.java:68)
    	... 47 more
    Last edited by danox; Oct 23rd, 2009, 12:12 AM. Reason: fixed bad formatting

    Comment


    • #3
      Another thing that may be effecting this is that I am using late binding to pass through the output filename in the following way:

      Code:
      <beans:bean id="writer" class="org.springframework.batch.item.xml.StaxEventItemWriter" scope="step">
      		<beans:property name="marshaller" ref="marshaller" />
      		<beans:property name="resource" value="#{jobParameters[output.path]}" />
      		<beans:property name="overwriteOutput" value="false" />
      		<beans:property name="rootTagName" value="Root" />
      		...
      	</beans:bean>
      Spring batch appears to be flushing the file buffer as the transaction completes. Could it be that trying to flush out the file buffer after the job is complete is causing this?

      Is there a way that I can make spring-batch flush the file buffer after the step, rather than after the completion of the transaction?

      Comment

      Working...
      X