Issue 1:
tanmoy banerjee opened SPR-7432 and commented

Hi,

In Spring pet-clinic, the implementation is an MVC application serving a browser client. Hence, ModelANdView with

contentNegotiationViewResolver works fine.

From the pet-clinic application:

@RequestMapping(value="/owners/*/pets/{petId}/visits", method=RequestMethod.GET)
public ModelAndView visitsHandler(@PathVariable int petId) {
ModelAndView mav = new ModelAndView("visits");
mav.addObject("visits", this.clinic.loadPet(petId).getVisits());
return mav;
}

I was trying to create a simple application which has a Restful Service provider, with browser and non-browser clients. My sample application ( mvc application - for browser client) - given in the spring forum

@RequestMapping(value = "products/search", method = RequestMethod.GET)
public ModelAndView readAllProducts() {
List<Product> products = productService.findAllProducts();
ModelAndView mav = new ModelAndView();
mav.addObject("products", products);
mav.setViewName("products");
return mav;
}

@RequestMapping(value = "products/new", method = RequestMethod.POST)
public String createProduct(@ModelAttribute Product product) {

Product createdProduct = productService.saveOrUpdate(product);
return "redirect:/products/search";
}

Also, when the controller is created for a rest client,by creating similar methods a bit differently, mainly changing the @ModelAttribute to @RequestBody and the return type of the method to @ResponseBody Product from ModelAndView, it works fine.

(mvc restful application - for non-browser client)

@RequestMapping(value = "products/search", method = RequestMethod.GET)
public @ResponseBody
List<Product> getProducts() {
return productService.findAllProducts();
}

@RequestMapping(value = "products/new", method = RequestMethod.POST)
public @ResponseBody
Product createProduct(@RequestBody Product product) {

return productService.saveOrUpdate(product);
}

However, when the requirement is like this that the application should have a normal MVC behavior, as well as serve non-browser REST clients, currently there isn't a way out other than duplicating the methods/creating separate URIs though the resource to be delivered is the same.

I feel that this should be possible that when i type in the URI.html in a browser , i get the the JSP rendered HTML; while if I run a REST client (non-browser), it should be able to provide me the json/xml/atom as per the media type requested. Currently this is not easy/intuitive as the MVC is returning ModelAndView, or String view but this is not working out for a REST client for which forcefully using a ModelAndVIew doesn't make sense.

Similarly, for MVC, @ModelAttribute is to be used. For REST, where restTemplate POSTs to the URI, @ModelAttribute doesnt work and has to be replaced by @RequestBody.

@Test
public void testPostProduct() {

URI createProductURI = getURI(PRODUCTS_NEW);

Product product = mockNewProduct();

HttpEntity<Product> entity = new HttpEntity<Product>(product);

Product productReturned = this.restTemplate.postForObject(
createProductURI, product, Product.class);

Assert.assertEquals(product, productReturned);

}

Let me know if

ModelAndView/ResponseBody - ResponseEntity can be made compatible to be used in either ways

Same for @ModelAttribute and @RequestBody

Are there anty architecture concerns/reasons for not providing such an option. Though I understand the two ways are for different purposes, I think the API should not restrict this.

Thanks,

Tanmoy

Reference URL: http://forum.springsource.org/showthread.php?t=93358

Issue 2:
Martin Ouellet opened SPR-3490 and commented

In method "public void afterPropertiesSet()" of EhCacheFactoryBean, only cache region created on the fly (i.e. they have no named definition in the xml ehcache configuration file) seems to be decorated. When one defines a named cache, it will never be decorated eventhough one provides a non null CacheEntryFactory property.

We should have these included in the appropriate condition:

if (this.cacheManager.cacheExists(this.cacheName)) {

...

Ehcache decoratedCache = decorateCache(this.cache);

this.cacheManager.replaceCacheWithDecoratedCache(this.cache, decoratedCache);

this.cache = decoratedCache;

}

else ...

Martin

Affects: 2.0.5

Issue Links:

#8594 EhCacheFactoryBean.setBlocking doesn't work for named caches. ("is duplicated by")