- 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>
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;
this.basketBean = (BasketSessionBeanRemote) context.lookup("ejb/stateless-basket"); //NOI18N
} catch (final NamingException ex) {
// Continue to throw
- throw new FacesException(ex);
+ throw new FaceletException(ex);
}
}
/**
* 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
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;
/**
* 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
/**
* 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
--- /dev/null
+/*
+ * 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.";
+ }
+
+}
<?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>