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