1 /*
2 * Licensed under the GPL License. You may not use this file except in compliance with the License.
3 * You may obtain a copy of the License at
4 *
5 * https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6 *
7 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8 * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9 * PURPOSE.
10 */
11 package psiprobe;
12
13 import java.io.File;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.util.List;
17
18 import javax.naming.NamingException;
19
20 import org.apache.catalina.Context;
21 import org.apache.catalina.Wrapper;
22 import org.apache.catalina.connector.Connector;
23
24 import psiprobe.model.ApplicationParam;
25 import psiprobe.model.ApplicationResource;
26 import psiprobe.model.FilterInfo;
27 import psiprobe.model.FilterMapping;
28 import psiprobe.model.jsp.Summary;
29
30 /**
31 * Part of Tomcat container version abstraction layer.
32 */
33 public interface TomcatContainer {
34
35 /**
36 * Finds a context based on its path.
37 *
38 * @param name the context path
39 *
40 * @return the context deployed to that path
41 */
42 Context findContext(String name);
43
44 /**
45 * Formats a context name to a path that the container will recognize. Usually this means
46 * prepending a {@code /} character, although there is special behavior for the root context.
47 *
48 * @param name the context name
49 *
50 * @return the context name formatted as the container expects
51 */
52 String formatContextName(String name);
53
54 /**
55 * Formats a context name so that it can be used as a step for the context descriptor .xml or
56 * deployed .war file. Usually this means stripping a leading {@code /} character, although there
57 * is special behavior for the root context.
58 *
59 * @param contextName the context name
60 *
61 * @return the filename stem for this context
62 */
63 String formatContextFilename(String contextName);
64
65 /**
66 * Find contexts.
67 *
68 * @return all contexts
69 */
70 List<Context> findContexts();
71
72 /**
73 * Find connectors.
74 *
75 * @return all connectors
76 */
77 List<Connector> findConnectors();
78
79 /**
80 * Stops the context with the given name.
81 *
82 * @param name the name of the context to stop
83 *
84 * @throws Exception if stopping the context fails spectacularly
85 */
86 void stop(String name) throws Exception;
87
88 /**
89 * Starts the context with the given name.
90 *
91 * @param name the name of the context to start
92 *
93 * @throws Exception if starting the context fails spectacularly
94 */
95 void start(String name) throws Exception;
96
97 /**
98 * Undeploys a context.
99 *
100 * @param name the context path
101 *
102 * @throws Exception if undeployment fails spectacularly
103 */
104 void remove(String name) throws Exception;
105
106 /**
107 * Installs .war file at the given context name.
108 *
109 * @param name the name of the context
110 *
111 * @throws Exception if installing the .war fails spectacularly
112 */
113 void installWar(String name) throws Exception;
114
115 /**
116 * This method always returns absolute path, no matter what Tomcat is up to.
117 *
118 * @return absolute path to applications base (normally "webapps")
119 */
120 File getAppBase();
121
122 /**
123 * Returns the context descriptor filename for the given context.
124 *
125 * @param context the context
126 *
127 * @return the context descriptor filename, or {@code null}
128 */
129 File getConfigFile(Context context);
130
131 /**
132 * Gets the config base.
133 *
134 * @return the config base
135 */
136 String getConfigBase();
137
138 /**
139 * Sets the wrapper.
140 *
141 * @param wrapper the new wrapper
142 */
143 void setWrapper(Wrapper wrapper);
144
145 /**
146 * Indicates whether this adapter can bind to the container.
147 *
148 * @param binding the ServerInfo of the container
149 *
150 * @return true if binding is possible
151 */
152 boolean canBoundTo(String binding);
153
154 /**
155 * Deploys a context, assuming an context descriptor file exists on the server already.
156 *
157 * @param contextName the context path, which should match the filename
158 *
159 * @return {@code true} if deployment was successful
160 *
161 * @throws Exception if deployment fails spectacularly
162 */
163 boolean installContext(String contextName) throws Exception;
164
165 /**
166 * Lists and optionally compiles all JSPs for the given context. Compilation details are added to
167 * the summary.
168 *
169 * @param context the context
170 * @param summary the summary in which the output is stored
171 * @param compile whether to compile all of the JSPs or not
172 */
173 void listContextJsps(Context context, Summary summary, boolean compile);
174
175 /**
176 * Compiles a list of JSPs. Names of JSP files are expected to be relative to the webapp root. The
177 * method updates summary with compilation details.
178 *
179 * @param context the context
180 * @param summary the summary in which the output is stored
181 * @param names the list of JSPs to compile
182 */
183 void recompileJsps(Context context, Summary summary, List<String> names);
184
185 /**
186 * Deletes the "work" directory of the given context.
187 *
188 * @param context the context
189 */
190 void discardWorkDir(Context context);
191
192 /**
193 * Gets the host name.
194 *
195 * @return the host name
196 */
197 String getHostName();
198
199 /**
200 * Gets the name.
201 *
202 * @return the name
203 */
204 String getName();
205
206 /**
207 * Returns the JSP servlet filename for the given JSP file.
208 *
209 * @param context the context
210 * @param jspName the JSP filename
211 *
212 * @return the name of the JSP servlet
213 */
214 String getServletFileNameForJsp(Context context, String jspName);
215
216 /**
217 * Gets the application filter maps.
218 *
219 * @param context the context
220 *
221 * @return the application filter maps
222 */
223 List<FilterMapping> getApplicationFilterMaps(Context context);
224
225 /**
226 * Gets the available.
227 *
228 * @param context the context
229 *
230 * @return the available
231 */
232 boolean getAvailable(Context context);
233
234 /**
235 * Adds the context resource.
236 *
237 * @param context the context
238 * @param resourceList the resource list
239 */
240 void addContextResource(Context context, List<ApplicationResource> resourceList);
241
242 /**
243 * Adds the context resource link.
244 *
245 * @param context the context
246 * @param resourceList the resource list
247 */
248 void addContextResourceLink(Context context, List<ApplicationResource> resourceList);
249
250 /**
251 * Gets the application filters.
252 *
253 * @param context the context
254 *
255 * @return the application filters
256 */
257 List<FilterInfo> getApplicationFilters(Context context);
258
259 /**
260 * Gets the application init params.
261 *
262 * @param context the context
263 *
264 * @return the application init params
265 */
266 List<ApplicationParam> getApplicationInitParams(Context context);
267
268 /**
269 * Resource exists.
270 *
271 * @param name the name
272 * @param context the context
273 *
274 * @return true, if successful
275 */
276 boolean resourceExists(String name, Context context);
277
278 /**
279 * Gets the resource stream.
280 *
281 * @param name the name
282 * @param context the context
283 *
284 * @return the resource stream
285 *
286 * @throws IOException Signals that an I/O exception has occurred.
287 */
288 InputStream getResourceStream(String name, Context context) throws IOException;
289
290 /**
291 * Gets the resource attributes.
292 *
293 * @param name the name
294 * @param context the context
295 *
296 * @return the resource attributes
297 */
298 Long[] getResourceAttributes(String name, Context context);
299
300 /**
301 * Binds a naming context to the current thread's classloader.
302 *
303 * @param context the catalina context
304 *
305 * @throws NamingException if binding the classloader fails
306 */
307 void bindToContext(Context context) throws NamingException;
308
309 /**
310 * Unbinds a naming context from the current thread's classloader.
311 *
312 * @param context the catalina context
313 *
314 * @throws NamingException if unbinding the classloader fails
315 */
316 void unbindFromContext(Context context) throws NamingException;
317 }