private Message<StepExecutionRequest> createMessage(int sequenceNumber, int sequenceSize, StepExecutionRequest stepExecutionRequest, PollableChannel replyChannel) { return MessageBuilder.withPayload(stepExecutionRequest).setSequenceNumber(sequenceNumber) .setSequenceSize(sequenceSize) .setCorrelationId(stepExecutionRequest.getJobExecutionId() + ":" + stepExecutionRequest.getStepName()) .setReplyChannel(replyChannel) .build(); } }
@Test public void stepExecutionRequestShouldBeDeserializableWithJackson() throws IOException { // when StepExecutionRequest deserializedRequest = this.objectMapper.readValue(SERIALIZED_REQUEST, StepExecutionRequest.class); // then Assert.assertNotNull(deserializedRequest); Assert.assertEquals("step", deserializedRequest.getStepName()); Assert.assertEquals(1L, deserializedRequest.getJobExecutionId().longValue()); Assert.assertEquals(1L, deserializedRequest.getStepExecutionId().longValue()); } }
@ServiceActivator public StepExecution handle(StepExecutionRequest request) { Long jobExecutionId = request.getJobExecutionId(); Long stepExecutionId = request.getStepExecutionId(); StepExecution stepExecution = jobExplorer.getStepExecution(jobExecutionId, stepExecutionId); if (stepExecution == null) { throw new NoSuchStepException("No StepExecution could be located for this request: " + request); } String stepName = request.getStepName(); Step step = stepLocator.getStep(stepName); if (step == null) { throw new NoSuchStepException(String.format("No Step with name [%s] could be located.", stepName)); } try { step.execute(stepExecution); } catch (JobInterruptedException e) { stepExecution.setStatus(BatchStatus.STOPPED); // The receiver should update the stepExecution in repository } catch (Throwable e) { stepExecution.addFailureException(e); stepExecution.setStatus(BatchStatus.FAILED); // The receiver should update the stepExecution in repository } return stepExecution; }