Bonjour tout le ti monde,

Ce que je voudrais faire :
=>Je voudrais simplement lire un fichier XML et l'afficher dans ma console

Actuellement, j'ai dans ma console : "java.lang.UnsupportedOperationException: XStreamMarshaller does not support unmarshalling using SAX XMLReaders".

=> Je ne vois pas ce qu'il manque où peut se situer le problème ???

Ci-dessous les sources ...

Merci pour votre aide !!!

gdev7

ImportSpringBatch (main)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("/batch-context.xml");
		JobLauncher launcher = (JobLauncher) context.getBean("jobLauncher");
		Job job = (Job) context.getBean("importer");
		try {
			//launch
			launcher.run(job, new JobParameters());
 
		} catch (...) { ... }
	}
batch-context.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?xml version="1.0" encoding="UTF-8"?>
<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:beans="http://www.springframework.org/schema/beans"
		xmlns:util="http://www.springframework.org/schema/util"
		xmlns:oxm="http://www.springframework.org/schema/oxm" 
		xsi:schemaLocation="http://www.springframework.org/schema/beans 
							http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
							http://www.springframework.org/schema/oxm 
							http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd
							http://www.springframework.org/schema/batch 
							http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
	<!-- configuration des beans -->
	<bean id="batchWriter" class="com.batch.BatchWriter" />
	<bean id="batchTask" class="com.batch.BatchTask" />
	<bean id="appJobExecutionListener" class="com.batch.AppJobExecutionListener" />
 
	<!-- job -->
	<job id="importer" xmlns="http://www.springframework.org/schema/batch">
		<!-- listener pour afficher status job -->
		<listeners>
			<listener ref="appJobExecutionListener" />
		</listeners>
		<!-- step pour simplement afficher l heure-->
		<step id="print" next="import">
			<batch:tasklet ref="batchTask" />
		</step>
		<!-- step faire l import/export-->
		<step id="import">
			<tasklet>
				<chunk reader="batchXmlReader" writer="batchWriter" commit-interval="100" />
			</tasklet>
		</step>
	</job>
 
	<bean id="batchXmlReader" class="org.springframework.batch.item.xml.StaxEventItemReader">
		<property name="fragmentRootElementName" value="contact" />
		<property name="resource" value="file:/inputData.xml" />
		<property name="unmarshaller" ref="contactMarshaller" />
	</bean>
 
	<bean id="contactMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">
		<property name="aliases">
			<map>
				<entry key="contact" value="com.batch.Contact" />
			</map>
		</property>
	</bean>
 
	<!-- composant qui permet de lancer un batch -->
	<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
  		<property name="jobRepository" ref="jobRepository" /> 
  	</bean>
 
	<!-- jobRepository permet de suivre et de reprendre l’avancement des taches -->
	<bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
  		<property name="transactionManager" ref="transactionManager" /> 
	</bean>
 
	<bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" /> 
 
</beans>
BatchWriter.java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
public class BatchWriter implements ItemWriter<Contact>  {
 
	/** Permet le 'stockage' des donnees */
	public void write (List<? extends Contact> items) {
		for (Contact item : items) {
			System.out.println("write() - " + item.toString());
		}
	}
}
inputData.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="UTF-8"?>
<contacts>
	<contact>
		<firstname>Dupont</firstname>
		<lastname>Roger</lastname>
	</contact>
	<contact>
		<firstname>Dupont</firstname>
		<lastname>Gerard</lastname>
	</contact>
	<contact>
		<firstname>Dupont</firstname>
		<lastname>Robert</lastname>
	</contact>
</contacts>
Résultat dans la console
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Status : STARTED
Thu Nov 18 15:30:10 CET 2010
Status : FAILED
Job failed: [java.lang.UnsupportedOperationException: XStreamMarshaller does not support unmarshalling using SAX XMLReaders]
Job failed: [StepExecution: id=1, version=3, name=print, status=COMPLETED, exitStatus=COMPLETED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0, exitDescription=, StepExecution: id=2, version=2, name=import, status=FAILED, exitStatus=FAILED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=1, exitDescription=java.lang.UnsupportedOperationException: XStreamMarshaller does not support unmarshalling using SAX XMLReaders
	at org.springframework.oxm.xstream.XStreamMarshaller.unmarshalSaxReader(XStreamMarshaller.java:460)
	at org.springframework.oxm.support.AbstractMarshaller.unmarshalSaxSource(AbstractMarshaller.java:341)
	at org.springframework.oxm.support.AbstractMarshaller.unmarshal(AbstractMarshaller.java:131)
	at org.springframework.batch.item.xml.StaxEventItemReader.doRead(StaxEventItemReader.java:235)
	at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:85)
	at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:90)
	at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:148)
	at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:108)
	at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367)
	at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214)
	at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)
	at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:103)
	at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:68)
	at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:371)
	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)
	at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:262)
	at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:76)
	at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367)
	at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214)
	at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)
	at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:248)
	at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
	at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135)
	at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)
	at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
	at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)
	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
	at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
	at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281)
	at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120)
	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:48)
	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114)
	at com.batch.ImportSpringBatch.main(ImportSpringBatch.java:34)]