1 27 package olstore.global; 28 29 import javax.servlet.http.*; 31 32 import olstore.framework.EJBHomeFactory; 33 34 import org.apache.struts.action.*; 35 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 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); 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 |