From: Roland Haeder Date: Tue, 11 Aug 2015 12:06:41 +0000 (+0200) Subject: Continued with project: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=25bd7c866b98b327cefc61e96114ff548648f7f7;p=pizzaservice-war.git Continued with project: - Moved call of markProductAsOrdered() to do_order.jsp - Logged more data in some debug/trace messages - If choose[product] is set in session, it can only be unset now, this saves some calls - Added some trace messages - Removed synchronized() check Signed-off-by:Roland Häder --- diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java index 5eb1ce18..4ce28a5b 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java @@ -402,7 +402,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } // Get element - this.getLogger().debug("Calling handleChooseFromRequestSession() ..."); //NOI18N + this.getLogger().debug(MessageFormat.format("Calling handleChooseFromRequestSession({0},{1},{2}) ...", product.getName(), request, session)); //NOI18N String choosen = this.handleChooseFromRequestSession(product, request, session); this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getName(), choosen)); //NOI18N @@ -503,7 +503,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } // Get choosen - this.getLogger().debug("Calling handleChooseFromRequestSession() ..."); //NOI18N + this.getLogger().debug(MessageFormat.format("Calling handleChooseFromRequestSession({0},{1},{2}) ...", product.getName(), request, session)); //NOI18N String choosen = this.handleChooseFromRequestSession(product, request, session); this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getName(), choosen)); //NOI18N @@ -625,14 +625,14 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P this.getLogger().warn(ex); return "0"; //NOI18N } - + // Then set it in session this.setValueInSession(product, session, HTTP_PARAM_AMOUNT, object); - + // And return it return (String) object; } - + // Trace message this.getLogger().trace("Calling getAmountFromSession() ..."); //NOI18N @@ -664,15 +664,15 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Not set throw new NullPointerException("session is null"); //NOI18N } - + // Get choosen - this.getLogger().debug("Calling handleChooseFromRequestSession() ..."); //NOI18N + this.getLogger().debug(MessageFormat.format("Calling handleChooseFromRequestSession({0},{1},{2}) ...", product.getName(), request, session)); //NOI18N String choosen = this.handleChooseFromRequestSession(product, request, session); this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getName(), choosen)); //NOI18N - + // Must not be null assert(choosen instanceof String): "choosen is null"; //NOI18N - + // Is it not choosen? if (choosen.isEmpty()) { // Not choosen @@ -681,10 +681,10 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Get amount String amount = this.handleAmountFromRequestSession(product, request, session); - + // Must not be null assert(amount instanceof String): "amount is not set"; //NOI18N - + // Trace message this.getLogger().trace(MessageFormat.format("amount={0} - EXIT!", amount)); //NOI18N @@ -904,7 +904,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P this.getLogger().trace(MessageFormat.format("product={0},session={1},attribute={2} - CALLED!", product, session, attribute)); //NOI18N // Init variable - Object value = this.getValueFromSession(session, String.format(HTTP_PARAM_MASK, product.getName(), attribute)); + Object value = this.getValueFromSession(session, String.format(HTTP_PARAM_MASK, attribute, product.getName())); this.getLogger().debug(MessageFormat.format("product={0},attribute={1},value={2}", product.getName(), attribute, value)); //NOI18N @@ -924,7 +924,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P */ private Object getValueFromSession (final HttpSession session, final String key) { // Trace message - this.getLogger().trace(MessageFormat.format("session={043},key={1} - CALLED!", session, key)); //NOI18N + this.getLogger().trace(MessageFormat.format("session={0},key={1} - CALLED!", session, key)); //NOI18N // Init value Object value = null; @@ -971,12 +971,18 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Check request method if (!"POST".equals(request.getMethod())) { //NOI18N // Not POST, so get from session + this.getLogger().trace(MessageFormat.format("Calling this.getChooseFromSession({0},{1}) ... - EXIT!", product.getName(), session)); return this.getChooseFromSession(product, session); } else if (this.isProductOrdered(product, session)) { // Product is ordered + this.getLogger().trace(MessageFormat.format("Calling this.getChooseFromSession({0},{1}) ... - EXIT!", product.getName(), session)); + return this.getChooseFromSession(product, session); + } else if (!this.getChooseFromSession(product, session).isEmpty()) { + // Found in session + this.getLogger().trace(MessageFormat.format("Calling this.getChooseFromSession({0},{1}) ... - EXIT!", product.getName(), session)); return this.getChooseFromSession(product, session); } - + // Get reqzest element object = request.getParameter(String.format(HTTP_PARAM_MASK, HTTP_PARAM_CHOOSE, product.getName())); this.getLogger().debug(MessageFormat.format("product={0},object={1}", product.getName(), object)); //NOI18N @@ -1044,13 +1050,11 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P private void setValueInSession (final Product product, final HttpSession session, final String keyPart, final Object value) { // Trace message this.getLogger().trace(MessageFormat.format("product={0},session={1},keyPart={2},value={3} - CALLED!", product, session, keyPart, value)); //NOI18N - - synchronized(session) { - // Set it synced - this.getLogger().debug(MessageFormat.format("Setting value={0} for product={1},keyPart={2}", value, product.getName(), keyPart)); //NOI18N - this.setValueInSession(session, String.format(HTTP_PARAM_MASK, product.getName(), keyPart), value); - } - + + // Set it synced + this.getLogger().debug(MessageFormat.format("Setting value={0} for product={1},keyPart={2}", value, product.getName(), keyPart)); //NOI18N + this.setValueInSession(session, String.format(HTTP_PARAM_MASK, keyPart, product.getName()), value); + // Trace message this.getLogger().trace("EXIT!"); //NOI18N } diff --git a/web/finished.jsp b/web/finished.jsp index 3788ba18..c2ca53b6 100644 --- a/web/finished.jsp +++ b/web/finished.jsp @@ -67,11 +67,6 @@ <% // "Walk" over all products for (final Product product : app.getProducts()) { - // Is it choosen? - if (app.isProductChoosen(product, request, session)) { - // Mark product as ordered - app.markProductAsOrdered(product, session); - } %> diff --git a/web/form_handler/do_order.jsp b/web/form_handler/do_order.jsp index cdfe1c37..06c44225 100644 --- a/web/form_handler/do_order.jsp +++ b/web/form_handler/do_order.jsp @@ -6,9 +6,10 @@ <%--<%@page errorPage="errorHandler.jsp" %>--%> <%@page contentType="text/html" pageEncoding="UTF-8"%> -<%@page import="org.mxchange.pizzaapplication.beans.CustomerBean" %> <%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> <%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.CustomerBean" %> +<%@page import="org.mxchange.pizzaapplication.product.Product"%> <% // Init application instance @@ -17,6 +18,16 @@ // Is it post? if ("POST".equals(request.getMethod())) { //NOI18N // Handle saving customer data and such things + + // "Walk" over all products + for (final Product product : app.getProducts()) { + // Is it choosen? + if (app.isProductChoosen(product, request, session)) { + // Mark product as ordered + app.markProductAsOrdered(product, session); + } + } + // Redirect to proper URL // @TODO Commented out for developing: //response.sendRedirect(request.getContextPath() + "/finished.jsp");