What is the difference b/w @RequestParam and @QueryParam Anotation
@QueryParam is a JAX-RS framework annotation and @RequestParam is from Spring.
@QueryParam is a JAX-RS framework annotation and @RequestParam is from Spring.
This works with Jackson 2 (at least): @Controller public class YourController { @RequestMapping(..) public @ResponseBody Json get() { return new Json(“{ \”attr\” : \”value\” }”); } } class Json { private final String value; public Json(String value) { this.value = value; } @JsonValue @JsonRawValue public String value() { return value; } } Not particularly pretty … Read more
I am replicating one of my previous answers here: If you are using Spring 3.1 this handlerMapping component is an instance of RequestMappingHandlerMapping, which you can query to find the handlerMappedMethods and the associated controllers, along these lines(if you are on an older version of Spring, you should be able to use a similar approach): … Read more
You don’t need @ModelAttribute (parameter) just to use a Bean as a parameter For example, these handler methods work fine with these requests: @RequestMapping(“/a”) void pathA(SomeBean someBean) { assertEquals(“neil”, someBean.getName()); } GET /a?name=neil @RequestMapping(value=”/a”, method=RequestMethod.POST) void pathAPost(SomeBean someBean) { assertEquals(“neil”, someBean.getName()); } POST /a name=neil Use @ModelAttribute (method) to load default data into your model … Read more
You can use this: @RequestMapping(value=”/schedule”, method = RequestMethod.POST) public void action(@RequestParam(value = “param[]”) String[] paramValues){…} it will retrieve all values (inside array paramValues) of parameter param (note the attribute value of RequestParam: it ends with [])
You can use the method status.reason(). For example: @Test public void loginWithBadCredentials() { this.mockMvc.perform( post(“/rest/login”) .contentType(MediaType.APPLICATION_JSON) .content(“{\”username\”: \”baduser\”, \”password\”: \”invalidPassword\”}”) ) .andDo(MockMvcResultHandlers.print()) .andExpect(status().isUnauthorized()) .andExpect(status().reason(containsString(“Bad credentials”))) .andExpect(unauthenticated()); } MockHttpServletResponse: Status = 401 Error message = Authentication Failed: Bad credentials Content type = null Body = Forwarded URL = null Redirected URL = null Cookies = []
After couple of hours of struggling, I’ve finally found the solution. In short, ContentCachingResponseWrapper.copyBodyToResponse() should be called in the end of the filter method. ContentCachingResponseWrapper caches the response body by reading it from response output stream. So, the stream becomes empty. To write response back to the output stream ContentCachingResponseWrapper.copyBodyToResponse() should be used.
Two cases: Your architecture is full client-side: In this case the integration is very natural. Spring MVC exposes your service as a REST (JSON/XML) and your client application with AngularJS consumes your JSON. Here the .war application (Spring MVC) must be deployed in a servlet container (e.g. Tomcat) and your client application can be deployed … Read more
Original answer: The problem with pageable can be solved by providing a custom argument handler. If this is set you will run in a ViewResolver Exception (loop). To avoid this you have to set a ViewResolver (an anonymous JSON ViewResolver class for example). mockMvc = MockMvcBuilders.standaloneSetup(controller) .setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver()) .setViewResolvers(new ViewResolver() { @Override public View resolveViewName(String … Read more
You can get the url with your swagger-ui html page: GET http://localhost:8080/v2/api-docs?group=App And actually you can get all the urls with chrome/firefox develop tools network feature.