From cb9f35c1b485ba1e6363667df2d7c2d062531e2d Mon Sep 17 00:00:00 2001 From: dsyer Date: Mon, 16 Jun 2008 16:45:52 +0000 Subject: [PATCH] Refactor job launching message handler to use special request object. --- .../MessageToJobParametersStrategy.java | 2 +- ...ResourcePayloadAsJobParameterStrategy.java | 3 +- .../launch/JobExecutionRequest.java | 57 +++++++++++++ .../launch/JobLaunchingMessageHandler.java | 32 +++---- ...aunchingPostReceiveChannelInterceptor.java | 57 ------------- ...sagePropertiesToJobParametersStrategy.java | 25 ------ .../launch/MessageToJobStrategy.java | 16 ---- .../StringPayloadAsJobNameStrategy.java | 32 ------- ...unchingMessageHandlerIntegrationTests.java | 61 ++++++++------ .../JobLaunchingMessageHandlerTests.java | 19 +---- ...unchingPostReceiveChannelAdapterTests.java | 84 ------------------- .../launch/JobRequestConverter.java | 37 ++++++++ ...MessageHandlerIntegrationTests-context.xml | 71 ++++++++-------- 13 files changed, 182 insertions(+), 314 deletions(-) rename spring-batch-integration/src/main/java/org/springframework/batch/integration/{launch => file}/MessageToJobParametersStrategy.java (83%) create mode 100644 spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/JobExecutionRequest.java delete mode 100644 spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/JobLaunchingPostReceiveChannelInterceptor.java delete mode 100644 spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/MessagePropertiesToJobParametersStrategy.java delete mode 100644 spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/MessageToJobStrategy.java delete mode 100644 spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/StringPayloadAsJobNameStrategy.java delete mode 100644 spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingPostReceiveChannelAdapterTests.java create mode 100644 spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobRequestConverter.java diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/MessageToJobParametersStrategy.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/file/MessageToJobParametersStrategy.java similarity index 83% rename from spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/MessageToJobParametersStrategy.java rename to spring-batch-integration/src/main/java/org/springframework/batch/integration/file/MessageToJobParametersStrategy.java index 7d04a3cd3..e22634891 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/MessageToJobParametersStrategy.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/file/MessageToJobParametersStrategy.java @@ -1,4 +1,4 @@ -package org.springframework.batch.integration.launch; +package org.springframework.batch.integration.file; import org.springframework.batch.core.JobParameters; import org.springframework.integration.message.Message; diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/file/ResourcePayloadAsJobParameterStrategy.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/file/ResourcePayloadAsJobParameterStrategy.java index eb4872fee..c4b883d0c 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/file/ResourcePayloadAsJobParameterStrategy.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/file/ResourcePayloadAsJobParameterStrategy.java @@ -19,7 +19,6 @@ import java.io.IOException; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; -import org.springframework.batch.integration.launch.MessageToJobParametersStrategy; import org.springframework.batch.item.ItemStreamException; import org.springframework.core.io.Resource; import org.springframework.integration.message.Message; @@ -39,7 +38,7 @@ public class ResourcePayloadAsJobParameterStrategy implements MessageToJobParame * Convert a message payload which is a {@link Resource} to its URL * representation and load that into a job parameter. * - * @see org.springframework.batch.integration.launch.MessageToJobParametersStrategy#getJobParameters(org.springframework.integration.message.Message) + * @see org.springframework.batch.integration.file.MessageToJobParametersStrategy#getJobParameters(org.springframework.integration.message.Message) */ public JobParameters getJobParameters(Message message) { JobParametersBuilder builder = new JobParametersBuilder(); diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/JobExecutionRequest.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/JobExecutionRequest.java new file mode 100644 index 000000000..1f1b58751 --- /dev/null +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/JobExecutionRequest.java @@ -0,0 +1,57 @@ +/* + * Copyright 2006-2007 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.batch.integration.launch; + +import org.springframework.batch.core.Job; +import org.springframework.batch.core.JobParameters; + +/** + * Encapsulation of a {@link Job} and its {@link JobParameters} forming a + * request for a job to be launched. + * + * @author Dave Syer + * + */ +public class JobExecutionRequest { + + private final Job job; + private final JobParameters jobParameters; + + /** + * @param job + * @param jobParameters + */ + public JobExecutionRequest(Job job, JobParameters jobParameters) { + super(); + this.job = job; + this.jobParameters = jobParameters; + } + + /** + * @return the {@link Job} to be executed + */ + public Job getJob() { + return this.job; + } + + /** + * @return the {@link JobParameters} for this request + */ + public JobParameters getJobParameters() { + return this.jobParameters; + } + +} diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandler.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandler.java index 67e2a4171..7c238e2c4 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandler.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandler.java @@ -4,10 +4,9 @@ import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobExecutionException; import org.springframework.batch.core.JobParameters; +import org.springframework.batch.core.UnexpectedJobExecutionException; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.integration.annotation.Handler; -import org.springframework.integration.message.Message; -import org.springframework.integration.message.MessageHandlingException; /** * Message handler which uses strategies to convert a Message into a job and a @@ -18,37 +17,28 @@ import org.springframework.integration.message.MessageHandlingException; */ public class JobLaunchingMessageHandler { - private MessageToJobStrategy messageToJobStrategy; + private final JobLauncher jobLauncher; - private MessageToJobParametersStrategy messageToJobParametersStrategy = new MessagePropertiesToJobParametersStrategy(); - - private JobLauncher jobLauncher; - - public JobLaunchingMessageHandler(JobLauncher jobLauncher, MessageToJobStrategy messageToJobStrategy) { + /** + * @param jobLauncher + */ + public JobLaunchingMessageHandler(JobLauncher jobLauncher) { super(); this.jobLauncher = jobLauncher; - this.messageToJobStrategy = messageToJobStrategy; } @Handler - public JobExecution handle(Message message) { - Job job = messageToJobStrategy.getJob(message); - JobParameters jobParameters = messageToJobParametersStrategy.getJobParameters(message); + public JobExecution launch(JobExecutionRequest request) { + Job job = request.getJob(); + JobParameters jobParameters = request.getJobParameters(); try { JobExecution execution = jobLauncher.run(job, jobParameters); - if (message.getHeader().getReturnAddress() != null) { - return execution; - } - return null; + return execution; } catch (JobExecutionException e) { - throw new MessageHandlingException(message, "Exception executing job "); + throw new UnexpectedJobExecutionException("Exception executing job: ["+request+"]", e); } } - public void setMessageToJobParametersStrategy(MessageToJobParametersStrategy messageToJobParametersStrategy) { - this.messageToJobParametersStrategy = messageToJobParametersStrategy; - } - } diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/JobLaunchingPostReceiveChannelInterceptor.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/JobLaunchingPostReceiveChannelInterceptor.java deleted file mode 100644 index 954b6883b..000000000 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/JobLaunchingPostReceiveChannelInterceptor.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.springframework.batch.integration.launch; - -import org.springframework.batch.core.Job; -import org.springframework.batch.core.JobExecutionException; -import org.springframework.batch.core.JobParameters; -import org.springframework.batch.core.launch.JobLauncher; -import org.springframework.integration.channel.MessageChannel; -import org.springframework.integration.channel.interceptor.ChannelInterceptorAdapter; -import org.springframework.integration.message.Message; -import org.springframework.integration.message.MessageHandlingException; - -/** - * Channel interceptor which launches the configured job after the message has - * been received - * @author Jonas Partner - * - */ -public class JobLaunchingPostReceiveChannelInterceptor extends ChannelInterceptorAdapter { - - private JobLauncher jobLauncher; - - private Job job; - - private MessageToJobParametersStrategy messageToJobParametersStrategy = new MessagePropertiesToJobParametersStrategy(); - - /** - * - * @param job The job to launch - * @param jobLauncher - */ - public JobLaunchingPostReceiveChannelInterceptor(Job job, JobLauncher jobLauncher) { - super(); - this.job = job; - this.jobLauncher = jobLauncher; - } - - public MessageToJobParametersStrategy getMessageToJobParametersStrategy() { - return messageToJobParametersStrategy; - } - - public void setMessageToJobParametersStrategy(MessageToJobParametersStrategy messageToJobParametersStrategy) { - this.messageToJobParametersStrategy = messageToJobParametersStrategy; - } - - @Override - public void postReceive(Message message, MessageChannel channel) { - JobParameters parameters = messageToJobParametersStrategy.getJobParameters(message); - try { - jobLauncher.run(job, parameters); - } - catch (JobExecutionException e) { - throw new MessageHandlingException(message, "Excpetion executing job ", e); - } - - } - -} diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/MessagePropertiesToJobParametersStrategy.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/MessagePropertiesToJobParametersStrategy.java deleted file mode 100644 index 23a60017e..000000000 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/MessagePropertiesToJobParametersStrategy.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.springframework.batch.integration.launch; - -import java.util.Set; - -import org.springframework.batch.core.JobParameters; -import org.springframework.batch.core.JobParametersBuilder; -import org.springframework.integration.message.Message; - -/** - * Builds an instance of JobParameters from the properties in the message header - * @author Jonas Partner - * - */ -public class MessagePropertiesToJobParametersStrategy implements MessageToJobParametersStrategy { - - public JobParameters getJobParameters(Message message) { - JobParametersBuilder parametersBuilder = new JobParametersBuilder(); - Set propertyNames = message.getHeader().getPropertyNames(); - for (String key : propertyNames) { - parametersBuilder.addString(key, message.getHeader().getProperty(key)); - } - return parametersBuilder.toJobParameters(); - } - -} diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/MessageToJobStrategy.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/MessageToJobStrategy.java deleted file mode 100644 index 9abbfbf6c..000000000 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/MessageToJobStrategy.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.springframework.batch.integration.launch; - -import org.springframework.batch.core.Job; -import org.springframework.integration.message.Message; - - -/** - * Interface for strategy implementations which convert from a Message to a Spring batch Job - * @author Jonas Partner - * - */ -public interface MessageToJobStrategy{ - - public Job getJob(Message message); - -} diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/StringPayloadAsJobNameStrategy.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/StringPayloadAsJobNameStrategy.java deleted file mode 100644 index cd285b99d..000000000 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/StringPayloadAsJobNameStrategy.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.springframework.batch.integration.launch; - -import org.springframework.batch.core.Job; -import org.springframework.batch.core.configuration.JobLocator; -import org.springframework.batch.core.repository.NoSuchJobException; -import org.springframework.integration.message.Message; -import org.springframework.integration.message.MessageHandlingException; - -/** - * Takes the string payload of a message and delegates to a JobLocator - * @author Jonas Partner - * - */ -public class StringPayloadAsJobNameStrategy implements MessageToJobStrategy{ - - private JobLocator jobLocator; - - public StringPayloadAsJobNameStrategy(JobLocator jobLocator){ - this.jobLocator = jobLocator; - } - - public Job getJob(Message message) { - String name = (String)message.getPayload(); - try { - return jobLocator.getJob(name); - } - catch (NoSuchJobException e) { - throw new MessageHandlingException(message, "Could not find job with name " + name, e); - } - } - -} diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerIntegrationTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerIntegrationTests.java index 07820feda..8a405f594 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerIntegrationTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerIntegrationTests.java @@ -1,58 +1,69 @@ package org.springframework.batch.integration.launch; -import static org.junit.Assert.*; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.core.JobExecution; +import org.springframework.batch.core.JobParameters; +import org.springframework.batch.core.JobParametersBuilder; +import org.springframework.batch.integration.JobSupport; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.channel.MessageChannel; +import org.springframework.integration.message.GenericMessage; import org.springframework.integration.message.Message; -import org.springframework.integration.message.StringMessage; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -@ContextConfiguration() +@ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) -public class JobLaunchingMessageHandlerIntegrationTests { - - @Autowired @Qualifier("requests") +public class JobLaunchingMessageHandlerIntegrationTests { + + @Autowired + @Qualifier("requests") private MessageChannel requestChannel; - - @Autowired @Qualifier("response") + + @Autowired + @Qualifier("response") private MessageChannel responseChannel; + private JobSupport job = new JobSupport("testJob"); + @Before - public void setUp(){ + public void setUp() { requestChannel.purge(null); responseChannel.purge(null); } - - - @Test @DirtiesContext @SuppressWarnings("unchecked") - public void testNoReply(){ - requestChannel.send(new StringMessage("testJob")); - Message executionMessage = (Message)responseChannel.receive(1000); - - assertNull("JobExecution message received when no return address set", executionMessage); - } - + @Test + @DirtiesContext @SuppressWarnings("unchecked") - @Test @DirtiesContext - public void testReply(){ - StringMessage trigger = new StringMessage("testJob"); - trigger.getHeader().setProperty("dontclash", "12"); + public void testNoReply() { + GenericMessage trigger = new GenericMessage(new JobExecutionRequest(job, new JobParameters())); + requestChannel.send(trigger); + Message executionMessage = (Message) responseChannel.receive(1000); + + assertNull("JobExecution message received when no return address set", executionMessage); + } + + @SuppressWarnings("unchecked") + @Test + @DirtiesContext + public void testReply() { + JobParametersBuilder builder = new JobParametersBuilder(); + builder.addString("dontclash", "12"); + GenericMessage trigger = new GenericMessage(new JobExecutionRequest(job, builder.toJobParameters())); trigger.getHeader().setReturnAddress("response"); requestChannel.send(trigger); - Message executionMessage = (Message)responseChannel.receive(1000); + Message executionMessage = (Message) responseChannel.receive(1000); assertNotNull("No response received", executionMessage); JobExecution execution = executionMessage.getPayload(); assertNotNull("JobExectuion not returned", execution); - } + } } diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerTests.java index 60ab9fa2b..d10b7a8d2 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerTests.java @@ -14,13 +14,9 @@ import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.integration.JobSupport; -import org.springframework.batch.integration.launch.JobLaunchingMessageHandler; -import org.springframework.batch.integration.launch.MessageToJobStrategy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.bus.MessageBus; import org.springframework.integration.channel.AbstractMessageChannel; -import org.springframework.integration.message.Message; -import org.springframework.integration.message.StringMessage; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; @@ -30,8 +26,6 @@ public class JobLaunchingMessageHandlerTests extends AbstractJUnit4SpringContext JobLaunchingMessageHandler messageHandler; StubJobLauncher jobLauncher; - - // @Autowired // @Qualifier("jobs") TODO: Qualifier seems to be broken here why ????? @@ -43,13 +37,13 @@ public class JobLaunchingMessageHandlerTests extends AbstractJUnit4SpringContext @Before public void setUp() { jobLauncher = new StubJobLauncher(); - messageHandler = new JobLaunchingMessageHandler(jobLauncher, new StubMessageToJobStrategy()); + messageHandler = new JobLaunchingMessageHandler(jobLauncher); jobsChannel = (AbstractMessageChannel) applicationContext.getBean("jobs"); } @Test public void testSimpleDelivery() throws Exception{ - messageHandler.handle(new StringMessage("testjob")); + messageHandler.launch(new JobExecutionRequest(new JobSupport("testjob"), null)); assertEquals("Wrong job count", 1, jobLauncher.jobs.size()); assertEquals("Wrong job name", jobLauncher.jobs.get(0).getName(), "testjob"); @@ -71,14 +65,5 @@ public class JobLaunchingMessageHandlerTests extends AbstractJUnit4SpringContext } } - - private static class StubMessageToJobStrategy implements MessageToJobStrategy { - - public Job getJob(Message message) { - String name = (String) message.getPayload(); - return new JobSupport(name); - } - - } } diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingPostReceiveChannelAdapterTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingPostReceiveChannelAdapterTests.java deleted file mode 100644 index f7511ec95..000000000 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingPostReceiveChannelAdapterTests.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.springframework.batch.integration.launch; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.batch.core.Job; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobParameters; -import org.springframework.batch.core.launch.JobLauncher; -import org.springframework.batch.integration.JobSupport; -import org.springframework.batch.integration.launch.JobLaunchingPostReceiveChannelInterceptor; -import org.springframework.integration.channel.AbstractMessageChannel; -import org.springframework.integration.message.StringMessage; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@ContextConfiguration(locations = { "/job-execution-context.xml" }) -@RunWith(SpringJUnit4ClassRunner.class) -public class JobLaunchingPostReceiveChannelAdapterTests extends AbstractJUnit4SpringContextTests { - - JobLaunchingPostReceiveChannelInterceptor interceptor; - - StubJobLauncher jobLauncher; - - JobSupport job; - -// @Autowired - // @Qualifier("jobs") TODO: Qualifier seems to be broken here why ????? - public AbstractMessageChannel jobsChannel; - - @Before - public void setUp() { - job = new JobSupport(getClass().getName()); - jobLauncher = new StubJobLauncher(); - interceptor = new JobLaunchingPostReceiveChannelInterceptor(job, jobLauncher); - jobsChannel = (AbstractMessageChannel) applicationContext.getBean("jobs"); - jobsChannel.addInterceptor(interceptor); - } - - @Test - public void testJobPassedToLauncherCalled() { - StringMessage message = new StringMessage("test payload"); - jobsChannel.send(message); - assertTrue("Job launcher called before recevie", (jobLauncher.jobs.size() == 0)); - jobsChannel.receive(); - assertEquals(job, jobLauncher.jobs.get(0)); - } - - @Test - public void testMessagePropertiesPassedAsJobParameters() { - StringMessage message = new StringMessage("test payload"); - message.getHeader().setProperty("testOne", "a"); - message.getHeader().setProperty("testTwo", "b"); - jobsChannel.send(message); - jobsChannel.receive(); - JobParameters parameters = jobLauncher.parameters.get(0); - assertEquals("a", parameters.getString("testOne")); - assertEquals("b", parameters.getString("testTwo")); - - } - - private static class StubJobLauncher implements JobLauncher { - - List jobs = new ArrayList(); - - List parameters = new ArrayList(); - - - public JobExecution run(Job job, JobParameters jobParameters){ - jobs.add(job); - parameters.add(jobParameters); - return null; - } - - } - -} diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobRequestConverter.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobRequestConverter.java new file mode 100644 index 000000000..c29d8bdda --- /dev/null +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobRequestConverter.java @@ -0,0 +1,37 @@ +/* + * Copyright 2006-2007 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.batch.integration.launch; + +import java.util.Properties; + +import org.springframework.batch.core.converter.DefaultJobParametersConverter; +import org.springframework.batch.integration.JobSupport; +import org.springframework.integration.annotation.Handler; + +/** + * @author Dave Syer + * + */ +public class JobRequestConverter { + + @Handler + public JobExecutionRequest convert(String jobName) { + // TODO: get these from message header + Properties properties = new Properties(); + return new JobExecutionRequest(new JobSupport(jobName), new DefaultJobParametersConverter().getJobParameters(properties)); + } + +} diff --git a/spring-batch-integration/src/test/resources/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerIntegrationTests-context.xml b/spring-batch-integration/src/test/resources/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerIntegrationTests-context.xml index 057a88a1f..85630ca6b 100644 --- a/spring-batch-integration/src/test/resources/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerIntegrationTests-context.xml +++ b/spring-batch-integration/src/test/resources/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerIntegrationTests-context.xml @@ -1,44 +1,47 @@ - - - - - - - + + + + + + + - - - - + + + + + + + + + + - - + - - - - - + - + - + - + - + - + \ No newline at end of file