Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected @RequestMapping semantics when class-level and method-level mappings used together [SPR-5726] #10396

Closed
spring-projects-issues opened this issue May 7, 2009 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented May 7, 2009

Keith Donald opened SPR-5726 and commented

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";
	}	
}

Affects: 3.0 M3

Issue Links:

Referenced from: commits 4025df1

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

As a workaround, you can get rid of the leading slash before /{day}. That at least should get rid of the IllegalStateException,

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented May 7, 2009

Grzegorz Borkowski commented

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.

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

This should be fixed now in SVN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants