+ // Cast to servlet request
+ HttpServletRequest servletRequest = (HttpServletRequest) request;
+
+ // Get session instance
+ HttpSession session = servletRequest.getSession();
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("session={0}", session)); //NOI18N
+
+ // Should not be null
+ if (null == session) {
+ // session is null
+ throw new NullPointerException("session is null"); //NOI18N
+ }
+
+ // Get basket instance
+ BasketBean basket = (BasketBean) session.getAttribute("basket"); //NOI18N
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("basket={0}", basket)); //NOI18N
+
+ // Is the item already added?
+ if (item.getItemId() == null) {
+ // Item id is not set
+ throw new NullPointerException(MessageFormat.format("item id of item={0} is null", item)); //NOI18N
+ } else if (item.getItemType() == null) {
+ // Item type is not set
+ throw new NullPointerException(MessageFormat.format("item type of item={0} is null", item)); //NOI18N
+ } else if ((item.getAmount() == null) || (item.getAmount() == 0)) {
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("Amount for item {0} is null - EXIT!", item)); //NOI18N
+
+ // Amount is not entered
+ return;
+ } else if (basket.isItemAdded(item)) {
+ // Yes, then throw exception here
+ throw new ServletException(MessageFormat.format("item id={0} has already been added.", item.getItemId())); //NOI18N
+ }
+
+ // Register item with it
+ basket.addItem(item);
+
+ // Is amount null or zero?
+ if ((item.getAmount() == null) || (item.getAmount() == 0)) {
+ // Then redirect to added=0
+ ((HttpServletResponse) response).sendRedirect(servletRequest.getContextPath() + "/?add=0"); //NOI18N
+ } else {
+ // Redirect to proper URL
+ ((HttpServletResponse) response).sendRedirect(servletRequest.getContextPath() + "/?add=1"); //NOI18N
+ }
+ } catch (final SQLException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {