Lines 47-52
Link Here
|
47 |
import org.apache.catalina.connector.Response; |
47 |
import org.apache.catalina.connector.Response; |
48 |
import org.apache.catalina.util.URLEncoder; |
48 |
import org.apache.catalina.util.URLEncoder; |
49 |
import org.apache.catalina.valves.ValveBase; |
49 |
import org.apache.catalina.valves.ValveBase; |
|
|
50 |
import org.apache.juli.logging.LogFactory; |
50 |
import org.apache.tomcat.util.buf.CharChunk; |
51 |
import org.apache.tomcat.util.buf.CharChunk; |
51 |
import org.apache.tomcat.util.buf.MessageBytes; |
52 |
import org.apache.tomcat.util.buf.MessageBytes; |
52 |
import org.apache.tomcat.util.buf.UriUtil; |
53 |
import org.apache.tomcat.util.buf.UriUtil; |
Lines 143-149
Link Here
|
143 |
this.enabled = enabled; |
144 |
this.enabled = enabled; |
144 |
} |
145 |
} |
145 |
|
146 |
|
|
|
147 |
|
146 |
@Override |
148 |
@Override |
|
|
149 |
protected void initInternal() throws LifecycleException { |
150 |
super.initInternal(); |
151 |
containerLog = LogFactory.getLog(getContainer().getLogName() + ".rewrite"); |
152 |
} |
153 |
|
154 |
|
155 |
@Override |
147 |
protected synchronized void startInternal() throws LifecycleException { |
156 |
protected synchronized void startInternal() throws LifecycleException { |
148 |
|
157 |
|
149 |
super.startInternal(); |
158 |
super.startInternal(); |
Lines 155-165
Link Here
|
155 |
context = true; |
164 |
context = true; |
156 |
is = ((Context) getContainer()).getServletContext() |
165 |
is = ((Context) getContainer()).getServletContext() |
157 |
.getResourceAsStream("/WEB-INF/" + resourcePath); |
166 |
.getResourceAsStream("/WEB-INF/" + resourcePath); |
158 |
if (container.getLogger().isDebugEnabled()) { |
167 |
if (containerLog.isDebugEnabled()) { |
159 |
if (is == null) { |
168 |
if (is == null) { |
160 |
container.getLogger().debug("No configuration resource found: /WEB-INF/" + resourcePath); |
169 |
containerLog.debug("No configuration resource found: /WEB-INF/" + resourcePath); |
161 |
} else { |
170 |
} else { |
162 |
container.getLogger().debug("Read configuration from: /WEB-INF/" + resourcePath); |
171 |
containerLog.debug("Read configuration from: /WEB-INF/" + resourcePath); |
163 |
} |
172 |
} |
164 |
} |
173 |
} |
165 |
} else if (getContainer() instanceof Host) { |
174 |
} else if (getContainer() instanceof Host) { |
Lines 170-190
Link Here
|
170 |
// Use getResource and getResourceAsStream |
179 |
// Use getResource and getResourceAsStream |
171 |
is = getClass().getClassLoader() |
180 |
is = getClass().getClassLoader() |
172 |
.getResourceAsStream(resourceName); |
181 |
.getResourceAsStream(resourceName); |
173 |
if (is != null && container.getLogger().isDebugEnabled()) { |
182 |
if (is != null && containerLog.isDebugEnabled()) { |
174 |
container.getLogger().debug("Read configuration from CL at " + resourceName); |
183 |
containerLog.debug("Read configuration from CL at " + resourceName); |
175 |
} |
184 |
} |
176 |
} else { |
185 |
} else { |
177 |
if (container.getLogger().isDebugEnabled()) { |
186 |
if (containerLog.isDebugEnabled()) { |
178 |
container.getLogger().debug("Read configuration from " + file.getAbsolutePath()); |
187 |
containerLog.debug("Read configuration from " + file.getAbsolutePath()); |
179 |
} |
188 |
} |
180 |
is = new FileInputStream(file); |
189 |
is = new FileInputStream(file); |
181 |
} |
190 |
} |
182 |
if ((is == null) && (container.getLogger().isDebugEnabled())) { |
191 |
if ((is == null) && (containerLog.isDebugEnabled())) { |
183 |
container.getLogger().debug("No configuration resource found: " + resourceName + |
192 |
containerLog.debug("No configuration resource found: " + resourceName + |
184 |
" in " + getConfigBase() + " or in the classloader"); |
193 |
" in " + getConfigBase() + " or in the classloader"); |
185 |
} |
194 |
} |
186 |
} catch (Exception e) { |
195 |
} catch (Exception e) { |
187 |
container.getLogger().error("Error opening configuration", e); |
196 |
containerLog.error("Error opening configuration", e); |
188 |
} |
197 |
} |
189 |
} |
198 |
} |
190 |
|
199 |
|
Lines 197-208
Link Here
|
197 |
BufferedReader reader = new BufferedReader(isr)) { |
206 |
BufferedReader reader = new BufferedReader(isr)) { |
198 |
parse(reader); |
207 |
parse(reader); |
199 |
} catch (IOException ioe) { |
208 |
} catch (IOException ioe) { |
200 |
container.getLogger().error("Error closing configuration", ioe); |
209 |
containerLog.error("Error closing configuration", ioe); |
201 |
} finally { |
210 |
} finally { |
202 |
try { |
211 |
try { |
203 |
is.close(); |
212 |
is.close(); |
204 |
} catch (IOException e) { |
213 |
} catch (IOException e) { |
205 |
container.getLogger().error("Error closing configuration", e); |
214 |
containerLog.error("Error closing configuration", e); |
206 |
} |
215 |
} |
207 |
} |
216 |
} |
208 |
|
217 |
|
Lines 238-245
Link Here
|
238 |
Object result = parse(line); |
247 |
Object result = parse(line); |
239 |
if (result instanceof RewriteRule) { |
248 |
if (result instanceof RewriteRule) { |
240 |
RewriteRule rule = (RewriteRule) result; |
249 |
RewriteRule rule = (RewriteRule) result; |
241 |
if (container.getLogger().isDebugEnabled()) { |
250 |
if (containerLog.isDebugEnabled()) { |
242 |
container.getLogger().debug("Add rule with pattern " + rule.getPatternString() |
251 |
containerLog.debug("Add rule with pattern " + rule.getPatternString() |
243 |
+ " and substitution " + rule.getSubstitutionString()); |
252 |
+ " and substitution " + rule.getSubstitutionString()); |
244 |
} |
253 |
} |
245 |
for (int i = (conditions.size() - 1); i > 0; i--) { |
254 |
for (int i = (conditions.size() - 1); i > 0; i--) { |
Lines 248-256
Link Here
|
248 |
} |
257 |
} |
249 |
} |
258 |
} |
250 |
for (int i = 0; i < conditions.size(); i++) { |
259 |
for (int i = 0; i < conditions.size(); i++) { |
251 |
if (container.getLogger().isDebugEnabled()) { |
260 |
if (containerLog.isDebugEnabled()) { |
252 |
RewriteCond cond = conditions.get(i); |
261 |
RewriteCond cond = conditions.get(i); |
253 |
container.getLogger().debug("Add condition " + cond.getCondPattern() |
262 |
containerLog.debug("Add condition " + cond.getCondPattern() |
254 |
+ " test " + cond.getTestString() + " to rule with pattern " |
263 |
+ " test " + cond.getTestString() + " to rule with pattern " |
255 |
+ rule.getPatternString() + " and substitution " |
264 |
+ rule.getPatternString() + " and substitution " |
256 |
+ rule.getSubstitutionString() + (cond.isOrnext() ? " [OR]" : "") |
265 |
+ rule.getSubstitutionString() + (cond.isOrnext() ? " [OR]" : "") |
Lines 271-277
Link Here
|
271 |
} |
280 |
} |
272 |
} |
281 |
} |
273 |
} catch (IOException e) { |
282 |
} catch (IOException e) { |
274 |
container.getLogger().error("Error reading configuration", e); |
283 |
containerLog.error("Error reading configuration", e); |
275 |
} |
284 |
} |
276 |
} |
285 |
} |
277 |
this.rules = rules.toArray(new RewriteRule[0]); |
286 |
this.rules = rules.toArray(new RewriteRule[0]); |
Lines 338-345
Link Here
|
338 |
CharSequence test = (rule.isHost()) ? host : urlDecoded; |
347 |
CharSequence test = (rule.isHost()) ? host : urlDecoded; |
339 |
CharSequence newtest = rule.evaluate(test, resolver); |
348 |
CharSequence newtest = rule.evaluate(test, resolver); |
340 |
if (newtest != null && !test.equals(newtest.toString())) { |
349 |
if (newtest != null && !test.equals(newtest.toString())) { |
341 |
if (container.getLogger().isDebugEnabled()) { |
350 |
if (containerLog.isDebugEnabled()) { |
342 |
container.getLogger().debug("Rewrote " + test + " as " + newtest |
351 |
containerLog.debug("Rewrote " + test + " as " + newtest |
343 |
+ " with rule pattern " + rule.getPatternString()); |
352 |
+ " with rule pattern " + rule.getPatternString()); |
344 |
} |
353 |
} |
345 |
if (rule.isHost()) { |
354 |
if (rule.isHost()) { |