You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code below does not work as expected.
Specifically:
Sending a GET request to /appointments, which I was expected to be mapped to the "get()" method below, instead gets mapped to getForDay(Date), which results in the error:
java.lang.IllegalStateException: Could not find @PathVariable [day] in @RequestMapping
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.resolvePathVariable(AnnotationMethodHandlerAdapter.java:642)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolvePathVariable(HandlerMethodInvoker.java:514)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:262)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:146)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:354)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:342)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:763)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:709)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:613)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:195)
org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:159)
org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141)
org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90)
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:417)
Sending a GET requests to /appointments/2009-12-29 results in a HTTP 400 being sent to the client with message:
"The request sent by the client was syntactically incorrect ()."
Is this the default handing now when there is a binding error? I was expecting to see a binding exception as I do not have a Date editor registered yet. No info or warning logs indicated there was a binding problem, so I'm left wondering what happened.
FAILING CODE:
package org.springframework.samples.petclinic.appointments;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/appointments")
public class AppointmentsController {
private AppointmentBook appointmentBook;
@Autowired
public AppointmentsController(AppointmentBook appointmentBook) {
this.appointmentBook = appointmentBook;
}
@RequestMapping(method = RequestMethod.GET)
public Appointments get() {
return appointmentBook.getAppointmentsForToday();
}
@RequestMapping(value="/{day}", method = RequestMethod.GET)
public Appointments getForDay(@PathVariable Date day) {
return appointmentBook.getAppointmentsForDay(day);
}
@RequestMapping(value="/new", method = RequestMethod.GET)
public AppointmentForm getNewForm() {
return new AppointmentForm();
}
@RequestMapping(method = RequestMethod.POST)
public String post(AppointmentForm form) {
appointmentBook.createAppointment(form);
return "redirect:/appointments";
}
}
Keith, for explanation why code 400 code is returned see #10293.
I think generally it should be solved like this:
if you registered the date converter, and the URL uses date with incorrect format, than the code 400 should be returned, as this is client fault (incorrect format)
if you haven't registered any date converter, and the URL part must be converted to Date object, than it is definitely programmer (server side) fault, and the proper exception should be thrown (MissingConverterException or so), stack trace should be printed, and error code 500 returned.
Keith Donald opened SPR-5726 and commented
The code below does not work as expected.
Specifically:
"The request sent by the client was syntactically incorrect ()."
Is this the default handing now when there is a binding error? I was expecting to see a binding exception as I do not have a Date editor registered yet. No info or warning logs indicated there was a binding problem, so I'm left wondering what happened.
FAILING CODE:
Affects: 3.0 M3
Issue Links:
@RequestMapping
@Controller
handler method bind target, a 500 error code should be returned not a 400.Referenced from: commits 4025df1
The text was updated successfully, but these errors were encountered: