From eb6f37f9d3024f65491f90ffd5b5d607bd414119 Mon Sep 17 00:00:00 2001 From: "Notmoo-PC\\Notmoo" Date: Fri, 3 Nov 2017 18:32:09 +0100 Subject: [PATCH] =?UTF-8?q?Module=20Server=20:=20correction=20d'un=20bug?= =?UTF-8?q?=20emp=C3=AAchant=20la=20persistance=20des=20donn=C3=A9es=20run?= =?UTF-8?q?time,=20comme=20les=20comptes=20connect=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/module/account/FileAccountDao.java | 8 +++++++- .../com/pqt/server/servlets/QueryServlet.java | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Workspace/server/src/main/java/com/pqt/server/module/account/FileAccountDao.java b/Workspace/server/src/main/java/com/pqt/server/module/account/FileAccountDao.java index 50079ce4..a1f07ed8 100644 --- a/Workspace/server/src/main/java/com/pqt/server/module/account/FileAccountDao.java +++ b/Workspace/server/src/main/java/com/pqt/server/module/account/FileAccountDao.java @@ -52,7 +52,13 @@ public class FileAccountDao implements IAccountDao { * @return La première correspondance trouvée, ou {@code null} si aucune correspondance n'a pu être faite. */ private AccountEntry lookupMatchingEntry(Account account, Collection entries){ - return entries.stream().filter(accountEntry -> accountEntry.getUsername().equals(account.getUsername())).findFirst().orElse(null); + return entries.stream() + .filter(accountEntry -> + accountEntry != null + && account != null + && accountEntry.getUsername().equals(account.getUsername())) + .findFirst() + .orElse(null); } @Override diff --git a/Workspace/server/src/main/java/com/pqt/server/servlets/QueryServlet.java b/Workspace/server/src/main/java/com/pqt/server/servlets/QueryServlet.java index 998622b3..aecc6b13 100644 --- a/Workspace/server/src/main/java/com/pqt/server/servlets/QueryServlet.java +++ b/Workspace/server/src/main/java/com/pqt/server/servlets/QueryServlet.java @@ -16,6 +16,17 @@ import java.io.IOException; //TODO ajouter logs @WebServlet(name = "QueryServlet", urlPatterns = "/") public class QueryServlet extends HttpServlet { + + private final IMessageToolFactory messageToolFactory; + private final IMessageHandler msgHandler; + + public QueryServlet() { + super(); + + this.messageToolFactory = new GSonMessageToolFactory(); + this.msgHandler = new SimpleMessageHandler(); + } + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { executeServletProcess(request, response); } @@ -25,8 +36,6 @@ public class QueryServlet extends HttpServlet { } private void executeServletProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - IMessageToolFactory messageToolFactory = new GSonMessageToolFactory(); - IMessageHandler msgHandler = new SimpleMessageHandler(); if (request.getQueryString() != null && !request.getQueryString().isEmpty() && request.getParameter("message")!=null) { try { @@ -34,7 +43,10 @@ public class QueryServlet extends HttpServlet { response.getWriter().write(messageToolFactory.getObjectFormatter(Message.class).format(resp)); }catch(Exception e){ + e.printStackTrace(); response.getWriter().write(String.format("%s : %s", e.getClass().getName(), e.getMessage())); + response.getWriter().write("StackTrace :"); + e.printStackTrace(response.getWriter()); } }else{ response.getWriter().write("Query message was not correctly made : "+request.getQueryString());