1

I've been working on a Spring RESTful application consumed from an Android device. My problem occurs when I'm trying to send a POST request. My object is received on the server side but all the attributes are null.

My Controller :

@Controller
public class BeanController {

@Autowired
private ReservationService reservationService;

    @RequestMapping(value = "reservation/add/{dateR}", method = RequestMethod.POST)
public ModelAndView addReservation(@RequestBody Reservation reservation, @PathVariable String dateR) {
    Date date = Date.valueOf(dateR);
    boolean result = reservationService.saveReservation(reservation,date);
    return new ModelAndView("beanXmlView", BindingResult.MODEL_KEY_PREFIX + "reservation", result);
    }
}

On my client side I make sure the object attributes are set.

My Client Side :

Reservation reservation = new Reservation();
            reservation.setDateReservation(Model.date);
            reservation.setSalle(Model.salle);
            if(Model.selectedEquipements.size() == 0)
                reservation.setEquipements(new ArrayList<Equipement>());
            else reservation.setEquipements(Model.selectedEquipements);
            reservation.setPlagesHoraires(Model.selectedPlageHoraires);
            reservation.setUtilisateur(user);
            final String url = "http://10.0.2.2:8080/HibernateSpringREST/";
            RestTemplate restTemplate = new RestTemplate();
            // Add the Jackson and String message converters
            restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
            restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());
            // Make the HTTP POST request, marshaling the request to JSON, and the response to a String
            restTemplate.postForObject(url + "reservation/add/"+Model.date, reservation, Reservation.class);

Does any one have an idea about what might be causing this issue ?

wkl
  • 77,184
  • 16
  • 165
  • 176
Nohad Imad
  • 71
  • 7
  • Do you know what's actually being sent down the wire? – dmon Dec 25 '12 at 00:10
  • i'm sending that reservation object. is there something wrong in what i'm doing ? i using XML btw – Nohad Imad Dec 25 '12 at 00:14
  • Well, it's hard to tell from just the code, the first step is to know if the data is being serialized right. – dmon Dec 25 '12 at 00:57
  • i don't really know but it inserts Null Records in my database cause i'm setting the Hibernate Cascade to All. The records are null since the request body is null. – Nohad Imad Dec 25 '12 at 01:17

1 Answers1

0

From the information given I cannot deduce what the problem is. To find out I'd proceed as follows:

  1. Run your server in debug mode and set a breakpoint on the first line of addReservation
  2. Observe if the reservation parameter is what you expect it to be
  3. If not, inspect the POST request sent from the client, either on the device or with Fiddler/Wireshark
Community
  • 1
  • 1
Marcel Stör
  • 22,695
  • 19
  • 92
  • 198