KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > olstore > global > DemoRequestProcessor


1 /**
2  * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * 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  */

27 package olstore.global;
28
29 //import javax.servlet.ServletException;
30
import javax.servlet.http.*;
31
32 import olstore.framework.EJBHomeFactory;
33
34 import org.apache.struts.action.*;
35 //import org.apache.struts.actions.*;
36
import olstore.entity.UserLocal;
37 import olstore.entity.UserLocalHome;
38 import olstore.session.ShoppingCartLocal;
39 import olstore.session.ShoppingCartLocalHome;
40
41 import javax.ejb.FinderException;
42 //import java.io.IOException;
43
import javax.naming.NamingException;
44 import javax.ejb.CreateException;
45
46 public class DemoRequestProcessor extends RequestProcessor{
47     
48     
49     protected boolean processPreprocess( HttpServletRequest request,
50             HttpServletResponse response){
51         try{
52             if(request.getRemoteUser()!=null || request.getUserPrincipal()!=null){
53               HttpSession session = request.getSession(false); // session should already be set if logged in.
54
if(session.getAttribute("shoppingCart")==null){
55                     EJBHomeFactory factory = EJBHomeFactory.getInstance();
56                     UserLocalHome userHome = (UserLocalHome) factory.getLocalHome( EJBHomeFactory.USER );
57                     ShoppingCartLocalHome shoppingCartHome = (ShoppingCartLocalHome)
58                     factory.getLocalHome(EJBHomeFactory.SHOPPINGCART);
59                     
60                     UserLocal user = null;
61                     user=userHome.findByUsername (request.getRemoteUser());
62                     ShoppingCartLocal shoppingCart = shoppingCartHome.create(user);
63                     session.setAttribute("shoppingCart", shoppingCart);
64                 }
65                 return true;
66             }else{
67                 return true;
68             }
69         }catch(FinderException e){
70             System.out.println("FinderException" + e);
71             return false;
72         }catch(CreateException e){
73             System.out.println("CreateException" + e);
74             return false;
75         }catch(NamingException e){
76             System.out.println("NamingException" + e);
77             return false;
78         }catch(Exception e){
79             System.out.println("General Exception" + e);
80             return true;
81         }
82         
83     }
84     
85     
86     
87 }
88
89
Popular Tags