[SERVEUR] Mise en place d'un mécanisme de decoding UTF-8 pour pouvoir supporter l'encoding mis en palce lors du précédent commit

This commit is contained in:
Notmoo-PC\Notmoo 2018-01-24 18:38:17 +01:00
parent d771e9214d
commit d28dcdbc47

View File

@ -15,6 +15,8 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
//TODO Issue #6 : ajouter logs //TODO Issue #6 : ajouter logs
@WebServlet(name = "QueryServlet", urlPatterns = "/") @WebServlet(name = "QueryServlet", urlPatterns = "/")
@ -52,6 +54,12 @@ public class QueryServlet extends HttpServlet {
} }
if (request.getQueryString() != null && !request.getQueryString().isEmpty() && request.getParameter("message") != null) { if (request.getQueryString() != null && !request.getQueryString().isEmpty() && request.getParameter("message") != null) {
try { try {
String messageToHandle;
if(request.getParameter("encode")!=null)
messageToHandle = URLDecoder.decode(request.getParameter("message"), request.getParameter("encode"));
else
messageToHandle = request.getParameter("message");
Message resp = msgHandler.handleMessage(messageToolFactory.getObjectParser(Message.class).parse(request.getParameter("message"))); Message resp = msgHandler.handleMessage(messageToolFactory.getObjectParser(Message.class).parse(request.getParameter("message")));
response.getWriter().write(messageToolFactory.getObjectFormatter(Message.class).format(resp)); response.getWriter().write(messageToolFactory.getObjectFormatter(Message.class).format(resp));