0

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.

Anirban B
  • 507
  • 8
  • 27
  • Do you have any context path set for you application in a web server? – Branislav Lazic Sep 22 '16 at 16:54
  • can you post the part where you make the request , at least post the part generating the url, – Priyamal Sep 22 '16 at 16:59
  • @Priyamal, I am calling it from postman. Exactly the URI I posted with Accept header as Application/xml and Application/json – Anirban B Sep 22 '16 at 17:06
  • like @BranislavLazic said , whats the name of your web site, do you have a one – Priyamal Sep 22 '16 at 17:28
  • You need to add the application name to the url if your application war is not ROOT.war. Let say your application name is abc.war then you have to call http://localhost:8080/abc/reportservice/..... – Azim Sep 22 '16 at 18:27
  • @Azim it's a Spring Boot application. – Anirban B Sep 22 '16 at 18:49
  • Not sure about spring boot but looks like your ReportingMessageController is not picked as a rest service, are you sure it's getting scanned, any configuration like context:component-scan might be missing. – Rahul Kumar Sep 22 '16 at 21:26

2 Answers2

0

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

Community
  • 1
  • 1
Parth Solanki
  • 3,268
  • 2
  • 22
  • 41
0

Three changes I made and it worked:

  1. Replaced @RequestParam with @QueryParam.
  2. Changed Date ans int to String
  3. Made value and parameter name same (like both "startdate" instead of "startdate" and "startDate").
Anirban B
  • 507
  • 8
  • 27