Results 1 to 10 of 11

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

Hybrid View

  1. #1
    Join Date
    Mar 2012
    Posts
    22

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

    Hi,
    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(AbstractMarshaller.java:146)
    at org.springframework.batch.item.xml.StaxEventItemRe ader.doRead(StaxEventItemReader.java:233)
    at org.springframework.batch.item.support.AbstractIte mCountingItemStreamItemReader.read(AbstractItemCou ntingItemStreamItemReader.java:85)
    at org.springframework.batch.core.step.item.SimpleChu nkProvider.doRead(SimpleChunkProvider.java:90)
    at org.springframework.batch.core.step.item.SimpleChu nkProvider.read(SimpleChunkProvider.java:148)
    at org.springframework.batch.core.step.item.SimpleChu nkProvider$1.doInIteration(SimpleChunkProvider.jav a:108)
    at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:367)
    at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:214)
    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:68)
    at org.springframework.batch.core.step.tasklet.Taskle tStep$ChunkTransactionCallback.doInTransaction(Tas kletStep.java:386)
    at org.springframework.transaction.support.Transactio nTemplate.execute(TransactionTemplate.java:130)
    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:76)
    at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:367)
    at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:214)
    at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:143)
    at org.springframework.batch.core.step.tasklet.Taskle tStep.doExecute(TaskletStep.java:250)
    at org.springframework.batch.core.step.AbstractStep.e xecute(AbstractStep.java:195)
    at org.springframework.batch.core.job.SimpleStepHandl er.handleStep(SimpleStepHandler.java:135)
    at org.springframework.batch.core.job.flow.JobFlowExe cutor.executeStep(JobFlowExecutor.java:61)
    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:135)
    at org.springframework.batch.core.job.AbstractJob.exe cute(AbstractJob.java:281)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher$1.run(SimpleJobLauncher.java:120)
    at org.springframework.core.task.SyncTaskExecutor.exe cute(SyncTaskExecutor.java:48)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher.run(SimpleJobLauncher.java:114)
    at spring.batch.BatchLauncher.main(BatchLauncher.java :67)

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



    Thanks in advance..
    Sanjeev
    Last edited by sanjeev m; Jan 1st, 2013 at 04:00 AM.

  2. #2
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    366

    Default

    Your XML file didn't save. Can you please post, inline, a snip of the file?
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

  3. #3
    Join Date
    Mar 2012
    Posts
    22

    Default

    Hi minella,

    Here is xml which i was trying to read
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <records>
        <trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
            <isin>XYZ0001</isin>
            <quantity>5</quantity>
            <price>11.39</price>
            <customer>Customer1</customer>
        </trade>
        <trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
            <isin>XYZ0002</isin>
            <quantity>2</quantity>
            <price>72.99</price>
            <customer>Customer2c</customer>
        </trade>
        <trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
            <isin>XYZ0003</isin>
            <quantity>9</quantity>
            <price>99.99</price>
            <customer>Customer3</customer>
        </trade>
    </records>
    Last edited by mminella; Jan 3rd, 2013 at 08:28 AM. Reason: Formatting

  4. #4
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    366

    Default

    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.
    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:batch="http://www.springframework.org/schema/batch"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:util="http://www.springframework.org/schema/util"
    
    	xsi:schemaLocation="
    		http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
    		http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-2.5.xsd
    		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
    
    	<description>Papillon Accounting Batch</description>
    
    	<import resource="../launch-context.xml" />
    
    	<batch:job id="xmlReadJob" restartable="true">
    	    <batch:step id="processStuffHoldings">
    	        <batch:tasklet>
    	            <batch:chunk reader="stuffReader" writer="stuffWriter" commit-interval="1"/>
    	        </batch:tasklet>
    	    </batch:step>
    	</batch:job>
    
    	<bean id="stuffWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter">
        	    <property name="resource">
    	        <bean class="org.springframework.core.io.FileSystemResource">
    		    <constructor-arg value="/tmp/customerProcessed.xml"/>
    		</bean>
        	    </property>
         	    <property name="marshaller" ref="stuffUnmarshaller" />
        	    <property name="rootTagName" value="trades" />
    	</bean>
    
    
    	<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>
    
    	<bean id="stuffUnmarshaller"
    	      class="org.springframework.oxm.xstream.XStreamMarshaller">
    	    <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" />
    	        </util:map>
    	    </property>
    	</bean>
    </beans>
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

  5. #5
    Join Date
    Mar 2012
    Posts
    22

    Default

    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 applicationContextXml.txt
    Here my class with main method

    Code:
    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");
    			jobLauncher.run(job, 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) {        
    			e.printStackTrace();   
    		} 
    
    	}
    
    	/**
         * Method to get CurrentDate
         * @param String processDate
         * @return   
         */
    	private static java.sql.Date getCurrentDate(String covrStrdate) {
    		@SuppressWarnings("deprecation")
    		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;
    	}
    
    }
    Last edited by mminella; Jan 4th, 2013 at 08:38 AM. Reason: Formatting

  6. #6
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    366

    Default

    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.
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •