0

it unable to run on both URL

@GetMapping(value= {"/durationtrend/{moduleId}","/durationtrend/{moduleId}/{records}"},produces=MediaType.APPLICATION_JSON_VALUE)
public List<ExecutionDurationResource> getExecutionDurationByModuleId(@PathVariable("moduleId") Integer moduleId,@PathVariable("records") Integer records) {    
    return executionDurationService.getExecutionDuration(moduleId,records); 
}

http://localhost:8080/seleniumexecutiontrending/reports/durationtrend/427 -->it not Call. http://localhost:8080/seleniumexecutiontrending/reports/durationtrend/427/7-->it executes.

I want to execute both in same method

3 Answers3

0
 @GetMapping(value= {"/durationtrend/{moduleId}","/durationtrend/{moduleId}/{records}"},produces= MediaType.APPLICATION_JSON_VALUE)
public List getExecutionDurationByModuleId(HttpServletRequest request) {
    Map map= (Map) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
    Integer moduleId=null,records=null;
    if(map!=null && map.get("moduleId")!=null){
        moduleId = Integer.valueOf(map.get("moduleId").toString());
    }
    if(map!=null && map.get("records")!=null){
        records = Integer.valueOf(map.get("records").toString());
    }
    System.out.println("moduleId:"+moduleId);
    System.out.println("records:"+records);
    //then you use modules and records , just judge  whether they are null?
    return executionDurationService.getExecutionDuration(moduleId,records);
}

I tried code above that works . Try it , hopes that help you !

0

here your problem is

@PathVariable("moduleId") Integer moduleId,@PathVariable("records") Integer records

you need moduleId and records parameters for both your URL, in the first URL "/durationtrend/{moduleId}" you did not have records parameter that's why you have

org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException Resolved [org.springframework.web.bind.MissingPathVariableException: Missing URI template variable 'records' for method parameter of type Integer]

this error

Actually, you can achieve this goal in many ways, like using HttpServletRequest and other things, but remember you are using spring and you need to simplify the things using spring framework.

the simple way which I suggest is using two separate controllers and simplify the things.

@GetMapping("/durationtrend/{moduleId}")
public void getExecutionDurationByModuleId(@PathVariable("moduleId") Integer moduleId) {
    return executionDurationService.getExecutionDuration(moduleId);
    System.out.println(moduleId);
}

@GetMapping("/durationtrend/{moduleId}/{records}")
public void getExecutionDurationByRecords(@PathVariable("moduleId") Integer moduleId, @PathVariable("records") Integer records) {
    return executionDurationService.getExecutionDuration(moduleId, records);
    System.out.println(moduleId);
    System.out.println(records);
}

this is easy to understand and you can create getExecutionDuration(moduleId) method in your service class and can easily bypass it...

hope it is helpful...

majurageerthan
  • 2,169
  • 3
  • 17
  • 30
0
@GetMapping(value= "/module-execution-trend",produces=MediaType.APPLICATION_JSON_VALUE) 
     public List<ExecutionResource> getExecutionResult(@RequestParam("moduleId") Integer moduleId,@RequestParam(name="records",required=false,defaultValue="10")  Integer records ) 
     {
        System.out.println(moduleId); 
        System.out.println(records); 
         return executionService.getModuleExecutionResult(moduleId,records);
     }
Vladimir
  • 612
  • 3
  • 16