From fe4b5241a9e11e24a76bfb9a08c73d6ca85c1259 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 18 Sep 2015 15:07:19 +0200 Subject: [PATCH] =?utf8?q?Continued:=20-=20added=20JSP=20for=20writing=20P?= =?utf8?q?DF=20receipts=20for=20a=20given=20access=20key.=20An=20EJB=20is?= =?utf8?q?=20called=20which=20sends=20back=20a=20wrapped=20byte=20stream?= =?utf8?q?=20-=20rewrote=20constructors=20to=20not=20expose=20NamingExcept?= =?utf8?q?ion=20-=20updated=20jars=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- lib/jshop-core.jar | Bin 35810 -> 35810 bytes lib/jshop-ee-lib.jar | Bin 5796 -> 6486 bytes .../beans/basket/BasketWebBean.java | 3 +- .../beans/category/AdminCategoryWebBean.java | 18 ++-- .../beans/customer/CustomerWebBean.java | 21 +++-- .../beans/product/AdminProductWebBean.java | 20 ++-- .../servlet/receipt/PdfReceiptServlet.java | 86 ++++++++++++++++++ web/WEB-INF/web.xml | 54 ++++++----- 8 files changed, 155 insertions(+), 47 deletions(-) create mode 100644 src/java/org/mxchange/pizzaapplication/servlet/receipt/PdfReceiptServlet.java diff --git a/lib/jshop-core.jar b/lib/jshop-core.jar index afb43eb72ded776a734fd6fa67759259d5de90bb..5f4906c7ffb49defc0f43891ed5564ef2af01111 100644 GIT binary patch delta 584 zcmaDfo$1kZCY}IqW)?061`Y-W&HRZxnoJt`6V0bH0ofN6K;$P)AURo<(HKMl#V0o~ zbED{)Jc-c~BzKn40YvdLIYB6c$?-lMle?L?AR6sJ)O99D5GBQI4Wu@QGpn+I=sNZY zCJ=ptGXzZQ@!Vhr@i_$Y!15I$XTf}TiDzJ1U*;oNoszsLFG!uGPAOP?gT4TmK4f&9 z10>#Uy`K?8``G>jt9N(c0?P+GyRn1BXM1e`tMd)k;Q{fhBIknCb7+RAT)PX(zsLlW+C{hm&4gY#)5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5o59S)zyQKt zFcX3Fl15oppphDr9oXO+Ku$R?BE!_d4wP|+8*!HJkn94Wb`W+&F`|kSs8C^YgQzjs zt{Xlf2U>uNK-dFCVJ#2H`IF=MIVRWgD1%G}*`+Ne!<5bsl~IG+hmv?uj0qD2DaMGa UIxz`8AqF7^3t(h%2!nJ00L{(Ix&QzG delta 413 zcmca+v_zLDz?+$ci-CcIfnl!aL>^71Ii3^Er!xWB7ZgC`CruzZS(eclL>n6G{5DQTW)R)U z^8zeh%>R^;hmlEy8Rm}3V#1a{hfEF>23s^)*Z`<}@=>7RT+c}&&LEDfh$o1eAQAwg z9*G2jC^Jzobyrko@-k6Vkcfep3{xM|sZF{sKj< zcz~knlMnDHPkt}XBM&lMggIt;AJAYBc1D=Zu%uCC@&pMF5mq*kpa2k7vobIU3xaq6 D-3xP$ 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 + -- 2.39.5