]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Fri, 18 Sep 2015 13:07:19 +0000 (15:07 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 18 Sep 2015 13:10:08 +0000 (15:10 +0200)
- 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 <roland@mxchange.org>

lib/jshop-core.jar
lib/jshop-ee-lib.jar
src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java
src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebBean.java
src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebBean.java
src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebBean.java
src/java/org/mxchange/pizzaapplication/servlet/receipt/PdfReceiptServlet.java [new file with mode: 0644]
web/WEB-INF/web.xml

index afb43eb72ded776a734fd6fa67759259d5de90bb..5f4906c7ffb49defc0f43891ed5564ef2af01111 100644 (file)
Binary files a/lib/jshop-core.jar and b/lib/jshop-core.jar differ
index db14b45f9d8f2aaea8e995f0fb3c7cadf8b78cdb..0cb88359105bffadc690370cd27fa03168df7bd9 100644 (file)
Binary files a/lib/jshop-ee-lib.jar and b/lib/jshop-ee-lib.jar differ
index 95c2e71cb465b964c0cfb61bd8133746cd22aa96..afc1020d897271d781f3f08159a116eaa67d471a 100644 (file)
@@ -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);
                }
        }
 
index 18fce240e9bebb17a21c5998ad91247216cf13c1..6ca20bd4fa05066cc3d06b3ef40d76952ab8e5d1 100644 (file)
@@ -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
index bc76943a92bfbbb9e8a9634b19d80857831a3b06..298b056d9fdc19155c97ad7c988e06793a405b45 100644 (file)
@@ -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
index 211dbbac8bdb549ebbcae7c1c4ad914ea894713a..9de60f84d59df174ef187dce316597b189f4f451 100644 (file)
@@ -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 (file)
index 0000000..4cab3ed
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+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.";
+       }
+
+}
index 496a039e6fa7c58accfa5e98b8efdbda10d7c97d..131bbd9783284e86b5afe5578292cc9e72a67682 100644 (file)
@@ -1,28 +1,36 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
-       <context-param>
-               <param-name>javax.faces.PROJECT_STAGE</param-name>
-               <param-value>Development</param-value>
-       </context-param>
-       <servlet>
-               <servlet-name>Faces Servlet</servlet-name>
-               <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
-               <load-on-startup>1</load-on-startup>
-       </servlet>
-       <servlet-mapping>
-               <servlet-name>Faces Servlet</servlet-name>
-               <url-pattern>/faces/*</url-pattern>
-       </servlet-mapping>
-       <mime-mapping>
-               <extension>tpl</extension>
-               <mime-type>text/plain</mime-type>
-       </mime-mapping>
-       <session-config>
-               <session-timeout>
+    <context-param>
+        <param-name>javax.faces.PROJECT_STAGE</param-name>
+        <param-value>Development</param-value>
+    </context-param>
+    <servlet>
+        <servlet-name>Faces Servlet</servlet-name>
+        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+        <load-on-startup>1</load-on-startup>
+    </servlet>
+    <servlet>
+        <servlet-name>pdfRecipt</servlet-name>
+        <servlet-class>org.mxchange.pizzaapplication.servlet.receipt.PdfReceiptServlet</servlet-class>
+    </servlet>
+    <servlet-mapping>
+        <servlet-name>Faces Servlet</servlet-name>
+        <url-pattern>/faces/*</url-pattern>
+    </servlet-mapping>
+    <mime-mapping>
+        <extension>tpl</extension>
+        <mime-type>text/plain</mime-type>
+    </mime-mapping>
+    <servlet-mapping>
+        <servlet-name>pdfRecipt</servlet-name>
+        <url-pattern>/customer/recipt.pdf</url-pattern>
+    </servlet-mapping>
+    <session-config>
+        <session-timeout>
                        30
                </session-timeout>
-       </session-config>
-       <welcome-file-list>
-               <welcome-file>faces/index.xhtml</welcome-file>
-       </welcome-file-list>
+    </session-config>
+    <welcome-file-list>
+        <welcome-file>faces/index.xhtml</welcome-file>
+    </welcome-file-list>
 </web-app>