]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/servlet/receipt/PizzaPdfReceiptServlet.java
Updated copyright year
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / servlet / receipt / PizzaPdfReceiptServlet.java
1 /*
2  * Copyright (C) 2016 - 2020 Free Software Foundation
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Affero General Public License for more details.
13  *
14  * You should have received a copy of the GNU Affero General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.pizzaapplication.servlet.receipt;
18
19 import java.io.IOException;
20 import javax.faces.view.facelets.FaceletException;
21 import javax.naming.Context;
22 import javax.naming.InitialContext;
23 import javax.naming.NamingException;
24 import javax.servlet.ServletException;
25 import javax.servlet.http.HttpServlet;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28 import org.mxchange.jshopcore.model.receipt.ReceiptBeanRemote;
29 import org.mxchange.jshopcore.model.receipt.WrapableReceipt;
30
31 /**
32  * A servlet for a PDF receipt (official)
33  * <p>
34  * @author Roland Häder<roland@mxchange.org>
35  */
36 public class PizzaPdfReceiptServlet extends HttpServlet {
37
38         /**
39          * Serial number
40          */
41         private static final long serialVersionUID = 497_345_834_783_781L;
42
43         /**
44          * Remote bean
45          */
46         private ReceiptBeanRemote receiptBean;
47
48         /**
49          * Public constructor
50          */
51         public PizzaPdfReceiptServlet () {
52                 // Try it
53                 try {
54                         // Get initial context
55                         Context context = new InitialContext();
56
57                         // Set instance
58                         this.receiptBean = (ReceiptBeanRemote) context.lookup("java:global/jshop-ejb/pdf!org.mxchange.jshopcore.model.receipt.ReceiptBeanRemote"); //NOI18N
59                 } catch (final NamingException e) {
60                         // Throw again
61                         throw new FaceletException(e);
62                 }
63         }
64
65         @Override
66         public String getServletInfo () {
67                 return "Produces a receipt as PDF file for given access key.";
68         }
69
70         @Override
71         protected void doGet (final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
72                 // Is the key set?
73                 if (request.getParameter("key") == null) { //NOI18N
74                         // No more processing here
75                         super.doGet(request, response);
76                         return;
77                 }
78
79                 // Get PDF from bean
80                 WrapableReceipt receipt = this.receiptBean.createReceiptFromAccessKey(request.getParameter("key")); //NOI18N
81
82                 // TODO Write it's content to response output
83         }
84
85         @Override
86         protected void doPost (final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
87                 // Deligate to getter method
88                 this.doGet(request, response);
89         }
90
91 }