CAMEL-6656 fixed the issue that spring-batch losses header
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6f489f1d Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6f489f1d Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6f489f1d Branch: refs/heads/master Commit: 6f489f1d8105a7eb148c686147bc9f72a92eb9a7 Parents: ca5b6fb Author: Willem Jiang <ningji...@apache.org> Authored: Thu Aug 22 14:37:37 2013 +0800 Committer: Willem Jiang <ningji...@apache.org> Committed: Thu Aug 22 14:37:37 2013 +0800 ---------------------------------------------------------------------- .../component/spring/batch/SpringBatchProducer.java | 1 + .../spring/batch/SpringBatchIntegrationTest.java | 11 +++++++++++ .../component/spring/batch/springBatchtestContext.xml | 5 +++++ 3 files changed, 17 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/6f489f1d/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchProducer.java b/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchProducer.java index 332348f..4fc5395 100644 --- a/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchProducer.java +++ b/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchProducer.java @@ -46,6 +46,7 @@ public class SpringBatchProducer extends DefaultProducer { public void process(Exchange exchange) throws Exception { JobParameters jobParameters = prepareJobParameters(exchange.getIn().getHeaders()); JobExecution jobExecution = jobLauncher.run(job, jobParameters); + exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders()); exchange.getOut().setBody(jobExecution); } http://git-wip-us.apache.org/repos/asf/camel/blob/6f489f1d/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchIntegrationTest.java b/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchIntegrationTest.java index 77e3ad2..ea17b28 100644 --- a/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchIntegrationTest.java +++ b/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchIntegrationTest.java @@ -25,6 +25,8 @@ import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class SpringBatchIntegrationTest extends CamelSpringTestSupport { + @EndpointInject(uri = "mock:header") + MockEndpoint headerEndpoint; @EndpointInject(uri = "mock:output") MockEndpoint outputEndpoint; @@ -60,6 +62,15 @@ public class SpringBatchIntegrationTest extends CamelSpringTestSupport { jobExecutionEventsQueueEndpoint.assertIsSatisfied(); } + + @Test + public void testMessageHeader() throws Exception { + headerEndpoint.expectedHeaderReceived("header", 1); + + template.sendBodyAndHeader(null, "header", "1"); + + headerEndpoint.assertIsSatisfied(); + } @Override protected AbstractApplicationContext createApplicationContext() { http://git-wip-us.apache.org/repos/asf/camel/blob/6f489f1d/components/camel-spring-batch/src/test/resources/org/apache/camel/component/spring/batch/springBatchtestContext.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring-batch/src/test/resources/org/apache/camel/component/spring/batch/springBatchtestContext.xml b/components/camel-spring-batch/src/test/resources/org/apache/camel/component/spring/batch/springBatchtestContext.xml index a4161e8..d8fb231 100644 --- a/components/camel-spring-batch/src/test/resources/org/apache/camel/component/spring/batch/springBatchtestContext.xml +++ b/components/camel-spring-batch/src/test/resources/org/apache/camel/component/spring/batch/springBatchtestContext.xml @@ -50,6 +50,11 @@ <camel:simple>Echo ${body}</camel:simple> </camel:setBody> </camel:route> + <camel:route> + <camel:from uri="direct:header"/> + <camel:to uri="spring-batch:echoJob"/> + <camel:to uri="mock:header"/> + </camel:route> </camel:camelContext> <camel:consumerTemplate id="consumerTemplate" camelContextId="camel"/>