2

I am facing a strange issue. This is my REST API mapping

@RequestMapping(
    value = { "/{email}" },
    method = RequestMethod.GET,
    params = "time")
public void getEmail(
    @PathVariable("email") final String sender,
    @RequestParam(value = "time", required = true) final long time) 

When I call API like this

/someone@someone.com?time=10

I observe that sender contains someone@someone instead of someone@someone.com.

When I give it like this

@RequestMapping(
    value = { "/{email:.+}" },
    method = RequestMethod.GET,
    params = "time")
public void getEmail(
    @PathVariable("email") final String sender,
    @RequestParam(value = "time", required = true) final long time) 

I get 406 error.

I tried this too.

<bean
    class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
    <property name="useSuffixPatternMatch" value="false" />
</bean>

Still no help. What am I doing wrong?

Yogi
  • 1,035
  • 2
  • 13
  • 39

1 Answers1

0

Excerpt from RequestMapping JavaDoc:

@PathVariable annotated parameters (Servlet-only) for access to URI template values (i.e. /hotels/{hotel}). Variable values will be converted to the declared method argument type. By default, the URI template will match against the regular expression [^.]* (i.e. any character other than period), but this can be changed by specifying another regular expression, like so: /hotels/{hotel:\d+}. Additionally, @PathVariable can be used on a Map to gain access to all URI template variables.

Your second mapping definition is correct and works. You haven't probably tested it correctly.

Pavel Horal
  • 17,782
  • 3
  • 65
  • 89
  • Hi When I give regular expression, it returns 406 error. I have updated the question – Yogi Jun 13 '14 at 09:22
  • Error 406 is about `Accept` header. How are you testing your REST services? Also I can see that your handler method is `void`... not exactly sure how Spring is supposed to handle responses to such methods. – Pavel Horal Jun 13 '14 at 09:40
  • Hi, I am using firefox plugin RESTClient to test – Yogi Jun 13 '14 at 10:04
  • And are you setting any explicit `Accept` header? Also I would say it is pretty uncommon to not return any value from handler method... (`void` is interpretted as `null`). There might be problem with finding correct HandlerMethodReturnValueHandler => hence error about unsupported response content type... – Pavel Horal Jun 13 '14 at 10:51