@RequestMapping(value = "/update", method = RequestMethod.POST)
  public String updateLocation(
      @RequestParam String protocol,
      LocationData locationData,
      Model model,
      HttpServletRequest request)
      throws DuplicateLocationException {

    logger.debug("location param is " + locationData);

    LocationData locationDataResp =
        getLocationClient(request, LocationClient.CLIENT_TYPE.fromString(protocol))
            .updateorCreateLocation(locationData);
    /*
    new JAXBElement<LocationData>();

    LocationData locationDataResp = locationClient.createLocation(locationData.getLocation(), locationData);
     */

    logger.debug("location result is " + locationDataResp);

    List<LocationData> locationDataList = new LinkedList<LocationData>();
    locationDataList.add(locationDataResp);
    model.addAttribute("locationDataList", locationDataList);

    return "locationClient";
  }
  @RequestMapping(value = "/create", method = RequestMethod.POST)
  public String createLocation(
      @RequestParam String protocol,
      LocationData locationData,
      Model model,
      HttpServletRequest request,
      BindingResult bindingResult)
      throws DuplicateLocationException {

    logger.debug("location param is " + locationData);

    try {
      LocationData locationDataResp =
          getLocationClient(request, LocationClient.CLIENT_TYPE.fromString(protocol))
              .createLocation(locationData);
      List<LocationData> locationDataList = new LinkedList<LocationData>();
      locationDataList.add(locationDataResp);
      model.addAttribute("locationDataList", locationDataList);
      logger.debug("location result is " + locationDataResp);
    } catch (ValidationException e) {
      for (String field : e.getExceptionData().getData().keySet()) {
        bindingResult.rejectValue(field, null, e.getExceptionData().getData().get(field));
      }
    }

    return "locationClient";
  }
  @RequestMapping(value = "/deleteall", method = RequestMethod.GET)
  public String deleteAllLocation(
      @RequestParam String protocol, Model model, HttpServletRequest request)
      throws DuplicateLocationException {
    getLocationClient(request, LocationClient.CLIENT_TYPE.fromString(protocol)).deleteAllLocation();

    return "locationClient";
  }
  @RequestMapping(value = "/readall", method = RequestMethod.GET)
  public String readAllLocation(
      @RequestParam String protocol, Model model, HttpServletRequest request)
      throws DuplicateLocationException {
    Collection<LocationData> locationDataList =
        getLocationClient(request, LocationClient.CLIENT_TYPE.fromString(protocol))
            .readAllLocations();

    model.addAttribute("locationDataList", locationDataList);

    return "locationClient";
  }
  private LocationClient getLocationClient(
      HttpServletRequest request, LocationClient.CLIENT_TYPE clientType) {

    if (clientType.equals(LocationClient.CLIENT_TYPE.SOAP)) {
      if (locationClientSOAP == null) {
        locationClientSOAP =
            new LocationClient(getApplicationURI(request), LocationClient.CLIENT_TYPE.SOAP);
      }

      return locationClientSOAP;
    }

    if (clientType.equals(LocationClient.CLIENT_TYPE.REST)) {
      if (locationClientREST == null) {
        locationClientREST =
            new LocationClient(getApplicationURI(request), LocationClient.CLIENT_TYPE.REST);
      }

      return locationClientREST;
    }

    return null;
  }
  @RequestMapping(value = "/read", method = RequestMethod.GET)
  public String readLocation(
      @RequestParam String protocol,
      @RequestParam("location") String location,
      Model model,
      HttpServletRequest request)
      throws LocationNotFoundException {

    logger.debug("location param is " + location);

    LocationData locationDataResp =
        getLocationClient(request, LocationClient.CLIENT_TYPE.fromString(protocol))
            .readLocation(location);

    logger.debug("location result is " + locationDataResp);

    List<LocationData> locationDataList = new LinkedList<LocationData>();
    locationDataList.add(locationDataResp);
    model.addAttribute("locationDataList", locationDataList);

    return "locationClient";
  }