1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
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.LinkFactory; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | public class RestartService implements IEngineService |
41 | |
{ |
42 | |
|
43 | |
|
44 | |
private Log _log; |
45 | |
|
46 | |
|
47 | |
private HttpServletRequest _request; |
48 | |
|
49 | |
|
50 | |
private HttpServletResponse _response; |
51 | |
|
52 | |
|
53 | |
private LinkFactory _linkFactory; |
54 | |
|
55 | |
|
56 | |
private String _servletPath; |
57 | |
|
58 | |
public ILink getLink(boolean post, Object parameter) |
59 | |
{ |
60 | 0 | if (parameter != null) |
61 | 0 | throw new IllegalArgumentException(EngineMessages |
62 | |
.serviceNoParameter(this)); |
63 | |
|
64 | 0 | Map parameters = new HashMap(); |
65 | |
|
66 | 0 | return _linkFactory.constructLink(this, post, parameters, true); |
67 | |
} |
68 | |
|
69 | |
public void service(IRequestCycle cycle) |
70 | |
throws IOException |
71 | |
{ |
72 | 0 | HttpSession session = _request.getSession(false); |
73 | |
|
74 | 0 | if (session != null) |
75 | |
{ |
76 | |
try |
77 | |
{ |
78 | 0 | session.invalidate(); |
79 | |
} |
80 | 0 | catch (IllegalStateException ex) |
81 | |
{ |
82 | 0 | _log.warn("Exception thrown invalidating HttpSession.", ex); |
83 | |
|
84 | |
|
85 | 0 | } |
86 | |
} |
87 | |
|
88 | 0 | String url = cycle.getAbsoluteURL(_servletPath); |
89 | |
|
90 | 0 | _response.sendRedirect(url); |
91 | 0 | } |
92 | |
|
93 | |
public String getName() |
94 | |
{ |
95 | 0 | return Tapestry.RESTART_SERVICE; |
96 | |
} |
97 | |
|
98 | |
|
99 | |
public void setLog(Log log) |
100 | |
{ |
101 | 0 | _log = log; |
102 | 0 | } |
103 | |
|
104 | |
|
105 | |
public void setRequest(HttpServletRequest request) |
106 | |
{ |
107 | 0 | _request = request; |
108 | 0 | } |
109 | |
|
110 | |
|
111 | |
public void setResponse(HttpServletResponse response) |
112 | |
{ |
113 | 0 | _response = response; |
114 | 0 | } |
115 | |
|
116 | |
|
117 | |
public void setLinkFactory(LinkFactory linkFactory) |
118 | |
{ |
119 | 0 | _linkFactory = linkFactory; |
120 | 0 | } |
121 | |
|
122 | |
|
123 | |
public void setServletPath(String servletPath) |
124 | |
{ |
125 | 0 | _servletPath = servletPath; |
126 | 0 | } |
127 | |
} |