javawildflyjava-batch

Get Properties from reader in Java Batch


I have a Java Batch (JSR-352) application running on WildFly. The application is exposing a rest-api to trigger the job execution. I want to supply some values coming from the HTTP REST request to the Reader Class. What is the best way to implement this?

REST API where job is getting started:

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response handleFileReady(MyNotification notification) {
   final Properties jobParams = new Properties();
   jobParams.setProperty("filename", notification.getFileName());

   BatchRuntime.getJobOperator().start("filetransfer", jobParams);
   return Response.status(Response.Status.NO_CONTENT).build();
}

Reader where I would like to read the values from:

public class MyJobReader extends AbstractItemReader {

    @Override
    public Integer readItem() throws Exception {
       // Get Values here
       ...

Also, at the moment I am setting the String values in the properties by reading the notification object, is there a better way to supply the entire object?


Solution

  • By injecting JobContext I can get the execution id now:

    public class MyJobReader extends AbstractItemReader {
    
        @Inject
        private JobContext jobContext;
    
        @Override
        public Integer readItem() throws Exception {
    
            Properties pros = BatchRuntime.getJobOperator().getParameters(jobContext.getExecutionId());