@RequestMapping(method = RequestMethod.GET, value = "/getparkingsbyagency/{agencyId}")
  public @ResponseBody void getParkingsByAgency(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      @PathVariable String agencyId)
      throws InvocationException, AcServiceException {
    //		if ("COMUNE_DI_TRENTO".equals(agencyId)) {
    //			getParkings(request,response,session);
    //			return;
    //		}
    try {
      String address = otpURL + SMARTPLANNER + "getParkingsByAgency?agencyId=" + agencyId;

      String routes = HTTPConnector.doGet(address, null, null, MediaType.APPLICATION_JSON, "UTF-8");

      response.setContentType("application/json; charset=utf-8");
      response.getWriter().write(routes);

    } catch (ConnectorException e0) {
      response.setStatus(e0.getCode());
    } catch (Exception e) {
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
  }
  @RequestMapping(method = RequestMethod.POST, value = "/planrecurrent/{clientId}")
  public @ResponseBody RecurrentJourney planRecurrentJourney(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      @RequestBody RecurrentJourneyParameters parameters,
      @PathVariable String clientId)
      throws InvocationException, AcServiceException {
    try {
      User user = getUser(request);
      String userId = getUserId(user);
      if (userId == null) {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return null;
      }

      List<String> reqs = buildRecurrentJourneyPlannerRequest(parameters);
      List<SimpleLeg> legs = new ArrayList<SimpleLeg>();
      ObjectMapper mapper = new ObjectMapper();
      for (String req : reqs) {
        String plan =
            HTTPConnector.doGet(
                otpURL + SMARTPLANNER + RECURRENT, req, MediaType.APPLICATION_JSON, null, "UTF-8");
        List sl = mapper.readValue(plan, List.class);
        for (Object o : sl) {
          legs.add((SimpleLeg) mapper.convertValue(o, SimpleLeg.class));
        }
      }

      DomainObject res =
          getObjectByClientId(
              clientId, "smartcampus.services.journeyplanner.RecurrentJourneyObject");
      if (res != null) {
        String objectId = checkUser(res, userId);
        if (objectId == null) {
          response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        } else {
          RecurrentJourney oldJourney =
              mapper.convertValue(res.getContent().get("data"), RecurrentJourney.class);
          RecurrentJourney journey = new RecurrentJourney();
          journey.setParameters(parameters);
          journey.setLegs(legs);
          journey.setMonitorLegs(buildMonitorMap(legs, oldJourney.getMonitorLegs()));
          return journey;
        }
      } else {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      }

    } catch (ConnectorException e0) {
      response.setStatus(e0.getCode());
    } catch (Exception e) {
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }

    return null;
  }
  // no crud
  @RequestMapping(method = RequestMethod.POST, value = "/plansinglejourney")
  public @ResponseBody void planSingleJourney(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      @RequestBody SingleJourney journeyRequest)
      throws InvocationException, AcServiceException {
    try {
      User user = getUser(request);
      String userId = getUserId(user);

      logger.info("-" + userId + "~AppConsume~plan");

      if (userId == null) {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return;
      }

      List<String> reqs = buildItineraryPlannerRequest(journeyRequest);

      ObjectMapper mapper = new ObjectMapper();

      List<Itinerary> itineraries = new ArrayList<Itinerary>();

      for (String req : reqs) {
        String plan =
            HTTPConnector.doGet(
                otpURL + SMARTPLANNER + PLAN, req, MediaType.APPLICATION_JSON, null, "UTF-8");
        List its = mapper.readValue(plan, List.class);
        for (Object it : its) {
          Itinerary itinerary = mapper.convertValue(it, Itinerary.class);
          itineraries.add(itinerary);
        }
      }

      ItinerarySorter.sort(itineraries, journeyRequest.getRouteType());

      response.setContentType("application/json; charset=utf-8");

      String result = mapper.writeValueAsString(itineraries);

      ServletOutputStream sos = response.getOutputStream();
      sos.write(result.getBytes());
    } catch (ConnectorException e0) {
      response.setStatus(e0.getCode());
    } catch (Exception e) {
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
    //		return;
  }
  @RequestMapping(method = RequestMethod.POST, value = "/planrecurrent")
  public @ResponseBody RecurrentJourney planRecurrentJourney(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestBody RecurrentJourneyParameters parameters,
      HttpSession session)
      throws InvocationException, AcServiceException {
    try {
      User user = getUser(request);
      String userId = getUserId(user);
      if (userId == null) {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return null;
      }

      List<String> reqs = buildRecurrentJourneyPlannerRequest(parameters);
      List<SimpleLeg> legs = new ArrayList<SimpleLeg>();
      ObjectMapper mapper = new ObjectMapper();
      for (String req : reqs) {
        String plan =
            HTTPConnector.doGet(
                otpURL + SMARTPLANNER + RECURRENT, req, MediaType.APPLICATION_JSON, null, "UTF-8");
        List sl = mapper.readValue(plan, List.class);
        for (Object o : sl) {
          legs.add((SimpleLeg) mapper.convertValue(o, SimpleLeg.class));
        }
      }

      RecurrentJourney journey = new RecurrentJourney();
      journey.setParameters(parameters);
      journey.setLegs(legs);
      journey.setMonitorLegs(buildMonitorMap(legs));

      response.setContentType("application/json; charset=utf-8");

      String result = mapper.writeValueAsString(journey);

      ServletOutputStream sos = response.getOutputStream();
      sos.write(result.getBytes());
    } catch (ConnectorException e0) {
      response.setStatus(e0.getCode());
    } catch (Exception e) {
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }

    return null;
  }
  @RequestMapping(method = RequestMethod.GET, value = "/getbikesharing")
  public @ResponseBody void getBikeSharing(
      HttpServletRequest request, HttpServletResponse response, HttpSession session)
      throws InvocationException, AcServiceException {
    try {
      String address = otpURL + SMARTPLANNER + "getBikeSharing";

      String routes = HTTPConnector.doGet(address, null, null, MediaType.APPLICATION_JSON, "UTF-8");

      response.setContentType("application/json; charset=utf-8");
      response.getWriter().write(routes);

    } catch (ConnectorException e0) {
      response.setStatus(e0.getCode());
    } catch (Exception e) {
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
  }
  @RequestMapping(method = RequestMethod.GET, value = "/getroadinfobyagency/{agencyId}/{from}/{to}")
  public @ResponseBody void getRoadInfoByAgency(
      HttpServletResponse response,
      @PathVariable String agencyId,
      @PathVariable Long from,
      @PathVariable Long to)
      throws InvocationException, AcServiceException {
    try {
      String address =
          otpURL + SMARTPLANNER + "getAR?agencyId=" + agencyId + "&from=" + from + "&to=" + to;

      String roadInfo =
          HTTPConnector.doGet(address, null, null, MediaType.APPLICATION_JSON, "UTF-8");

      response.setContentType("application/json; charset=utf-8");
      response.getWriter().write(roadInfo);

    } catch (ConnectorException e0) {
      response.setStatus(e0.getCode());
    } catch (Exception e) {
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
  }