/** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    Message message = new Message();
    User user = (User) request.getSession().getAttribute("user");
    if (user.getBasket().isEmpty()) response.sendRedirect("/PolyStunter/basket");
    else {
      if (request.getParameter("street") != null
          && request.getParameter("zipCode") != null
          && request.getParameter("city") != null) {

        String forwardingAddress =
            request.getParameter("street")
                + "<br/>"
                + request.getParameter("zipCode")
                + request.getParameter("city");

        if (BasketDAO.getInstance().validate(user.getBasket(), forwardingAddress) == 1) {
          BasketDAO.getInstance().empty(user.getBasket());
          message.addSuccess("Votre commande a été validée avec succès.");
        } else {
          message.addError("Erreur de traitement de votre commande.");
        }
      } else {
        message.addError("Adresse de livraison non valide.");
      }
      request.setAttribute("message", message);
      getServletContext().getRequestDispatcher("/basket").forward(request, response);
    }
  }
Esempio n. 2
0
  @Override
  public Message read(String location) {

    String strFile = "";
    try {
      strFile = new Scanner(new File(location)).useDelimiter("\\Z").next();
    } catch (IOException ex) {
      System.out.println(ex);
    }

    Message m = new Message();
    m.setType("mess");
    m.setBody(strFile);

    return m;
  }
Esempio n. 3
0
  @Override
  public void write(String location, Message mess) {

    try {
      byte[] fileArray = mess.getBody().getBytes();
      Path newFilePath = Paths.get(location);
      Path parentDir = newFilePath.getParent();
      if (!Files.exists(parentDir)) {
        Files.createDirectories(parentDir);
      }
      Files.write(newFilePath, fileArray, StandardOpenOption.CREATE);
    } catch (IOException ex) {
      Logger.getLogger(FileIO.class.getName()).log(Level.SEVERE, null, ex);
    }
  }