Announcement Announcement Module
Collapse
No announcement yet.
problem in handling nested exception while parsing XML. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem in handling nested exception while parsing XML.

    hi,
    i'm running a job to read xml file .when bad record occurs during validation against xsd,job stop's execution.
    i need to continue my job and want to write all bad records in separate file.

    here's my code..

    <batch:job id="simpleJob" job-repository="jobRepository">
    <batch:step id="step1">
    <batch:tasklet>
    <batch:chunk reader="itemReader" writer="Writer"
    commit-interval="500"/>
    <batch:no-rollback-exception-classes>
    org.springframework.oxm.jaxb.JaxbUnmarshallingFail ureException
    </batch:no-rollback-exception-classes>

    </batch:tasklet>
    </batch:step>
    </batch:job>

    <bean id="inputFile" class="org.springframework.core.io.ClassPathResour ce" scope="step">
    <constructor-arg value="com/batch/todb/NHA_Repurchase.xml"/>
    </bean>

    <bean id="itemReader" class="org.springframework.batch.item.xml.StaxEven tItemReader" scope="step">
    <property name="fragmentRootElementName" value="ExposureData" />
    <property name="resource" ref="inputFile" />
    <property name="unmarshaller" ref="unMarshaller" />
    <property name="strict" value="true"/>
    </bean>

    <bean id="unMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshalle r" scope="step">
    <property name="classesToBeBound">
    <value>relationalMapping.ExpData</value>
    </property>
    <property name="schema" value="classpath:com/batch/todb/Exp_Data.xsd"/>
    </bean>

    <bean id="Writer" class="com.batch.todb.XmlFileWriter" scope="step">
    <property name="dataSource" ref="dataSource" />
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    can you say me how to continue the job and skip parse exceptions and JaxbUnmarshallingExceptions.

    thanks,
    gokul
    Last edited by krish3085; Nov 24th, 2009, 04:24 AM. Reason: missed some info

  • #2
    Is there something missing or unclear in the reference guide http://static.springsource.org/sprin...onfiguringSkip?

    Comment


    • #3
      Originally posted by Dave Syer View Post
      Is there something missing or unclear in the reference guide http://static.springsource.org/sprin...onfiguringSkip?
      but itz not working here.
      when the bad record occurs ,i want to skip it and move cursor to nextFragment in xml file.
      when exception occurs ,whole job seems to be rollbacked.

      how to skip the bad record and move cursor to next fragment.

      thanks,
      GOkul

      Comment


      • #4
        You haven't set a skippable exception list. Also make sure you upgrade to the latest Batch version (2.0.4 is GA, or 2.1.0 is in milestones).

        Please use [code][/code] tags for code and stack traces.

        Comment


        • #5
          i have configured like this...

          <batch:job id="simpleJob" job-repository="jobRepository">
          <batch:step id="step1">
          <batch:tasklet>
          <batch:chunk reader="itemReader"
          processor="itemProcessor" writer="Writer"
          commit-interval="500" skip-limit="500">
          <batch:skippable-exception-classes>
          org.xml.sax.SAXParseException
          javax.xml.bind.UnmarshalException
          org.springframework.oxm.jaxb.JaxbUnmarshallingFail ureException
          javax.xml.bind.UnmarshalException
          </batch:skippable-exception-classes>
          </batch:chunk>
          <batch:no-rollback-exception-classes>
          org.springframework.oxm.jaxb.JaxbUnmarshallingFail ureException
          </batch:no-rollback-exception-classes>
          <batch:listeners>
          <batch:listener ref="itemSkipListener"/>
          </batch:listeners>
          </batch:tasklet>
          </batch:step>
          </batch:job>

          but still it throws exception to chunk and tranction get rollbacked.
          am using spring-batch-2.0 version.

          exception occurs like...


          javax.xml.bind.UnmarshalException
          - with linked exception:
          [org.xml.sax.SAXParseException: cvc-enumeration-valid: Value 'a' is not facet-valid with respect to enumeration '[Current Account, Saving Account, Foreign CCY Saving, Time Deposit, Other Deposit, Segregated Account, Advanced to Customers, Advanced to Other, Unsettled Trade, Deposit Received, Advance Cost, Accounts Due, Call Loan, Bill Discount, Loan, Loan to Employee, Margin Trade, Repurchase Agreement, Repurchase, Other Loan Transaction, Swap, Interest Future, Forex Future, Other OTC Derivative, Land and Building, Equipment and Fixtures, Construction Suspense Account, Software, Other Asset, Deferred Tax Asset, Refunded Corporation Tax, Off Balance Trade, Deposits]'. It must be a value from the enumeration.]
          at com.sun.xml.internal.bind.v2.runtime.unmarshaller. UnmarshallerImpl.handleStreamException(Unknown Source)
          at com.sun.xml.internal.bind.v2.runtime.unmarshaller. UnmarshallerImpl.unmarshal0(Unknown Source)
          at com.sun.xml.internal.bind.v2.runtime.unmarshaller. UnmarshallerImpl.unmarshal(Unknown Source)
          at com.batch.todb.Jaxb2Marshaller.unmarshalStaxSource (Jaxb2Marshaller.java:296)
          at com.batch.todb.Jaxb2Marshaller.unmarshal(Jaxb2Mars haller.java:173)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
          at java.lang.reflect.Method.invoke(Unknown Source)
          at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:307)
          at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:182)
          at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :149)
          at org.springframework.aop.support.DelegatingIntroduc tionInterceptor.doProceed(DelegatingIntroductionIn terceptor.java:131)
          at org.springframework.aop.support.DelegatingIntroduc tionInterceptor.invoke(DelegatingIntroductionInter ceptor.java:119)
          at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
          at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204)
          at $Proxy8.unmarshal(Unknown Source)
          at com.batch.todb.StaxEventItemReader.doRead(StaxEven tItemReader.java:210)
          at org.springframework.batch.item.support.AbstractIte mCountingItemStreamItemReader.read(AbstractItemCou ntingItemStreamItemReader.java:84)
          at org.springframework.batch.core.step.item.SimpleChu nkProvider.doRead(SimpleChunkProvider.java:90)
          at org.springframework.batch.core.step.item.FaultTole rantChunkProvider.read(FaultTolerantChunkProvider. java:53)
          at org.springframework.batch.core.step.item.SimpleChu nkProvider$1.doInIteration(SimpleChunkProvider.jav a:106)
          at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:352)
          at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:212)
          at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:143)
          at org.springframework.batch.core.step.item.SimpleChu nkProvider.provide(SimpleChunkProvider.java:103)
          at org.springframework.batch.core.step.item.ChunkOrie ntedTasklet.execute(ChunkOrientedTasklet.java:64)
          at org.springframework.batch.core.step.tasklet.Taskle tStep$2.doInChunkContext(TaskletStep.java:264)
          at org.springframework.batch.core.scope.context.StepC ontextRepeatCallback.doInIteration(StepContextRepe atCallback.java:67)
          at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:352)
          at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:212)
          at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:143)
          at org.springframework.batch.core.step.tasklet.Taskle tStep.doExecute(TaskletStep.java:239)
          at org.springframework.batch.core.step.AbstractStep.e xecute(AbstractStep.java:197)
          at org.springframework.batch.core.job.AbstractJob.han dleStep(AbstractJob.java:348)
          at org.springframework.batch.core.job.flow.FlowJob.ac cess$100(FlowJob.java:43)
          at org.springframework.batch.core.job.flow.FlowJob$Jo bFlowExecutor.executeStep(FlowJob.java:137)
          at org.springframework.batch.core.job.flow.support.st ate.StepState.handle(StepState.java:60)
          at org.springframework.batch.core.job.flow.support.Si mpleFlow.resume(SimpleFlow.java:144)
          at org.springframework.batch.core.job.flow.support.Si mpleFlow.start(SimpleFlow.java:124)
          at org.springframework.batch.core.job.flow.FlowJob.do Execute(FlowJob.java:105)
          at org.springframework.batch.core.job.AbstractJob.exe cute(AbstractJob.java:250)
          at org.springframework.batch.core.launch.support.Simp leJobLauncher$1.run(SimpleJobLauncher.java:110)
          at org.springframework.core.task.SyncTaskExecutor.exe cute(SyncTaskExecutor.java:49)
          at org.springframework.batch.core.launch.support.Simp leJobLauncher.run(SimpleJobLauncher.java:105)
          at com.batch.todb.ToDBBatchTestCase.startJobs(ToDBBat chTestCase.java:69)
          at com.batch.todb.ToDBBatchTestCase.main(ToDBBatchTes tCase.java:106)
          Caused by: org.xml.sax.SAXParseException: cvc-enumeration-valid: Value 'a' is not facet-valid with respect to enumeration '[Current Account, Saving Account, Foreign CCY Saving, Time Deposit, Other Deposit, Segregated Account, Advanced to Customers, Advanced to Other, Unsettled Trade, Deposit Received, Advance Cost, Accounts Due, Call Loan, Bill Discount, Loan, Loan to Employee, Margin Trade, Repurchase Agreement, Repurchase, Other Loan Transaction, Swap, Interest Future, Forex Future, Other OTC Derivative, Land and Building, Equipment and Fixtures, Construction Suspense Account, Software, Other Asset, Deferred Tax Asset, Refunded Corporation Tax, Off Balance Trade, Deposits]'. It must be a value from the enumeration.
          at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.createSAXParseException(Unknown Source)
          at com.sun.org.apache.xerces.intern


          itz all happening during xml validation. i need to skip the bad record and continue job execution.

          can u give me some idea how to skip bad record while validating and how to proceed further.

          thanks,
          GOkul

          Comment

          Working...
          X