01: /**
02: * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or any later version.
08: *
09: * This library 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 GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17: * USA
18: *
19: * Component of: Red Hat Application Server
20: *
21: * Initial Developers: Aizaz Ahmed
22: * Vivek Lakshmanan
23: * Andrew Overholt
24: * Matthew Wringe
25: *
26: */package olstore.global;
27:
28: //import javax.servlet.ServletException;
29: import javax.servlet.http.*;
30:
31: import olstore.framework.EJBHomeFactory;
32:
33: import org.apache.struts.action.*; //import org.apache.struts.actions.*;
34: import olstore.entity.UserLocal;
35: import olstore.entity.UserLocalHome;
36: import olstore.session.ShoppingCartLocal;
37: import olstore.session.ShoppingCartLocalHome;
38:
39: import javax.ejb.FinderException; //import java.io.IOException;
40: import javax.naming.NamingException;
41: import javax.ejb.CreateException;
42:
43: public class DemoRequestProcessor extends RequestProcessor {
44:
45: protected boolean processPreprocess(HttpServletRequest request,
46: HttpServletResponse response) {
47: try {
48: if (request.getRemoteUser() != null
49: || request.getUserPrincipal() != null) {
50: HttpSession session = request.getSession(false); // session should already be set if logged in.
51: if (session.getAttribute("shoppingCart") == null) {
52: EJBHomeFactory factory = EJBHomeFactory
53: .getInstance();
54: UserLocalHome userHome = (UserLocalHome) factory
55: .getLocalHome(EJBHomeFactory.USER);
56: ShoppingCartLocalHome shoppingCartHome = (ShoppingCartLocalHome) factory
57: .getLocalHome(EJBHomeFactory.SHOPPINGCART);
58:
59: UserLocal user = null;
60: user = userHome.findByUsername(request
61: .getRemoteUser());
62: ShoppingCartLocal shoppingCart = shoppingCartHome
63: .create(user);
64: session.setAttribute("shoppingCart", shoppingCart);
65: }
66: return true;
67: } else {
68: return true;
69: }
70: } catch (FinderException e) {
71: System.out.println("FinderException" + e);
72: return false;
73: } catch (CreateException e) {
74: System.out.println("CreateException" + e);
75: return false;
76: } catch (NamingException e) {
77: System.out.println("NamingException" + e);
78: return false;
79: } catch (Exception e) {
80: System.out.println("General Exception" + e);
81: return true;
82: }
83:
84: }
85:
86: }
|