1 15 package org.apache.tapestry.engine; 16 17 import java.io.IOException ; 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import javax.servlet.http.HttpServletRequest ; 22 import javax.servlet.http.HttpServletResponse ; 23 import javax.servlet.http.HttpSession ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.tapestry.IRequestCycle; 27 import org.apache.tapestry.Tapestry; 28 import org.apache.tapestry.services.AbsoluteURLBuilder; 29 import org.apache.tapestry.services.LinkFactory; 30 import org.apache.tapestry.services.ServiceConstants; 31 32 40 41 public class RestartService implements IEngineService 42 { 43 44 private Log _log; 45 46 47 private HttpServletRequest _request; 48 49 50 private HttpServletResponse _response; 51 52 53 private AbsoluteURLBuilder _builder; 54 55 56 private LinkFactory _linkFactory; 57 58 59 private String _servletPath; 60 61 public ILink getLink(IRequestCycle cycle, Object parameter) 62 { 63 if (parameter != null) 64 throw new IllegalArgumentException (EngineMessages.serviceNoParameter(this)); 65 66 Map parameters = new HashMap (); 67 68 parameters.put(ServiceConstants.SERVICE, Tapestry.RESTART_SERVICE); 69 70 return _linkFactory.constructLink(cycle, parameters, true); 71 } 72 73 public void service(IRequestCycle cycle) throws IOException 74 { 75 HttpSession session = _request.getSession(); 76 77 if (session != null) 78 { 79 try 80 { 81 session.invalidate(); 82 } 83 catch (IllegalStateException ex) 84 { 85 _log.warn("Exception thrown invalidating HttpSession.", ex); 86 87 } 89 } 90 91 String url = _builder.constructURL(cycle.getAbsoluteURL(_servletPath)); 92 93 _response.sendRedirect(url); 94 } 95 96 public String getName() 97 { 98 return Tapestry.RESTART_SERVICE; 99 } 100 101 102 public void setLog(Log log) 103 { 104 _log = log; 105 } 106 107 108 public void setRequest(HttpServletRequest request) 109 { 110 _request = request; 111 } 112 113 114 public void setBuilder(AbsoluteURLBuilder builder) 115 { 116 _builder = builder; 117 } 118 119 120 public void setResponse(HttpServletResponse response) 121 { 122 _response = response; 123 } 124 125 126 public void setLinkFactory(LinkFactory linkFactory) 127 { 128 _linkFactory = linkFactory; 129 } 130 131 132 public void setServletPath(String servletPath) 133 { 134 _servletPath = servletPath; 135 } 136 } | Popular Tags |