'RESTful API resource returns 404 when added @QueryParam
My resource worked fine till now. I added @QueryParam there. If I make request without writing query param to uri it works fine. After I write query param to the uri 404 code responses.
@GET
@Path("{id}/appointments")
@UnitOfWork
@JsonView(Views.DoctorView.class)
public List<?> getDoctorAppointments(@Auth LoggedUser loggedUser,
@QueryParam("date") Date date,
@QueryParam("timePeriod") TimePeriod timePeriod,
@PathParam("id") int id
) {
if(date != null && (timePeriod == null || timePeriod.equals(TimePeriod.TODAY))){
return appointmentDAO.getDoctorsAppointmentsByDate(id, date);
}
if(date != null && timePeriod.equals(TimePeriod.WEEK)){
return appointmentDAO.getDoctorsNumberOfAppointmentsForWeek(date, id);
}
return appointmentDAO.getAppointments(id, UserType.DOCTOR);
}
Solution 1:[1]
If you're getting a 404 I suspect you're not issuing the HTTP request correctly. My assumption for the query w/out a date
or timePeriod
param you'll be issuing
GET http://my-site/1/appointments
And if you try to pass a date and are getting a 404 you are issuing
GET http://my-site/1/appointments/date=2017-01-13
Or maybe this
GET http://my-site/1/appointments/2017-01-13
Which would result in a 404, whereas this should work fine and pass in the date
query param
GET http://my-site/1/appointments?date=2017-01-13
I may be guessing wrong. Let me know what the URLs you're querying look like and we can troubleshoot more.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kevin |