Line
Link Here
|
0 |
-- Tomcat.java |
0 |
++ Tomcat-fixed.java |
Lines 75-102
Link Here
|
75 |
/** |
75 |
/** |
76 |
* Minimal tomcat starter for embedding/unit tests. |
76 |
* Minimal tomcat starter for embedding/unit tests. |
77 |
* |
77 |
* |
|
|
78 |
* <p> |
78 |
* Tomcat supports multiple styles of configuration and |
79 |
* Tomcat supports multiple styles of configuration and |
79 |
* startup - the most common and stable is server.xml-based, |
80 |
* startup - the most common and stable is server.xml-based, |
80 |
* implemented in org.apache.catalina.startup.Bootstrap. |
81 |
* implemented in org.apache.catalina.startup.Bootstrap. |
81 |
* |
82 |
* |
|
|
83 |
* <p> |
82 |
* This class is for use in apps that embed tomcat. |
84 |
* This class is for use in apps that embed tomcat. |
|
|
85 |
* |
86 |
* <p> |
83 |
* Requirements: |
87 |
* Requirements: |
|
|
88 |
* <ul> |
89 |
* <li>all tomcat classes and possibly servlets are in the classpath. |
90 |
* ( for example all is in one big jar, or in eclipse CP, or in |
91 |
* any other combination )</li> |
84 |
* |
92 |
* |
85 |
* - all tomcat classes and possibly servlets are in the classpath. |
93 |
* <li>we need one temporary directory for work files</li> |
86 |
* ( for example all is in one big jar, or in eclipse CP, or in any other |
|
|
87 |
* combination ) |
88 |
* |
94 |
* |
89 |
* - we need one temporary directory for work files |
95 |
* <li>no config file is required. This class provides methods to |
|
|
96 |
* use if you have a webapp with a web.xml file, but it is |
97 |
* optional - you can use your own servlets.</li> |
98 |
* </ul> |
90 |
* |
99 |
* |
91 |
* - no config file is required. This class provides methods to |
100 |
* <p> |
92 |
* use if you have a webapp with a web.xml file, but it is |
|
|
93 |
* optional - you can use your own servlets. |
94 |
* |
95 |
* There are a variety of 'add' methods to configure servlets and webapps. These |
101 |
* There are a variety of 'add' methods to configure servlets and webapps. These |
96 |
* methods, by default, create a simple in-memory security realm and apply it. |
102 |
* methods, by default, create a simple in-memory security realm and apply it. |
97 |
* If you need more complex security processing, you can define a subclass of |
103 |
* If you need more complex security processing, you can define a subclass of |
98 |
* this class. |
104 |
* this class. |
99 |
* |
105 |
* |
|
|
106 |
* <p> |
100 |
* This class provides a set of convenience methods for configuring webapp |
107 |
* This class provides a set of convenience methods for configuring webapp |
101 |
* contexts, all overloads of the method <code>addWebapp</code>. These methods |
108 |
* contexts, all overloads of the method <code>addWebapp</code>. These methods |
102 |
* create a webapp context, configure it, and then add it to a {@link Host}. |
109 |
* create a webapp context, configure it, and then add it to a {@link Host}. |
Lines 104-109
Link Here
|
104 |
* listener that adds the standard DefaultServlet, JSP processing, and welcome |
111 |
* listener that adds the standard DefaultServlet, JSP processing, and welcome |
105 |
* files. |
112 |
* files. |
106 |
* |
113 |
* |
|
|
114 |
* <p> |
107 |
* In complex cases, you may prefer to use the ordinary Tomcat API to create |
115 |
* In complex cases, you may prefer to use the ordinary Tomcat API to create |
108 |
* webapp contexts; for example, you might need to install a custom Loader |
116 |
* webapp contexts; for example, you might need to install a custom Loader |
109 |
* before the call to {@link Host#addChild(Container)}. To replicate the basic |
117 |
* before the call to {@link Host#addChild(Container)}. To replicate the basic |
Lines 111-124
Link Here
|
111 |
* methods of this class: {@link #noDefaultWebXmlPath()} and |
119 |
* methods of this class: {@link #noDefaultWebXmlPath()} and |
112 |
* {@link #getDefaultWebXmlListener()}. |
120 |
* {@link #getDefaultWebXmlListener()}. |
113 |
* |
121 |
* |
|
|
122 |
* <p> |
114 |
* {@link #getDefaultWebXmlListener()} returns a {@link LifecycleListener} that |
123 |
* {@link #getDefaultWebXmlListener()} returns a {@link LifecycleListener} that |
115 |
* adds the standard DefaultServlet, JSP processing, and welcome files. If you |
124 |
* adds the standard DefaultServlet, JSP processing, and welcome files. If you |
116 |
* add this listener, you must prevent Tomcat from applying any standard global |
125 |
* add this listener, you must prevent Tomcat from applying any standard global |
117 |
* web.xml with ... |
126 |
* web.xml with ... |
118 |
* |
127 |
* |
|
|
128 |
* <p> |
119 |
* {@link #noDefaultWebXmlPath()} returns a dummy pathname to configure to |
129 |
* {@link #noDefaultWebXmlPath()} returns a dummy pathname to configure to |
120 |
* prevent {@link ContextConfig} from trying to apply a global web.xml file. |
130 |
* prevent {@link ContextConfig} from trying to apply a global web.xml file. |
121 |
* |
131 |
* |
|
|
132 |
* <p> |
122 |
* This class provides a main() and few simple CLI arguments, |
133 |
* This class provides a main() and few simple CLI arguments, |
123 |
* see setters for doc. It can be used for simple tests and |
134 |
* see setters for doc. It can be used for simple tests and |
124 |
* demo. |
135 |
* demo. |
Lines 153-163
Link Here
|
153 |
* Tomcat needs a directory for temp files. This should be the |
164 |
* Tomcat needs a directory for temp files. This should be the |
154 |
* first method called. |
165 |
* first method called. |
155 |
* |
166 |
* |
|
|
167 |
* <p> |
156 |
* By default, if this method is not called, we use: |
168 |
* By default, if this method is not called, we use: |
157 |
* - system properties - catalina.base, catalina.home |
169 |
* <ul> |
158 |
* - $PWD/tomcat.$PORT |
170 |
* <li>system properties - catalina.base, catalina.home</li> |
|
|
171 |
* <li>$PWD/tomcat.$PORT</li> |
172 |
* </ul> |
159 |
* (/tmp doesn't seem a good choice for security). |
173 |
* (/tmp doesn't seem a good choice for security). |
160 |
* |
174 |
* |
|
|
175 |
* <p> |
161 |
* TODO: disable work dir if not needed ( no jsp, etc ). |
176 |
* TODO: disable work dir if not needed ( no jsp, etc ). |
162 |
* |
177 |
* |
163 |
* @param basedir The Tomcat base folder on which all others |
178 |
* @param basedir The Tomcat base folder on which all others |
Lines 215-238
Link Here
|
215 |
* programmatically, there will still be no scanning for |
230 |
* programmatically, there will still be no scanning for |
216 |
* {@link javax.servlet.annotation.HandlesTypes} matches. |
231 |
* {@link javax.servlet.annotation.HandlesTypes} matches. |
217 |
* |
232 |
* |
|
|
233 |
* <p> |
218 |
* API calls equivalent with web.xml: |
234 |
* API calls equivalent with web.xml: |
219 |
* |
235 |
* |
220 |
* context-param |
236 |
* <pre>{@code |
|
|
237 |
* // context-param |
221 |
* ctx.addParameter("name", "value"); |
238 |
* ctx.addParameter("name", "value"); |
222 |
* |
239 |
* |
223 |
* |
240 |
* |
224 |
* error-page |
241 |
* // error-page |
225 |
* ErrorPage ep = new ErrorPage(); |
242 |
* ErrorPage ep = new ErrorPage(); |
226 |
* ep.setErrorCode(500); |
243 |
* ep.setErrorCode(500); |
227 |
* ep.setLocation("/error.html"); |
244 |
* ep.setLocation("/error.html"); |
228 |
* ctx.addErrorPage(ep); |
245 |
* ctx.addErrorPage(ep); |
229 |
* |
246 |
* |
230 |
* ctx.addMimeMapping("ext", "type"); |
247 |
* ctx.addMimeMapping("ext", "type"); |
|
|
248 |
* }</pre> |
249 |
* |
231 |
* |
250 |
* |
|
|
251 |
* <p> |
232 |
* Note: If you reload the Context, all your configuration will be lost. If |
252 |
* Note: If you reload the Context, all your configuration will be lost. If |
233 |
* you need reload support, consider using a LifecycleListener to provide |
253 |
* you need reload support, consider using a LifecycleListener to provide |
234 |
* your configuration. |
254 |
* your configuration. |
235 |
* |
255 |
* |
|
|
256 |
* <p> |
236 |
* TODO: add the rest |
257 |
* TODO: add the rest |
237 |
* |
258 |
* |
238 |
* @param contextPath The context mapping to use, "" for root context. |
259 |
* @param contextPath The context mapping to use, "" for root context. |
Lines 247-260
Link Here
|
247 |
/** |
268 |
/** |
248 |
* Equivalent to <servlet><servlet-name><servlet-class>. |
269 |
* Equivalent to <servlet><servlet-name><servlet-class>. |
249 |
* |
270 |
* |
|
|
271 |
* <p> |
250 |
* In general it is better/faster to use the method that takes a |
272 |
* In general it is better/faster to use the method that takes a |
251 |
* Servlet as param - this one can be used if the servlet is not |
273 |
* Servlet as param - this one can be used if the servlet is not |
252 |
* commonly used, and want to avoid loading all deps. |
274 |
* commonly used, and want to avoid loading all deps. |
253 |
* ( for example: jsp servlet ) |
275 |
* ( for example: jsp servlet ) |
254 |
* |
276 |
* |
255 |
* You can customize the returned servlet, ex: |
277 |
* You can customize the returned servlet, ex: |
256 |
* |
278 |
* <pre> |
257 |
* wrapper.addInitParameter("name", "value"); |
279 |
* wrapper.addInitParameter("name", "value"); |
|
|
280 |
* </pre> |
258 |
* |
281 |
* |
259 |
* @param contextPath Context to add Servlet to |
282 |
* @param contextPath Context to add Servlet to |
260 |
* @param servletName Servlet name (used in mappings) |
283 |
* @param servletName Servlet name (used in mappings) |
Lines 399-404
Link Here
|
399 |
* Get the default http connector. You can set more |
422 |
* Get the default http connector. You can set more |
400 |
* parameters - the port is already initialized. |
423 |
* parameters - the port is already initialized. |
401 |
* |
424 |
* |
|
|
425 |
* <p> |
402 |
* Alternatively, you can construct a Connector and set any params, |
426 |
* Alternatively, you can construct a Connector and set any params, |
403 |
* then call addConnector(Connector) |
427 |
* then call addConnector(Connector) |
404 |
* |
428 |
* |
Lines 933-938
Link Here
|
933 |
/** |
957 |
/** |
934 |
* Fix startup sequence - required if you don't use web.xml. |
958 |
* Fix startup sequence - required if you don't use web.xml. |
935 |
* |
959 |
* |
|
|
960 |
* <p> |
936 |
* The start() method in context will set 'configured' to false - and |
961 |
* The start() method in context will set 'configured' to false - and |
937 |
* expects a listener to set it back to true. |
962 |
* expects a listener to set it back to true. |
938 |
*/ |
963 |
*/ |