Skip to content

Commit 4ad0016

Browse files
committed
Changed default ExecutionContext serialization mechanism
The current default for serializing the ExecutionContext is via XStream using Jettison's driver. However, recent updates to Jettison make it incompatible with XStream with no progress on a fix. Because of this, and to encourage the use of well supported library combinations, the default ExecutionContext serialization mechanism for Spring Batch has been switched to Jackson (via the Jackson2ExecutionContextStringSerializer). This commit also depricates the XStreamExecutionContextStringSerializer for removal at a later date. However, it is still available for users that require that during a migration. Resolves BATCH-2575
1 parent 7f94ca2 commit 4ad0016

File tree

5 files changed

+31
-19
lines changed

5 files changed

+31
-19
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBean.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616

1717
package org.springframework.batch.core.explore.support;
1818

19+
import javax.sql.DataSource;
20+
1921
import org.springframework.batch.core.explore.JobExplorer;
2022
import org.springframework.batch.core.repository.ExecutionContextSerializer;
2123
import org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao;
2224
import org.springframework.batch.core.repository.dao.ExecutionContextDao;
25+
import org.springframework.batch.core.repository.dao.Jackson2ExecutionContextStringSerializer;
2326
import org.springframework.batch.core.repository.dao.JdbcExecutionContextDao;
2427
import org.springframework.batch.core.repository.dao.JdbcJobExecutionDao;
2528
import org.springframework.batch.core.repository.dao.JdbcJobInstanceDao;
@@ -38,8 +41,6 @@
3841
import org.springframework.jdbc.support.lob.LobHandler;
3942
import org.springframework.util.Assert;
4043

41-
import javax.sql.DataSource;
42-
4344
/**
4445
* A {@link FactoryBean} that automates the creation of a
4546
* {@link SimpleJobExplorer} using JDBC DAO implementations. Requires the user
@@ -127,10 +128,7 @@ public void afterPropertiesSet() throws Exception {
127128
}
128129

129130
if(serializer == null) {
130-
XStreamExecutionContextStringSerializer defaultSerializer = new XStreamExecutionContextStringSerializer();
131-
defaultSerializer.afterPropertiesSet();
132-
133-
serializer = defaultSerializer;
131+
serializer = new Jackson2ExecutionContextStringSerializer();
134132
}
135133
}
136134

spring-batch-core/src/main/java/org/springframework/batch/core/jsr/partition/JsrPartitionHandler.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@ private Set<StepExecution> applyPartitionPlan(StepExecution stepExecution,
303303
throw new IllegalArgumentException("Either a number of threads or partitions are required");
304304
}
305305

306-
stepExecution.getExecutionContext().put("partitionPlanState", new PartitionPlanState(plan));
306+
PartitionPlanState partitionPlanState = new PartitionPlanState();
307+
partitionPlanState.setPartitionPlan(plan);
308+
309+
stepExecution.getExecutionContext().put("partitionPlanState", partitionPlanState);
307310

308311
stepSplitter = new JsrStepExecutionSplitter(jobRepository, allowStartIfComplete, stepExecution.getStepName(), restoreState);
309312
partitionStepExecutions = stepSplitter.split(stepExecution, plan.getPartitions());
@@ -416,6 +419,15 @@ public PartitionPlanState(PartitionPlan plan) {
416419
threads = plan.getThreads();
417420
}
418421

422+
public PartitionPlanState() {
423+
}
424+
425+
public void setPartitionPlan(PartitionPlan plan) {
426+
this.partitionProperties = plan.getPartitionProperties();
427+
this.partitions = plan.getPartitions();
428+
this.threads = plan.getThreads();
429+
}
430+
419431
/* (non-Javadoc)
420432
* @see javax.batch.api.partition.PartitionPlan#getPartitionProperties()
421433
*/

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/XStreamExecutionContextStringSerializer.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2013 the original author or authors.
2+
* Copyright 2006-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,24 +23,27 @@
2323
import java.io.OutputStream;
2424
import java.util.Map;
2525

26+
import com.thoughtworks.xstream.XStream;
27+
import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
28+
import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
29+
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
30+
2631
import org.springframework.batch.core.repository.ExecutionContextSerializer;
2732
import org.springframework.beans.factory.InitializingBean;
2833
import org.springframework.core.serializer.Deserializer;
2934
import org.springframework.core.serializer.Serializer;
3035
import org.springframework.util.Assert;
3136

32-
import com.thoughtworks.xstream.XStream;
33-
import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
34-
import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
35-
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
36-
3737
/**
3838
* Implementation that uses XStream and Jettison to provide serialization.
3939
*
4040
* @author Thomas Risberg
4141
* @author Michael Minella
4242
* @since 2.0
4343
* @see ExecutionContextSerializer
44+
* @deprecated Due to the incompattabilities between current Jettison versions and XStream
45+
* versions, this serializer is depricated in favor of
46+
* {@link Jackson2ExecutionContextStringSerializer}
4447
*/
4548
public class XStreamExecutionContextStringSerializer implements ExecutionContextSerializer, InitializingBean {
4649

spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
import org.springframework.batch.core.repository.ExecutionContextSerializer;
2727
import org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao;
2828
import org.springframework.batch.core.repository.dao.ExecutionContextDao;
29+
import org.springframework.batch.core.repository.dao.Jackson2ExecutionContextStringSerializer;
2930
import org.springframework.batch.core.repository.dao.JdbcExecutionContextDao;
3031
import org.springframework.batch.core.repository.dao.JdbcJobExecutionDao;
3132
import org.springframework.batch.core.repository.dao.JdbcJobInstanceDao;
3233
import org.springframework.batch.core.repository.dao.JdbcStepExecutionDao;
3334
import org.springframework.batch.core.repository.dao.JobExecutionDao;
3435
import org.springframework.batch.core.repository.dao.JobInstanceDao;
3536
import org.springframework.batch.core.repository.dao.StepExecutionDao;
36-
import org.springframework.batch.core.repository.dao.XStreamExecutionContextStringSerializer;
3737
import org.springframework.batch.item.database.support.DataFieldMaxValueIncrementerFactory;
3838
import org.springframework.batch.item.database.support.DefaultDataFieldMaxValueIncrementerFactory;
3939
import org.springframework.batch.support.DatabaseType;
@@ -90,7 +90,7 @@ public void setClobType(int type) {
9090

9191
/**
9292
* A custom implementation of the {@link ExecutionContextSerializer}.
93-
* The default, if not injected, is the {@link XStreamExecutionContextStringSerializer}.
93+
* The default, if not injected, is the {@link Jackson2ExecutionContextStringSerializer}.
9494
*
9595
* @param serializer used to serialize/deserialize {@link org.springframework.batch.item.ExecutionContext}
9696
* @see ExecutionContextSerializer
@@ -189,8 +189,7 @@ public void afterPropertiesSet() throws Exception {
189189
}
190190

191191
if(serializer == null) {
192-
XStreamExecutionContextStringSerializer defaultSerializer = new XStreamExecutionContextStringSerializer();
193-
defaultSerializer.afterPropertiesSet();
192+
Jackson2ExecutionContextStringSerializer defaultSerializer = new Jackson2ExecutionContextStringSerializer();
194193

195194
serializer = defaultSerializer;
196195
}

spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBeanTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.springframework.batch.core.repository.ExecutionContextSerializer;
3030
import org.springframework.batch.core.repository.JobRepository;
3131
import org.springframework.batch.core.repository.dao.DefaultExecutionContextSerializer;
32-
import org.springframework.batch.core.repository.dao.XStreamExecutionContextStringSerializer;
32+
import org.springframework.batch.core.repository.dao.Jackson2ExecutionContextStringSerializer;
3333
import org.springframework.batch.item.database.support.DataFieldMaxValueIncrementerFactory;
3434
import org.springframework.core.serializer.Serializer;
3535
import org.springframework.dao.DataAccessException;
@@ -153,7 +153,7 @@ public void tesDefaultSerializer() throws Exception {
153153

154154
factory.afterPropertiesSet();
155155
Serializer<Map<String, Object>> serializer = (Serializer<Map<String,Object>>) ReflectionTestUtils.getField(factory, "serializer");
156-
assertTrue(serializer instanceof XStreamExecutionContextStringSerializer);
156+
assertTrue(serializer instanceof Jackson2ExecutionContextStringSerializer);
157157
}
158158

159159
@Test

0 commit comments

Comments
 (0)