Announcement Announcement Module
Collapse
No announcement yet.
Unable to format xml using jaxb2marshaller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to format xml using jaxb2marshaller

    Hi,

    Iíve written a job that extracts several (business defined) data types from a database and writes each of the data types to a separate xml file. To aid in performance each of the data types are split into several threads using the partitioning feature of spring batch. Once all these steps have completed another step then merges all the fragments into one file. For this I am using the following dependencies:
    Spring Batch 2.1.6
    Spring 3.0.0
    Spring oxm 1.5.9
    Spring oxm tiger1.5.9
    For completeness I have attached my pom.xml for the other dependencies.

    To accomplish the above requirements I am using the following classes
    org.springframework.batch.item.xml.StaxEventItemRe ader
    org.springframework.batch.item.xml.StaxEventItemWr iter
    org.springframework.oxm.jaxb.Jaxb2Marshaller
    The job is extracting everything as expected however it is writing everything onto a single line. To overcome this I have tried setting the Marshaller property
    Code:
    javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT
    to format the xml but this doesnít format the xml. Here is xml I am using to configure the StaxEventItemWriter.


    Code:
    		<bean id="mergeFilesWriter" scope="step" class="org.springframework.batch.item.xml.StaxEventItemWriter">
    			<property name="resource" value="file:#{jobExecutionContext['dailyExtractFileName']}" />
    			<property name="marshaller" ref="DailyExtractJAXB2Marshaller" />
    			<property name="rootTagName" value="DailyExtract" />
    			<property name="overwriteOutput" value="true" />
    			<property name="saveState" value="${mergeFiles.saveState}" />	
    		</bean>
    		
    		<bean id="DailyExtractJAXB2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    			<property name="classesToBeBound">
    				<list>
    							<value>org.atoc.batch.dss.jaxb.DailyExtract</value>
    				</list>
    			</property>
    			<!--  This is meant to format the marshalled xml data wth linefeeds and indention but doesn't work unfortunately!  -->
    			<property name="marshallerProperties">
    				<map>
    					<entry>
    						<key>
    							<util:constant static-field="javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT" />
    						</key>
    						<value type="boolean">true</value>
    					</entry>
    				</map>
    			</property>
    		</bean>

    Could someone please tell me what Iím going wrong or this is a bug?

    Thanks in advance
    Dave

  • #2
    Opps forgot to attach my pom.xml.

    Comment


    • #3
      It's unlikely to be a bug in Spring Batch, since the feature looks like it's in JAXB and/or Spring OXM. I'm slightly mystified though as neither really is responsible for formatting your output - that's done by the StAX writer which knows nothing about either OXM or JAXB. (Yet another 3rd party.) You can use Spring OXM 3.0 with Spring Batch 2.1.7, by the way. That might be worth a try. And also probably making sure your StAX and JAXB implementations are up to date?

      Comment


      • #4
        Thanks Dave for getting back to me.

        I've now updated my batch job to use the following and have corrected any dependency conflicts in the pom.
        Spring Batch 2.1.7
        Spring 3.0.5.RELEASE (including all its dependencies)
        Unfortunately when I run the job the xml file it produces still isn't formated.

        Correct me if I am wrong but isn't the JAXB and StAX implementations part of java these days and i have using the Java SE 1.6.0.24.

        Thinking out loud now I'm writing this I wonder should I be using the enterprise edition? But surely if the SE didn't implement JAXB and/or StAX it won't compile.

        Regards

        Comment


        • #5
          Need help,

          can you please show the code of writer and java files please,i am using jaxb2marshaller and facing lot of issues,

          Thanks in adavance

          Originally posted by dwakley View Post
          Hi,

          Iíve written a job that extracts several (business defined) data types from a database and writes each of the data types to a separate xml file. To aid in performance each of the data types are split into several threads using the partitioning feature of spring batch. Once all these steps have completed another step then merges all the fragments into one file. For this I am using the following dependencies:
          Spring Batch 2.1.6
          Spring 3.0.0
          Spring oxm 1.5.9
          Spring oxm tiger1.5.9
          For completeness I have attached my pom.xml for the other dependencies.

          To accomplish the above requirements I am using the following classes
          org.springframework.batch.item.xml.StaxEventItemRe ader
          org.springframework.batch.item.xml.StaxEventItemWr iter
          org.springframework.oxm.jaxb.Jaxb2Marshaller
          The job is extracting everything as expected however it is writing everything onto a single line. To overcome this I have tried setting the Marshaller property
          Code:
          javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT
          to format the xml but this doesnít format the xml. Here is xml I am using to configure the StaxEventItemWriter.


          Code:
          		<bean id="mergeFilesWriter" scope="step" class="org.springframework.batch.item.xml.StaxEventItemWriter">
          			<property name="resource" value="file:#{jobExecutionContext['dailyExtractFileName']}" />
          			<property name="marshaller" ref="DailyExtractJAXB2Marshaller" />
          			<property name="rootTagName" value="DailyExtract" />
          			<property name="overwriteOutput" value="true" />
          			<property name="saveState" value="${mergeFiles.saveState}" />	
          		</bean>
          		
          		<bean id="DailyExtractJAXB2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
          			<property name="classesToBeBound">
          				<list>
          							<value>org.atoc.batch.dss.jaxb.DailyExtract</value>
          				</list>
          			</property>
          			<!--  This is meant to format the marshalled xml data wth linefeeds and indention but doesn't work unfortunately!  -->
          			<property name="marshallerProperties">
          				<map>
          					<entry>
          						<key>
          							<util:constant static-field="javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT" />
          						</key>
          						<value type="boolean">true</value>
          					</entry>
          				</map>
          			</property>
          		</bean>

          Could someone please tell me what Iím going wrong or this is a bug?

          Thanks in advance
          Dave

          Comment


          • #6
            Originally posted by aqueelshah View Post
            can you please show the code of writer and java files please,i am using jaxb2marshaller and facing lot of issues,

            Thanks in adavance
            Hi,

            Unfortunately I'm no longer on this project and haven't got access to the code anymore.

            All I can suggest at this time (sorry I can't be of anymore help) is have you looked at any of the sample projects that are shipped with the SpringBatch or even online tutorials?

            Regards
            Dave

            Comment

            Working...
            X