Announcement Announcement Module
Collapse
No announcement yet.
Web Service POST did not work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Web Service POST did not work

    I am using Roo 1.1.3.
    I have two web services, one is GET and the other one is POST in the controller below.

    The GET works fine, but POST doesn't. The error is "Content type 'text/plain;charset=UTF-8' not supported". What could be the reason ?

    @RequestMapping("/ws")
    @Controller
    public class WSController {

    @RequestMapping(value = "/offers", method = RequestMethod.GET, headers = "Accept=application/xml")
    public @ResponseBody OfferList findOffersByStoresXml(@RequestParam("store_id") Long store_id) {
    Set<Store> stores = new HashSet<Store>();
    stores.add(Store.findStore(store_id));
    List<Offer> offers = Offer.findOffersByStores(stores).getResultList();
    OfferList list = new OfferList(offers);
    return list;
    }

    @RequestMapping(value = "/saverating", method = RequestMethod.POST, headers = "Accept=application/xml")
    public @ResponseBody RatingInfo saveOfferRating(@RequestBody RatingInfo rating, BindingResult bindingResult) {
    if (!bindingResult.hasErrors()) {
    OfferRating offerRating = new OfferRating();
    offerRating.setOffer(Offer.findOffer(new Long(rating.getCouponid())));
    offerRating.setUuid(rating.getUuid());
    offerRating.setRating(rating.getValue());
    offerRating.persist();

    return rating;
    }else {
    return null;
    }
    }
    }

    Content type 'text/plain;charset=UTF-8' not supported
    org.springframework.web.bind.annotation.support.Ha ndlerMethodInvoker.readWithMessageConverters(Handl erMethodInvoker.java:637)
    org.springframework.web.bind.annotation.support.Ha ndlerMethodInvoker.resolveRequestBody(HandlerMetho dInvoker.java:597)
    org.springframework.web.bind.annotation.support.Ha ndlerMethodInvoker.resolveHandlerArguments(Handler MethodInvoker.java:346)
    org.springframework.web.bind.annotation.support.Ha ndlerMethodInvoker.invokeHandlerMethod(HandlerMeth odInvoker.java:171)
    org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.invokeHandlerMethod(An notationMethodHandlerAdapter.java:426)
    org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.handle(AnnotationMetho dHandlerAdapter.java:414)
    org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:790)

  • #2
    REST Support

    Tested with following code. @RequestBody does return the posted xml. I guess now the question should be:

    Is "REST Support" still available in the spring 3.0.x and above as indicated in 3.0.0.M3 ?

    http://static.springsource.org/sprin...html/ch18.html

    It is removed in the latest Spring document.

    @RequestMapping(value = "/saverating", method = RequestMethod.POST, headers = "Accept=application/xml")
    public @ResponseBody RatingInfo saveOfferRating(@RequestBody String rating) {
    System.out.println(rating);

    return null;
    }

    Comment


    • #3
      I think you are in the wrong forum - this is for Spring Roo specific questions.

      From a brief look at your example, you are defining your REST controller methods to only accept XML: 'Accept=application/xml', yet your request shows you are sending 'text/plain'. This means that the controller methods will not be deemed as applicable by the HandlerMethodInvoker.

      Comment

      Working...
      X