Announcement Announcement Module
No announcement yet.
How to fix: Unknown Source type: class javax.xml.transform.stax.StAXSource Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to fix: Unknown Source type: class javax.xml.transform.stax.StAXSource

    I am trying to read an xml file using staxEventitemReader but i am getting following exception

    java.lang.IllegalArgumentException: Unknown Source type: class javax.xml.transform.stax.StAXSource
    at org.springframework.oxm.AbstractMarshaller.unmarsh al(
    at org.springframework.batch.item.xml.StaxEventItemRe ader.doRead(
    at org.springframework.batch.core.step.item.SimpleChu nkProvider.doRead(
    at org.springframework.batch.core.step.item.SimpleChu
    at org.springframework.batch.core.step.item.SimpleChu nkProvider$1.doInIteration(SimpleChunkProvider.jav a:108)
    at plate.getNextResult(
    at plate.executeInternal(
    at plate.iterate(
    at org.springframework.batch.core.step.item.SimpleChu nkProvider.provide(
    at org.springframework.batch.core.step.item.ChunkOrie ntedTasklet.execute(
    at org.springframework.batch.core.step.tasklet.Taskle tStep$ChunkTransactionCallback.doInTransaction(Tas
    at nTemplate.execute(
    at org.springframework.batch.core.step.tasklet.Taskle tStep$2.doInChunkContext(
    at org.springframework.batch.core.scope.context.StepC ontextRepeatCallback.doInIteration(StepContextRepe
    at plate.getNextResult(
    at plate.executeInternal(
    at plate.iterate(
    at org.springframework.batch.core.step.tasklet.Taskle tStep.doExecute(
    at org.springframework.batch.core.step.AbstractStep.e xecute(
    at org.springframework.batch.core.job.SimpleStepHandl er.handleStep(
    at org.springframework.batch.core.job.flow.JobFlowExe cutor.executeStep(
    at ate.StepState.handle(
    at mpleFlow.resume(
    at mpleFlow.start(
    at Execute(
    at org.springframework.batch.core.job.AbstractJob.exe cute(
    at leJobLauncher$
    at org.springframework.core.task.SyncTaskExecutor.exe cute(
    at spring.batch.BatchLauncher.main( :67)

    Here is My configuration Attachment
    file attached, i am getting this exception while reading xml

    Thanks in advance..
    Attached Files
    Last edited by sanjeev m; Jan 1st, 2013, 05:00 AM.

  • #2
    Your XML file didn't save. Can you please post, inline, a snip of the file?


    • #3
      Hi minella,

      Here is xml which i was trying to read
      <?xml version="1.0" encoding="UTF-8"?>
          <trade xmlns="">
          <trade xmlns="">
          <trade xmlns="">
      Last edited by mminella; Jan 3rd, 2013, 09:28 AM. Reason: Formatting


      • #4
        Looking at this, I didn't see anything obviously wrong so I pulled it into my workspace. I tweaked the readText.xml file to what I have pasted below (essentially just stripping out the parts that shouldn't impact the read) and ran it against the snip you included in the previous post. When I ran that, the job ran fine (no exceptions). If you have a unit test that I can recreate the error with, I'd be more than happy to take a second look.
        <beans xmlns=""
        	xmlns:xsi="" xmlns:batch=""
        	xmlns:jdbc="" xmlns:util=""

        	<description>Papillon Accounting Batch</description>
        	<import resource="../launch-context.xml" />
        	<batch:job id="xmlReadJob" restartable="true">
        	    <batch:step id="processStuffHoldings">
        	            <batch:chunk reader="stuffReader" writer="stuffWriter" commit-interval="1"/>
        	<bean id="stuffWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter">
            	    <property name="resource">
        	        <bean class="">
        		    <constructor-arg value="/tmp/customerProcessed.xml"/>
             	    <property name="marshaller" ref="stuffUnmarshaller" />
            	    <property name="rootTagName" value="trades" />
        	<bean id="stuffReader" class="org.springframework.batch.item.xml.StaxEventItemReader">
        	    <property name="fragmentRootElementName" value="trade" />
        	    <property name="resource" value="classpath:/data/forumIssue.xml" />
        	    <property name="unmarshaller" ref="stuffUnmarshaller" />
        	<bean id="stuffUnmarshaller"
        	    <property name="aliases">
        	        <util:map id="aliases">
        	            <entry key="trade"
        	                   value="org.springsource.batch.domain.Trade" />
        	            <entry key="priceWrong" value="java.math.BigDecimal" />
        	            <entry key="name" value="java.lang.String" />


        • #5
          Hi minella,

          when i run it through commandline jobrunner.. no exception , no output but
          when i run the same through class containg main method i am getting exception mentioned above

          application context xml that i am importing Attachment
          Here my class with main method

          public class BatchLauncher {
          	public static Job job ;
          	public static JobLauncher jobLauncher;
          	public static JobRepository jobRepository;
          	public static String P_covStrDate = null;
          	 * @param args
          	public static void main(String[] args) {
          		try { 
          			AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext("readXmlConfig.xml");   
          			JobParametersBuilder builder = new JobParametersBuilder();   
          			System.out.println("Entering.. main method of  BatchLauncher ");  
          			builder.addString("Date", "20/12/2012");  
          			jobLauncher = (JobLauncher) applicationContext.getBean("jobLauncher");
          			jobRepository = (JobRepository) applicationContext.getBean("jobRepository");
          			job = (Job) applicationContext.getBean("xmlReadJob");
   , builder.toJobParameters()); 
          			JobExecution jobExecution = jobRepository.getLastJobExecution(job.getName(), builder.toJobParameters());
          			System.out.println("Execution Status :: in main method of  BatchLauncher "+jobExecution.toString());
          		} catch(Exception e) {        
               * Method to get CurrentDate
               * @param String processDate
               * @return   
          	private static java.sql.Date getCurrentDate(String covrStrdate) {
          		java.util.Date today = new java.util.Date(covrStrdate);
          		return new java.sql.Date(today.getTime());
          	public static Job getJob() {
          		return job;
          	public static void setJob(Job job) {
          		BatchLauncher.job = job;
          	public static JobLauncher getJobLauncher() {
          		return jobLauncher;
          	public static void setJobLauncher(JobLauncher jobLauncher) {
          		BatchLauncher.jobLauncher = jobLauncher;
          	public static JobRepository getJobRepository() {
          		return jobRepository;
          	public static void setJobRepository(JobRepository jobRepository) {
          		BatchLauncher.jobRepository = jobRepository;
          Attached Files
          Last edited by mminella; Jan 4th, 2013, 09:38 AM. Reason: Formatting


          • #6
            Two things:
            1. Please use formatting when posting code. It makes it much easier to read and copy.
            2. I know you're not going to like this, but I pulled in the main class you posted above, pointed it at the job definition I posted above…and it worked without error (I just ran it as a java application from STS).
            If you have a unit test that I can try that consistently recreates the error, I'd be more than happy to give it another try.


            • #7
              Thanks minella..

              I deleted everything and started from scratch to read from xml now its working, sad thing is i didnt get what was the actual problem.

              Hi have a doubt, Is it possible to read the complex xml using staxEventItemreader..?
              when i tried to read complex xml i am getting null value and in google i found many people saying
              staxEventItemreader cant be used for complex xml so we need to go for custom reader..

              Thanks in advance
              Last edited by sanjeev m; Jan 8th, 2013, 06:34 AM.


              • #8

                The StaxEventItemReader can read any XML I've ever tried to read with it. You may need to use advanced configurations to get everything mapped correctly, but I am unaware of a scenario that it would be unable to handle. Is there a particular scenario that you are concerned with?


                • #9
                  I am happy to hear that. Here is my xml
                  <?xml version="1.0" encoding="UTF-8"?>
                  <!--DOCTYPE aim SYSTEM "MyMsg.dtd"> -->
                  <MyMsg Status="Live">
                      <aim Source="C" Double="N" TeaParty="N" Deal="N">
                          <aid IdScope="Sender">20110421000008</aid >
                                      <UnstructAddressLine>kabban park street</UnstructAddressLine>
                                      <UnstructAddressLine>shivaji nagar</UnstructAddressLine>
                                  <UnstructPersonName>DR HALLAPPA</UnstructPersonName>
                                          <UnstructAddressLine>Shanti nivasa</UnstructAddressLine>
                              <BowlingSpecialist Scheme="9BU01">03055890</BowlingSpecialist >
                              <TH Scheme="9BU01">60010490</TH>
                              <PNo Scheme="9BU01">03055890</PNo >
                              <aid IdScope="aim">1</aid >
                              <PNo Scheme="9BU01">03055890</PNo>
                              <Description>Railway station</Description>
                  Here i am able to read MId,MIssueDate,MSender, for 'aim' i am getting object with null values.
                  Last edited by mminella; Jan 9th, 2013, 01:55 PM. Reason: Formatting


                  • #10
                    Have you configured your unmarshaller for the various mappings needed (for example, mapping the aim tag to a particular class)?


                    • #11
                      Yes, I have mapped tags to the respective classes.
                      I have problem in
                      1.Mapping tag which contains attribute and value..for e.g
                      <aid IdScope="Sender">20110421000008</aid >
                      Here how to read IdScope attribute and its value.If it was <IdScope>sender<IdScope> i could map to IdScope class and may get it.(i cant change format of the xml..)
                      2.I am getting duplicate entry exception for following as unstructAddressLine tag is repeated.
                      <UnstructAddressLine>kabban park street</UnstructAddressLine>
                      <UnstructAddressLine>shivaji nagar</UnstructAddressLine>

                      please help me to resolve these things.

                      Thanks in advance
                      Last edited by sanjeev m; Jan 10th, 2013, 09:47 AM.