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