Announcement Announcement Module
Collapse
No announcement yet.
handling EndDocument in StaxEventItemReader Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • handling EndDocument in StaxEventItemReader

    Hi All,
    I am using StaxEventItemReader to read a huge xml document containing fragments that need to be processed individually. Below is the structure:
    <CustomerBill>
    <Bill..>
    <Bill..>
    ...
    </CustomerBill>
    I am using jibx for unmarshalling the xml.
    my itemReader configuration is as follows:
    <bean id="itemReader" class="org.springframework.batch.item.xml.StaxEven tItemReader">
    <property name="strict" value="false" />
    <property name="fragmentRootElementName" value="CustomerBill" />
    <property name="resource">
    <bean class="org.springframework.core.io.FileSystemResou rce"
    scope="step">
    ...
    </bean>
    </property>
    <property name="unmarshaller" ref="jibxBillMarshaller" />
    </bean>
    <bean id="jibxBillMarshaller" class="org.springframework.oxm.jibx.JibxMarshaller ">
    <property name="targetClass" value="com.etl.xml.Bill" />
    </bean>

    After successfully completing all the fragments StaxEventItemReader does not handle EndDocument it goes past end of document and throws exception "java.util.NoSuchElementException".

    am I missing something or is there some other way to handle. Any help is appreciated!!

  • #2
    Could you post a test case with some sample data?

    Comment


    • #3
      Sample fragment Data given below.
      when it completes the processing the last BillDetail element It moves on to look for the next CustomerBill frangment but as this is the only fragment for my sample test. it get the Document end.In method "moveCursorToNextFragment" the reader.peek doesnt return null hence the method "moveCursorToNextFragment" it goes on to read the next element and throws the "java.util.NoSuchElementException".

      thanks for your help in advance!!

      <CustomerBill>
      <StartDate>2001-01-02</StartDate>
      <EndDate>2001-02-01</EndDate>
      <SetID />
      <RSCD>E-RS/SMP</RSCD>
      <CalculatedAmt>11.40</CalculatedAmt>
      <DescriptionOnBill>Simple Residential Rate</DescriptionOnBill>
      <RateScheduleDescr />
      <BillDetail>
      <AppliedInSummary>Y</AppliedInSummary>
      <CalculatedAmt>10.00</CalculatedAmt>
      <ExemptAmt />
      <UnitOfMeasureCode />
      <TimeOfUseCode />
      <SQICode />
      <BillSQ />
      <DescriptionOnBill>Base Customer Charge</DescriptionOnBill>
      <DisplayOrder>2100</DisplayOrder>
      <Component>ELE210</Component>
      <Characteristics>
      <Char_Name>PrintChr</Char_Name>
      <Char_Value>CSTCHG</Char_Value>
      </Characteristics>
      </BillDetail>
      <BillDetail>
      <AppliedInSummary>N</AppliedInSummary>
      <CalculatedAmt>10.00</CalculatedAmt>
      <ExemptAmt />
      <UnitOfMeasureCode />
      <TimeOfUseCode />
      <SQICode />
      <BillSQ />
      <DescriptionOnBill>Sum of the Charges</DescriptionOnBill>
      </BillDetail>
      <BillDetail>
      <AppliedInSummary>N</AppliedInSummary>
      <CalculatedAmt>0.90</CalculatedAmt>
      <ExemptAmt />
      <UnitOfMeasureCode />
      <TimeOfUseCode />
      <SQICode />
      <BillSQ />
      <DescriptionOnBill>City Tax at 9%</DescriptionOnBill>
      </BillDetail>
      <BillDetail>
      <AppliedInSummary>N</AppliedInSummary>
      <CalculatedAmt>0.50</CalculatedAmt>
      <ExemptAmt />
      <UnitOfMeasureCode />
      <TimeOfUseCode />
      <SQICode />
      <BillSQ />
      <DescriptionOnBill>State Tax 5%</DescriptionOnBill>
      <DisplayOrder>2110</DisplayOrder>
      <Component>ELE210</Component>
      <Characteristics>
      <Char_Name>PrintChr</Char_Name>
      <Char_Value>DSTCHG</Char_Value>
      </Characteristics>
      </BillDetail>
      </CustomerBill>

      Comment


      • #4
        Is that a fragment or the whole input file? If the latter, then it needs to be wrapped in a document root of some kind. If the former, then can you post the whole file?
        Last edited by Dave Syer; Sep 1st, 2010, 01:18 PM.

        Comment


        • #5
          here is the configuration of the ItemReader
          ===================================
          <bean id="itemReader" class="com.bge.oracle.css.etl.task.BillEventReader ">
          <property name="strict" value="false" />
          <property name="fragmentRootElementName" value="CustomerBill" />
          <property name="resource">
          <bean class="org.springframework.core.io.FileSystemResou rce"
          scope="step">
          <constructor-arg value="#{jobParameters[inputfilename]}" />
          <!-- <constructor-arg value="/Rajesh/Development/WS_Batch_H/FileExample01/src/com/batch/simpletask/data/BGE_First_Test.xml" />-->
          </bean>
          </property>
          <property name="unmarshaller" ref="jibxBillMarshaller" />
          </bean>

          <bean id="jibxBillMarshaller" class="org.springframework.oxm.jibx.JibxMarshaller ">
          <property name="targetClass" value="com.bge.oracle.css.etl.xml.CustomerBill" />
          </bean>
          =============================================
          given bellow is the complete xml to be processed

          <Bill>
          <CustomerBill>
          <StartDate>2001-01-02</StartDate>
          <EndDate>2001-02-01</EndDate>
          <SetID />
          <RSCD>E-RS/SMP</RSCD>
          <CalculatedAmt>11.40</CalculatedAmt>
          <DescriptionOnBill>Simple Residential Rate</DescriptionOnBill>
          <RateScheduleDescr />
          <BillDetail>
          <AppliedInSummary>Y</AppliedInSummary>
          <CalculatedAmt>10.00</CalculatedAmt>
          <ExemptAmt />
          <UnitOfMeasureCode />
          <TimeOfUseCode />
          <SQICode />
          <BillSQ />
          <DescriptionOnBill>Base Customer Charge</DescriptionOnBill>
          <DisplayOrder>2100</DisplayOrder>
          <Component>ELE210</Component>
          <Characteristics>
          <Char_Name>PrintChr</Char_Name>
          <Char_Value>CSTCHG</Char_Value>
          </Characteristics>
          </BillDetail>
          <BillDetail>
          <AppliedInSummary>N</AppliedInSummary>
          <CalculatedAmt>10.00</CalculatedAmt>
          <ExemptAmt />
          <UnitOfMeasureCode />
          <TimeOfUseCode />
          <SQICode />
          <BillSQ />
          <DescriptionOnBill>Sum of the Charges</DescriptionOnBill>
          </BillDetail>
          <BillDetail>
          <AppliedInSummary>N</AppliedInSummary>
          <CalculatedAmt>0.90</CalculatedAmt>
          <ExemptAmt />
          <UnitOfMeasureCode />
          <TimeOfUseCode />
          <SQICode />
          <BillSQ />
          <DescriptionOnBill>City Tax at 9%</DescriptionOnBill>
          </BillDetail>
          <BillDetail>
          <AppliedInSummary>N</AppliedInSummary>
          <CalculatedAmt>0.50</CalculatedAmt>
          <ExemptAmt />
          <UnitOfMeasureCode />
          <TimeOfUseCode />
          <SQICode />
          <BillSQ />
          <DescriptionOnBill>State Tax 5%</DescriptionOnBill>
          <DisplayOrder>2110</DisplayOrder>
          <Component>ELE210</Component>
          <Characteristics>
          <Char_Name>PrintChr</Char_Name>
          <Char_Value>DSTCHG</Char_Value>
          </Characteristics>
          </BillDetail>
          </CustomerBill>
          <CustomerBill>
          <StartDate>2001-02-02</StartDate>
          <EndDate>2001-03-01</EndDate>
          <SetID />
          <RSCD>E-RS/SMP</RSCD>
          <CalculatedAmt>15.40</CalculatedAmt>
          <DescriptionOnBill>Simple Residential Rate</DescriptionOnBill>
          <RateScheduleDescr />
          <BillDetail>
          <AppliedInSummary>Y</AppliedInSummary>
          <CalculatedAmt>14.00</CalculatedAmt>
          <ExemptAmt />
          <UnitOfMeasureCode />
          <TimeOfUseCode />
          <SQICode />
          <BillSQ />
          <DescriptionOnBill>Base Customer Charge</DescriptionOnBill>
          <DisplayOrder>2100</DisplayOrder>
          <Component>ELE210</Component>
          <Characteristics>
          <Char_Name>PrintChr</Char_Name>
          <Char_Value>CSTCHG</Char_Value>
          </Characteristics>
          </BillDetail>
          <BillDetail>
          <AppliedInSummary>N</AppliedInSummary>
          <CalculatedAmt>14.00</CalculatedAmt>
          <ExemptAmt />
          <UnitOfMeasureCode />
          <TimeOfUseCode />
          <SQICode />
          <BillSQ />
          <DescriptionOnBill>Sum of the Charges</DescriptionOnBill>
          </BillDetail>
          <BillDetail>
          <AppliedInSummary>N</AppliedInSummary>
          <CalculatedAmt>1.00</CalculatedAmt>
          <ExemptAmt />
          <UnitOfMeasureCode />
          <TimeOfUseCode />
          <SQICode />
          <BillSQ />
          <DescriptionOnBill>City Tax at 9%</DescriptionOnBill>
          </BillDetail>
          <BillDetail>
          <AppliedInSummary>N</AppliedInSummary>
          <CalculatedAmt>0.60</CalculatedAmt>
          <ExemptAmt />
          <UnitOfMeasureCode />
          <TimeOfUseCode />
          <SQICode />
          <BillSQ />
          <DescriptionOnBill>State Tax 5%</DescriptionOnBill>
          <DisplayOrder>2110</DisplayOrder>
          <Component>ELE210</Component>
          <Characteristics>
          <Char_Name>PrintChr</Char_Name>
          <Char_Value>DSTCHG</Char_Value>
          </Characteristics>
          </BillDetail>
          </CustomerBill>
          </Bill>

          Comment


          • #6
            Looks correct. What version of Java/StaX are you using (try with Java 6 and no additional StaX libraries)?

            Comment


            • #7
              appreciate the prompt reply.
              I am using woodstox stax parser and jdk 1.5

              as you suggested I will reconfigure to use jdk1.6.

              Comment


              • #8
                I changed to java 6 and no stax parser in library. I am still getting same error below is the stacktrace for the exception.


                [java] 15:50:49,737 DEBUG main RepeatTemplate:291 - Handling exception: java.util.NoSuchElementException, caused by: java.util.NoSuchElementException: null
                [java] 15:50:49,737 DEBUG main RepeatTemplate:251 - Handling fatal exception explicitly (rethrowing first of 1): java.util.NoSuchElementException: null
                [java] 15:50:49,753 DEBUG main TaskletStep:393 - Applying contribution: [StepContribution: read=1, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING]
                [java] 15:50:49,753 DEBUG main TaskletStep:425 - Rollback for RuntimeException: java.util.NoSuchElementException: null
                [java] 15:50:49,753 DEBUG main TransactionTemplate:152 - Initiating transaction rollback on application exception
                [java] java.util.NoSuchElementException
                [java] at com.ctc.wstx.evt.WstxEventReader.throwEOD(WstxEven tReader.java:359)
                [java] at com.ctc.wstx.evt.WstxEventReader.peek(WstxEventRea der.java:290)
                [java] at org.springframework.batch.item.xml.stax.DefaultFra gmentEventReader.peek(DefaultFragmentEventReader.j ava:168)
                [java] at org.springframework.batch.item.xml.StaxEventItemRe ader.moveCursorToNextFragment(StaxEventItemReader. java:143)
                [

                Comment


                • #9
                  What is "com.ctc.wstx.evt.WstxEventReader"? (It's not J2SE and it's not Woodstox. Get rid of that and it should work.)

                  Comment


                  • #10
                    Thanks a Ton Dave!!


                    jibx-run.jar was loading wstx-asl.jar that had the property javax.xml.stream.XMLInputFactory set to use com.ctc.wstx.stax.WstxEventFactory hence using com.ctc.wstx.evt.WstxEventReader I removed that jar and problem solved like you suggested.

                    its working like a charm now!!!!

                    Comment

                    Working...
                    X