Announcement Announcement Module
Collapse
No announcement yet.
How to use RestTemplate to send execute request with parameter to Spring Batch Admin Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use RestTemplate to send execute request with parameter to Spring Batch Admin

    Hi all,

    In Spring Batch Admin there is RESTful services to execute job as bellow:

    org.springframework.batch.admin.web.JobController. launch(ModelMap, String, LaunchRequest, Errors, String)
    Code:
    @RequestMapping(value = "/jobs/{jobName}", method = RequestMethod.POST)
    	public String launch(ModelMap model, @ModelAttribute("jobName") String jobName,
    			@ModelAttribute("launchRequest") LaunchRequest launchRequest, Errors errors,
    			@RequestParam(defaultValue = "execution") String origin) {
    
    		launchRequest.setJobName(jobName);
    		String params = launchRequest.jobParameters;
    They receive launchRequest object, but I don't know how to send request with launchRequest by using RestTemplate.
    I write some test code as below:
    Code:
    String url = "http://localhost:8080/spring-batch-admin/jobs/helloJob.json";
            RestTemplate restTemplate = new RestTemplate();
    
            String jobParameters = "fail=false";
            LaunchRequest launchRequest = new LaunchRequest();
            launchRequest.setJobParameters(jobParameters);
    
            String result = restTemplate.postForObject(url, launchRequest, String.class);
    The code run well, but the the jobParameters in launchRequest always null.

    Does anyone know how to use RestTemplate to send execute job request with jobParameters to Spring Batch Admin?
    Or anyone has a full example?
Working...
X