1

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?

adesai
  • 370
  • 3
  • 22

2 Answers2

1

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());

adesai
  • 370
  • 3
  • 22
  • Please let me suggest retrieving such properties at the ``open(CheckPoint)`` method, since ``readItem()`` might be called many times, and those parameters will not change during the job execution. – Jose Tepedino Apr 28 '19 at 21:46
1

You can pass them as query strings in your http request, and your REST resource class then pass them as batch job parameters. In your job xml files, you pass job parameters to your reader as reader's batch properties. Your reader class then inject these batch properties as class fields.

This is how it is done in jberet-rest.

cheng
  • 1,076
  • 6
  • 6