Page 1 of 2 12 LastLast
Results 1 to 10 of 11

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

  1. #1
    Join Date
    Mar 2012
    Posts
    21

    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
    338

    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
    21

    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
    338

    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
    21

    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
    338

    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

  7. #7
    Join Date
    Mar 2012
    Posts
    21

    Default

    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
    sanjeev
    Last edited by sanjeev m; Jan 8th, 2013 at 05:34 AM.

  8. #8
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    338

    Default

    Sanjeev,

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

  9. #9
    Join Date
    Mar 2012
    Posts
    21

    Default

    I am happy to hear that. Here is my xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!--DOCTYPE aim SYSTEM "MyMsg.dtd"> -->
    <MyMsg Status="Live">
        <MID>700</MID>
        <MIssueDate>20110421000008</MIssueDate>
        <MSender>snjeev</MSender>
        <MRecipient>sajal</MRecipient>
        <aim Source="C" Double="N" TeaParty="N" Deal="N">
            <aid IdScope="Sender">20110421000008</aid >
            <Pnt>
                <StructPersonName>
                    <FName>Shivu</FName>
                    <GName>kandratti</GName>
                </StructPersonName>
                <Cr>
                    <RNo>069632</RNo>
                </Cr>
                <Sex>2</Sex>
                <Date>19600401</Date>
                <Address_u>
                    <PostCode>582112</PostCode>
                    <UnstructAddress>
                        <UnstructAddressLine>kabban park street</UnstructAddressLine>
                        <UnstructAddressLine>shivaji nagar</UnstructAddressLine>
                        <UnstructAddressLine>dharwad</UnstructAddressLine>
                    </UnstructAddress>
                </Address_u>
                <GP>
                    <UnstructPersonName>DR HALLAPPA</UnstructPersonName>
                    <Address_u>
                        <PostCode>582118</PostCode>
                        <UnstructAddress>
                            <UnstructAddressLine>Shanti nivasa</UnstructAddressLine>
                            <UnstructAddressLine>nagarbhavi</UnstructAddressLine>
                            <UnstructAddressLine>.</UnstructAddressLine>
                            <UnstructAddressLine>kavishaila</UnstructAddressLine>
                        </UnstructAddress>
                    </Address_u>
                </GP>
            </Pnt>
            <EDetail>
                <BowlingSpecialist Scheme="9BU01">03055890</BowlingSpecialist >
                <Setting>I</Setting>
                <TH Scheme="9BU01">60010490</TH>
                <Di/>
            </EDetail>
            <IDetail>
                <INo>2208</INo>
                <IDate>20080116</IDate>
                <PNo Scheme="9BU01">03055890</PNo >
                <CAscore>45.00</CAscore>
                <FromDate>20080116000000</FromDate>
                <ToDate>20080116000000</ToDate>
                <IRef>2208</IRef>
                <ACode>1463134</ACode>
                <GTotal>45.00</GTotal>
            </IDetail>
            <Setem>
                <aid IdScope="aim">1</aid >
                <ISCode>C0000180</ISCode>
                <FD>20080116</FD>
                <LD>20080116</LD>
                <PNo Scheme="9BU01">03055890</PNo>
                <Units>1</Units>
                <Setting>I</Setting>
                <NTotal>45.00</NTotal>
                <Description>Railway station</Description>
                <GTotal>45.00</GTotal>
                <DTotal>.00</DTotal>
                <Vtotal>.00</Vtotal>
                <Vind>0</Vind>
                <Vrate>.00</Vrate>
            </Setem>
            <SignatureTune>2</SignatureTune>
        </aim>
    </MyMsg>
    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 at 12:55 PM. Reason: Formatting

  10. #10
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    338

    Default

    Have you configured your unmarshaller for the various mappings needed (for example, mapping the aim tag to a particular class)?
    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
  •