Anirban B Anirban B - 2 months ago 20
reST (reStructuredText) Question

Spring REST Endpoint: 404 requested resource is not available

I am creating a spring boot service with a Spring REST API end point. But I am stuck in a very simple rest call. My rest controller is as below:

@RestController
@RequestMapping(value={"/reportservice"})
public class ReportingMessageController {

@Autowired
private ReportService reportService;

@RequestMapping(value = {"/reports" }, method = RequestMethod.GET, produces = {
MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
public ResponseEntity<ResponseMessage> getReport(@RequestParam(value="eaid", required=true) String eaid,
@RequestParam(value="source", required=false) String source,
@RequestParam(value="userid", required=false) String userid,
@RequestParam(value="org", required=false) String org,
@RequestParam(value="startdate", required=true) Date startDate,
@RequestParam(value="enddate", required=true) Date endDate,
@RequestParam(value="page", required=false) int pageid){
ReportQueryParams params = new ReportQueryParams();
params.setEaid(eaid);
params.setSid(sid);
params.setSource(source);
params.setUserid(userid);
params.setOrg(org);
params.setStartdate(startDate);
params.setEnddate(endDate);
params.setPageid(pageid);
System.out.println(params);
ResponseMessage response = reportService.getReports(params);
return new ResponseEntity<ResponseMessage>(response, HttpStatus.OK);
}
}


Service class is :

@Component
public class ReportService {

public ResponseMessage getReports(ReportQueryParams params){
return new ResponseMessage();
}
}


ResponseMessage class is simple pojo

My uri is

http://localhost:8080/reportservice/reports?eaid=6764623946&source=ABC&userid=abhattacherji&org=trpo&startdate=8/11/2016&enddate=9/1/2016&page=1


and I am getting HTTP Status 404 error. Even if I ignore query param, the first part (/reportservice/reports) is not also working. Any lead will be helpful. Thanks in advance.

Answer

I think you pass wrong date parameters.

for example &startdate=8/11/2016 this may be consider as a different path variables.

You need to pass date parameters like,

@DateTimeFormat(pattern="MM/dd/yyyy") where yyyy is year, MM is month and dd is date

public ResponseEntity<ResponseMessage> getReport(@DateTimeFormat(pattern="MM/dd/yyyy") Date startDate) {
    ...
}

For more details check this link, passing date into request param

Comments