From: Roland Haeder Date: Fri, 18 Sep 2015 13:07:19 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fe4b5241a9e11e24a76bfb9a08c73d6ca85c1259;p=pizzaservice-war.git Continued: - added JSP for writing PDF receipts for a given access key. An EJB is called which sends back a wrapped byte stream - rewrote constructors to not expose NamingException - updated jars Signed-off-by:Roland Häder --- diff --git a/lib/jshop-core.jar b/lib/jshop-core.jar index afb43eb7..5f4906c7 100644 Binary files a/lib/jshop-core.jar and b/lib/jshop-core.jar differ diff --git a/lib/jshop-ee-lib.jar b/lib/jshop-ee-lib.jar index db14b45f..0cb88359 100644 Binary files a/lib/jshop-ee-lib.jar and b/lib/jshop-ee-lib.jar differ diff --git a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java index 95c2e71c..afc1020d 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java @@ -21,6 +21,7 @@ import java.util.List; import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; import javax.faces.FacesException; +import javax.faces.view.facelets.FaceletException; import javax.inject.Named; import javax.naming.Context; import javax.naming.InitialContext; @@ -84,7 +85,7 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl this.basketBean = (BasketSessionBeanRemote) context.lookup("ejb/stateless-basket"); //NOI18N } catch (final NamingException ex) { // Continue to throw - throw new FacesException(ex); + throw new FaceletException(ex); } } diff --git a/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebBean.java index 18fce240..6ca20bd4 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebBean.java @@ -69,15 +69,19 @@ public class AdminCategoryWebBean extends BaseFrameworkBean implements AdminCate /** * Default constructor - * - * @throws javax.naming.NamingException Something happened here? */ - public AdminCategoryWebBean () throws NamingException { - // Get initial context - Context context = new InitialContext(); + public AdminCategoryWebBean () { + // Try it + try { + // Get initial context + Context context = new InitialContext(); - // Try to lookup the bean - this.categoryBean = (AdminCategorySessionBeanRemote) context.lookup("ejb/stateless-admin-category"); //NOI18N + // Try to lookup the bean + this.categoryBean = (AdminCategorySessionBeanRemote) context.lookup("ejb/stateless-admin-category"); //NOI18N + } catch (final NamingException e) { + // Throw it again + throw new FaceletException(e); + } } @Override diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebBean.java index bc76943a..298b056d 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebBean.java @@ -19,6 +19,7 @@ package org.mxchange.pizzaapplication.beans.customer; import java.text.MessageFormat; import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; +import javax.faces.view.facelets.FaceletException; import javax.inject.Named; import javax.naming.Context; import javax.naming.InitialContext; @@ -120,18 +121,22 @@ public class CustomerWebBean extends BaseFrameworkBean implements CustomerWebCon /** * Default constructor - * - * @throws javax.naming.NamingException If something happens? */ - public CustomerWebBean () throws NamingException { - // Get initial context - Context context = new InitialContext(); - + public CustomerWebBean () { // Set gender to UNKNOWN this.gender = Gender.UNKNOWN; - // Try to lookup - this.customerBean = (CustomerSessionBeanRemote) context.lookup("ejb/stateless-customer"); + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup + this.customerBean = (CustomerSessionBeanRemote) context.lookup("ejb/stateless-customer"); + } catch (final NamingException e) { + // Throw again + throw new FaceletException(e); + } } @Override diff --git a/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebBean.java index 211dbbac..9de60f84 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebBean.java @@ -81,15 +81,19 @@ public class AdminProductWebBean extends BaseFrameworkBean implements AdminProdu /** * Default constructor - * - * @throws javax.naming.NamingException Something happened here? */ - public AdminProductWebBean () throws NamingException { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup the bean - this.productBean = (AdminProductSessionBeanRemote) context.lookup("ejb/stateless-admin-product"); //NOI18N + public AdminProductWebBean () { + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup the bean + this.productBean = (AdminProductSessionBeanRemote) context.lookup("ejb/stateless-admin-product"); //NOI18N + } catch (final NamingException e) { + // Throw it again + throw new FaceletException(e); + } } @Override diff --git a/src/java/org/mxchange/pizzaapplication/servlet/receipt/PdfReceiptServlet.java b/src/java/org/mxchange/pizzaapplication/servlet/receipt/PdfReceiptServlet.java new file mode 100644 index 00000000..4cab3ed4 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/servlet/receipt/PdfReceiptServlet.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.servlet.receipt; + +import java.io.IOException; +import javax.faces.view.facelets.FaceletException; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.mxchange.jshopcore.model.receipt.ReceiptBeanRemote; + +/** + * A servlet for a PDF receipt (official) + * + * @author Roland Haeder + */ +public class PdfReceiptServlet extends HttpServlet { + + /** + * Serial number + */ + private static final long serialVersionUID = 497_345_834_783_781L; + + /** + * Remote bean + */ + private final ReceiptBeanRemote receipt; + + /** + * Public constructor + */ + public PdfReceiptServlet () { + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Set instance + this.receipt = (ReceiptBeanRemote) context.lookup("ejb/pdf-receipt"); + } catch (final NamingException e) { + // Throw again + throw new FaceletException(e); + } + } + + @Override + protected void doGet (final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { + // Is the key set? + if (request.getParameter("key") == null) { + // No more processing here + return; + } + + // Get PDF from bean + } + + @Override + protected void doPost (final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { + // Deligate to getter method + this.doGet(request, response); + } + + @Override + public String getServletInfo () { + return "Produces an official recipit as PDF file for given access key."; + } + +} diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml index 496a039e..131bbd97 100644 --- a/web/WEB-INF/web.xml +++ b/web/WEB-INF/web.xml @@ -1,28 +1,36 @@ - - javax.faces.PROJECT_STAGE - Development - - - Faces Servlet - javax.faces.webapp.FacesServlet - 1 - - - Faces Servlet - /faces/* - - - tpl - text/plain - - - + + javax.faces.PROJECT_STAGE + Development + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + pdfRecipt + org.mxchange.pizzaapplication.servlet.receipt.PdfReceiptServlet + + + Faces Servlet + /faces/* + + + tpl + text/plain + + + pdfRecipt + /customer/recipt.pdf + + + 30 - - - faces/index.xhtml - + + + faces/index.xhtml +