1 package org.apache.tapestry.pets; 2 3 import java.util.Map ; 4 5 import javax.servlet.http.HttpSession ; 6 7 import org.apache.tapestry.IRequestCycle; 8 import org.apache.tapestry.engine.BaseEngine; 9 import org.apache.tapestry.request.RequestContext; 10 import org.springframework.context.ApplicationContext; 11 import org.springframework.web.context.support.WebApplicationContextUtils; 12 13 public class PetshopEngine extends BaseEngine { 14 15 private transient boolean killSession; 16 17 public static final String APPLICATION_CONTEXT_KEY = "appContext"; 18 19 22 protected void setupForRequest(RequestContext context) { 23 super.setupForRequest(context); 24 25 Map global = (Map ) getGlobal(); 26 ApplicationContext ac = (ApplicationContext) global 27 .get(APPLICATION_CONTEXT_KEY); 28 29 ac = WebApplicationContextUtils.getWebApplicationContext(context 30 .getServlet().getServletContext()); 31 global.put(APPLICATION_CONTEXT_KEY, ac); 32 33 } 34 35 protected void cleanupAfterRequest(IRequestCycle cycle) { 36 if (killSession) { 37 try { 38 HttpSession session = cycle.getRequestContext().getSession(); 39 if (session != null) { 40 session.invalidate(); 41 } 42 } catch (IllegalStateException ex) { 43 } 45 } 46 } 47 48 public void logout() { 49 Visit visit = (Visit) getVisit(); 50 if (visit != null) { 51 visit.setCustomer(null); 52 visit = null; 53 } 54 killSession = true; 55 } 56 } | Popular Tags |