From ea6fc0541f78baed9575477c0152da11297caa33 Mon Sep 17 00:00:00 2001
From: Paul Tuckey In total there " +
- (rules.size() == 1 ? "is 1 rule" : "are " + rules.size() + " rules") + ", " +
- (outboundRules.size() == 1 ? "1 outbound rule" : outboundRules.size() + " outbound rules") +
- (conditionsCount > 0 ? " and " : "") +
- (conditionsCount == 1 ? conditionsCount + " condition" : "") +
- (conditionsCount > 1 ? conditionsCount + " conditions" : "") +
- " in the configuration file. " + StringUtils.nl2br(normalRule.getNote()) + " URL's matching This rule and it's conditions will use the Note, other rules will be processed after this rule. " + StringUtils.nl2br(rule.getNote()) + " Outbound URL's matching Note, other outbound rules will be processed after this rule. Conf");
- if (conf == null ) println(" empty.Request Debug Info
");
-
- println("General
");
- println("");
-
- println("method: " + hsRequest.getMethod());
- if (hsRequest.getAuthType() != null) println("auth-type: " + hsRequest.getAuthType());
- if (hsRequest.getCharacterEncoding() != null)
- println("character-encoding: " + hsRequest.getCharacterEncoding());
- println("context-path: " + hsRequest.getContextPath());
- if (hsRequest.getPathInfo() != null) println("path-info: " + hsRequest.getPathInfo());
- if (hsRequest.getPathTranslated() != null) println("path-translated: " + hsRequest.getPathTranslated());
- println("port: " + hsRequest.getServerPort());
- println("protocol: " + hsRequest.getProtocol());
- if (hsRequest.getQueryString() != null) println("query-string: " + hsRequest.getQueryString());
- println("remote-addr: " + hsRequest.getRemoteAddr());
- println("remote-host: " + hsRequest.getRemoteHost());
- if (hsRequest.getRemoteUser() != null) println("remote-user: " + hsRequest.getRemoteUser());
- if (hsRequest.getRequestedSessionId() != null)
- println("requested-session-id: " + hsRequest.getRequestedSessionId());
- println("request-uri: " + hsRequest.getRequestURI());
- println("request-url: " + hsRequest.getRequestURL());
- println("server-name: " + hsRequest.getServerName());
- println("scheme: " + hsRequest.getScheme());
-
- println("
");
-
- HttpSession session = hsRequest.getSession(false);
- if (session != null) {
- println("Session
");
- println("
session-isnew: " + session.isNew());
- Enumeration enumer = session.getAttributeNames();
- while (enumer.hasMoreElements()) {
- String name = (String) enumer.nextElement();
- println("
session-attribute " + name + ": " + session.getAttribute(name));
- }
- }
-
- // show headers from request
- println("Request Headers
");
- println("");
- final Enumeration headers = hsRequest.getHeaderNames();
- while (headers.hasMoreElements()) {
- final String headerName = (String) headers.nextElement();
- // ignore cookies as they are handled later
- if ("cookie".equals(headerName)) continue;
- println(headerName + ": " + hsRequest.getHeader(headerName));
- }
- println("
");
-
- final Cookie[] cookies = hsRequest.getCookies();
- if (cookies != null && cookies.length > 0) {
- println("Cookies
");
- for (int i = 0; i < cookies.length; i++) {
- println("Cookie " + i + "
");
- final Cookie cookie = cookies[i];
- if (cookie == null) continue;
- println("");
- println(" name : " + cookie.getName());
- println(" value : " + cookie.getValue());
- println(" path : " + cookie.getPath());
- println(" domain : " + cookie.getDomain());
- println(" max age : " + cookie.getMaxAge());
- println(" is secure: " + cookie.getSecure());
- println(" version : " + cookie.getVersion());
- println(" comment : " + cookie.getComment());
- println("
");
- }
- }
-
- // show headers from request
- println("Time info
");
- println("");
- Calendar nowCal = Calendar.getInstance();
- println("time: " + nowCal.getTime().getTime());
- println("year: " + nowCal.get(Calendar.YEAR));
- println("month: " + nowCal.get(Calendar.MONTH));
- println("dayofmonth: " + nowCal.get(Calendar.DAY_OF_MONTH));
- println("dayofweek: " + nowCal.get(Calendar.DAY_OF_WEEK));
- println("ampm: " + nowCal.get(Calendar.AM_PM));
- println("hourofday: " + nowCal.get(Calendar.HOUR_OF_DAY));
- println("minute: " + nowCal.get(Calendar.MINUTE));
- println("second: " + nowCal.get(Calendar.SECOND));
- println("millisecond: " + nowCal.get(Calendar.MILLISECOND));
- println("
");
-
- }
-
- private void showConf() {
- if (conf == null) return;
-
- println("Summary");
- if (conf.isLoadedFromFile()) println(" of " + conf.getFileName());
- println("
");
-
- if (!conf.isOk()) {
- final List errors = conf.getErrors();
- println("Errors During Load of " + conf.getFileName() + "
");
- println("");
- if (errors.size() > 0) {
- for (int i = 0; i < errors.size(); i++) {
- final String error = (String) errors.get(i);
- println("
");
- }
-
- int conditionsCount = 0;
- final List rules = conf.getRules();
- for (int i = 0; i < rules.size(); i++) {
- final Rule rule = (Rule) rules.get(i);
- if (rule instanceof NormalRule) {
- conditionsCount += ((NormalRule) rule).getConditions().size();
- }
- }
- final List outboundRules = conf.getOutboundRules();
- for (int i = 0; i < outboundRules.size(); i++) {
- final OutboundRule rule = (OutboundRule) outboundRules.get(i);
- conditionsCount += rule.getConditions().size();
- }
- println("
");
- }
-
- private void showRules(List rules) {
- for (int i = 0; i < rules.size(); i++) {
- final Rule rule = (Rule) rules.get(i);
- if (rule instanceof NormalRule) {
- NormalRule normalRule = (NormalRule) rule;
- println("" + normalRule.getDisplayName() +
- (normalRule.isEnabled() ? "" : " **DISABLED**") + "
");
- if (!StringUtils.isBlank(normalRule.getNote())) {
- println("
");
- }
-
- print("" + normalRule.getFrom() + "
");
- if (normalRule.isFilter()) {
- print(" (filter)");
- }
- if (!StringUtils.isBlank(normalRule.getTo())) {
- print(" will ");
- if ("forward".equals(normalRule.getToType()))
- print("be forwarded
to");
- else if ("include".equals(normalRule.getToType()))
- print("include
");
- else if ("redirect".equals(normalRule.getToType()))
- print("be redirected
to");
- else
- print("" + normalRule.getToType() + "
to");
- print(" " + normalRule.getTo() + "
");
- }
- println("." + normalRule.getMatchType() + "
matching engine." + classRule.getDisplayName() +
- (classRule.isEnabled() ? "" : " **DISABLED**") + "
");
- }
- println();
- println();
- }
- }
-
- private void showOutboundRules(List outboundRules) {
- for (int i = 0; i < outboundRules.size(); i++) {
- final OutboundRule rule = (OutboundRule) outboundRules.get(i);
- println("" + rule.getDisplayName() +
- (rule.isEnabled() ? "" : " **DISABLED**") + "
");
- if (!StringUtils.isBlank(rule.getNote())) {
- println("
");
- }
- print("" + rule.getFrom() + "
");
- if (!StringUtils.isBlank(rule.getTo())) {
- print(" will be rewritten to " + rule.getTo() + "
");
- }
- if (!rule.isEncodeFirst()) {
- print(", after response.encodeURL()
has been called");
- }
- if (!rule.isEncodeToUrl()) {
- print(", response.encodeURL()
will not be called");
- }
- println(".UrlRewriteFilter " +
- UrlRewriteFilter.getFullVersionString() + " configuration overview " +
- "(generated " + s.format(new Date()) + ")
");
- println("
");
- }
-
- private void showRunningInfo() {
- println("Running Status
");
- if (conf == null) {
- println("ERROR: UrlRewriteFilter failed to load config, check server log
");
- } else if (!conf.isOk()) {
- println("ERROR: UrlRewriteFilter NOT ACTIVE
");
- }
- println("" + conf.getFileName() + "
");
- if (conf != null ) println("loaded " + conf.getLoadedDate() + ".
Conf file reload check enabled, last modified will be checked every " + - urlRewriteFilter.getConfReloadCheckInterval() + "s, last checked " + - urlRewriteFilter.getConfReloadLastCheck() + ", next check at " + - nextReloadCheckDate + " in " + - Math.round((nextReloadCheckDate.getTime() - System.currentTimeMillis()) / 1000d) + "s."); - } else { - println("Conf file reload check disabled"); - } - println("
Status path " + urlRewriteFilter.getStatusPath() + "
.
This rule will set:
" + - "" + setAttribute.getName() + "
HTTP response header " +
- "to " + setAttribute.getValue() + "
");
-
- } else if ("request".equals(setAttribute.getType()) ||
- "session".equals(setAttribute.getType())) {
- println("An attribute on the " + setAttribute.getType() + "
object " +
- "called " + setAttribute.getName() + "
" +
- "to the value " +
- "" + setAttribute.getValue() + "
");
- } else if ("cookie".equals(setAttribute.getType())) {
- println("A cookie " +
- "called " + setAttribute.getName() + "
" +
- " to the value " +
- "" + setAttribute.getValue() + "
");
- } else if ("locale".equals(setAttribute.getType())) {
- println("locale to " +
- "" + setAttribute.getValue() + "
");
- } else if ("status".equals(setAttribute.getType())) {
- println("status to " +
- "" + setAttribute.getValue() + "
");
- } else if ("content-type".equals(setAttribute.getType())) {
- println("content-type to " +
- "" + setAttribute.getValue() + "
");
- } else if ("charset".equals(setAttribute.getType())) {
- println("charset to " +
- "" + setAttribute.getValue() + "
");
- }
- println("This rule will run:
" + - "" + run.getMethodSignature() + "
on an instance " +
- "of " + "" + run.getClassStr() + "
");
- if (run.isNewEachTime()) {
- println(" (a new instance will be created for each rule match)");
- }
- println("init(ServletConfig)
or destroy()
is found on the above " +
- "object" + (runs.size() > 1 ? "s" : "") + " they will be run at when creating or destroying an instance.");
- }
-
- private void showConditions(RuleBase rule) {
- List conditions = rule.getConditions();
- if (conditions.size() == 0) return;
-
- println("Given that the following condition" + - (conditions.size() == 1 ? " is" : "s are") + " met.
" + - "" + condition.getName() + "
HTTP header " +
- ("notequal".equals(condition.getOperator()) ? "does NOT match" : "matches") + " the value " +
- "" + condition.getValue() + "
");
- } else {
- println("" + condition.getType() + "
" +
- (condition.getName() == null ? "" : "" + condition.getName() + "
") +
- "is " +
- ("greater".equals(condition.getOperator()) ? "greater than" : "") +
- ("less".equals(condition.getOperator()) ? "less than" : "") +
- ("equal".equals(condition.getOperator()) ? "equal to" : "") +
- ("notequal".equals(condition.getOperator()) ? "NOT equal to" : "") +
- ("greaterorequal".equals(condition.getOperator()) ? "is greater than or equal to" : "") +
- ("lessorequal".equals(condition.getOperator()) ? "is less than or equal to" : "") +
- "
the value " +
- (StringUtils.isBlank(condition.getValue()) ? condition.getName() : condition.getValue()) + "
");
- }
- if (j < conditions.size() - 1) {
- println("" + condition.getNext() + "
");
- }
- println(""); + + println("method: " + hsRequest.getMethod()); + if (hsRequest.getAuthType() != null) println("auth-type: " + hsRequest.getAuthType()); + if (hsRequest.getCharacterEncoding() != null) + println("character-encoding: " + hsRequest.getCharacterEncoding()); + println("context-path: " + hsRequest.getContextPath()); + if (hsRequest.getPathInfo() != null) println("path-info: " + hsRequest.getPathInfo()); + if (hsRequest.getPathTranslated() != null) println("path-translated: " + hsRequest.getPathTranslated()); + println("port: " + hsRequest.getServerPort()); + println("protocol: " + hsRequest.getProtocol()); + if (hsRequest.getQueryString() != null) println("query-string: " + hsRequest.getQueryString()); + println("remote-addr: " + hsRequest.getRemoteAddr()); + println("remote-host: " + hsRequest.getRemoteHost()); + if (hsRequest.getRemoteUser() != null) println("remote-user: " + hsRequest.getRemoteUser()); + if (hsRequest.getRequestedSessionId() != null) + println("requested-session-id: " + hsRequest.getRequestedSessionId()); + println("request-uri: " + hsRequest.getRequestURI()); + println("request-url: " + hsRequest.getRequestURL()); + println("server-name: " + hsRequest.getServerName()); + println("scheme: " + hsRequest.getScheme()); + + println(""); + + HttpSession session = hsRequest.getSession(false); + if (session != null) { + println("
"); + final Enumeration headers = hsRequest.getHeaderNames(); + while (headers.hasMoreElements()) { + final String headerName = (String) headers.nextElement(); + // ignore cookies as they are handled later + if ("cookie".equals(headerName)) continue; + println(headerName + ": " + hsRequest.getHeader(headerName)); + } + println(""); + + final Cookie[] cookies = hsRequest.getCookies(); + if (cookies != null && cookies.length > 0) { + println("
"); + println(" name : " + cookie.getName()); + println(" value : " + cookie.getValue()); + println(" path : " + cookie.getPath()); + println(" domain : " + cookie.getDomain()); + println(" max age : " + cookie.getMaxAge()); + println(" is secure: " + cookie.getSecure()); + println(" version : " + cookie.getVersion()); + println(" comment : " + cookie.getComment()); + println(""); + } + } + + // show headers from request + println("
"); + Calendar nowCal = Calendar.getInstance(); + println("time: " + nowCal.getTime().getTime()); + println("year: " + nowCal.get(Calendar.YEAR)); + println("month: " + nowCal.get(Calendar.MONTH)); + println("dayofmonth: " + nowCal.get(Calendar.DAY_OF_MONTH)); + println("dayofweek: " + nowCal.get(Calendar.DAY_OF_WEEK)); + println("ampm: " + nowCal.get(Calendar.AM_PM)); + println("hourofday: " + nowCal.get(Calendar.HOUR_OF_DAY)); + println("minute: " + nowCal.get(Calendar.MINUTE)); + println("second: " + nowCal.get(Calendar.SECOND)); + println("millisecond: " + nowCal.get(Calendar.MILLISECOND)); + println(""); + + } + + private void showConf() { + if (conf == null) return; + + println("
In total there " + + (rules.size() == 1 ? "is 1 rule" : "are " + rules.size() + " rules") + ", " + + (outboundRules.size() == 1 ? "1 outbound rule" : outboundRules.size() + " outbound rules") + + (conditionsCount > 0 ? " and " : "") + + (conditionsCount == 1 ? conditionsCount + " condition" : "") + + (conditionsCount > 1 ? conditionsCount + " conditions" : "") + + " in the configuration file.
"); + + showRules(rules); + showOutboundRules(outboundRules); + println("" + StringUtils.nl2br(normalRule.getNote()) + "
URL's matching " + normalRule.getFrom() + "
");
+ if (normalRule.isFilter()) {
+ print(" (filter)");
+ }
+ if (!StringUtils.isBlank(normalRule.getTo())) {
+ print(" will ");
+ if ("forward".equals(normalRule.getToType()))
+ print("be forwarded
to");
+ else if ("include".equals(normalRule.getToType()))
+ print("include
");
+ else if ("redirect".equals(normalRule.getToType()))
+ print("be redirected
to");
+ else
+ print("" + normalRule.getToType() + "
to");
+ print(" " + normalRule.getTo() + "
");
+ }
+ println(".
This rule and it's conditions will use the " + normalRule.getMatchType() + "
matching engine.
Note, other rules will be processed after this rule.
"); + } + } + if (rule instanceof ClassRule) { + ClassRule classRule = (ClassRule) rule; + println("" + StringUtils.nl2br(rule.getNote()) + "
Outbound URL's matching " + rule.getFrom() + "
");
+ if (!StringUtils.isBlank(rule.getTo())) {
+ print(" will be rewritten to " + rule.getTo() + "
");
+ }
+ if (!rule.isEncodeFirst()) {
+ print(", after response.encodeURL()
has been called");
+ }
+ if (!rule.isEncodeToUrl()) {
+ print(", response.encodeURL()
will not be called");
+ }
+ println(".
Note, other outbound rules will be processed after this rule.
"); + } + println(); + println(); + } + } + + private void showHeader() { + SimpleDateFormat s = new SimpleDateFormat(); + println(""); + println(""); + println(""); + if ( conf == null ) { + println("Conf"); + if (conf == null ) println(" empty.
"); + if (conf != null && conf.isLoadedFromFile()) println("file" + conf.getFileName() + "
");
+ if (conf != null ) println("loaded " + conf.getLoadedDate() + ".");
+ if (urlRewriteFilter != null) {
+ if (urlRewriteFilter.isConfReloadCheckEnabled()) {
+ Date nextReloadCheckDate = new Date(urlRewriteFilter.getConfReloadLastCheck().getTime() +
+ (urlRewriteFilter.getConfReloadCheckInterval() * 1000L));
+ println("Conf file reload check enabled, last modified will be checked every " + + urlRewriteFilter.getConfReloadCheckInterval() + "s, last checked " + + urlRewriteFilter.getConfReloadLastCheck() + ", next check at " + + nextReloadCheckDate + " in " + + Math.round((nextReloadCheckDate.getTime() - System.currentTimeMillis()) / 1000d) + "s."); + } else { + println("Conf file reload check disabled"); + } + println("
Status path " + urlRewriteFilter.getStatusPath() + "
.
This rule will set:
" + + "" + setAttribute.getName() + "
HTTP response header " +
+ "to " + setAttribute.getValue() + "
");
+
+ } else if ("request".equals(setAttribute.getType()) ||
+ "session".equals(setAttribute.getType())) {
+ println("An attribute on the " + setAttribute.getType() + "
object " +
+ "called " + setAttribute.getName() + "
" +
+ "to the value " +
+ "" + setAttribute.getValue() + "
");
+ } else if ("cookie".equals(setAttribute.getType())) {
+ println("A cookie " +
+ "called " + setAttribute.getName() + "
" +
+ " to the value " +
+ "" + setAttribute.getValue() + "
");
+ } else if ("locale".equals(setAttribute.getType())) {
+ println("locale to " +
+ "" + setAttribute.getValue() + "
");
+ } else if ("status".equals(setAttribute.getType())) {
+ println("status to " +
+ "" + setAttribute.getValue() + "
");
+ } else if ("content-type".equals(setAttribute.getType())) {
+ println("content-type to " +
+ "" + setAttribute.getValue() + "
");
+ } else if ("charset".equals(setAttribute.getType())) {
+ println("charset to " +
+ "" + setAttribute.getValue() + "
");
+ }
+ println("This rule will run:
" + + "" + run.getMethodSignature() + "
on an instance " +
+ "of " + "" + run.getClassStr() + "
");
+ if (run.isNewEachTime()) {
+ println(" (a new instance will be created for each rule match)");
+ }
+ println("init(ServletConfig)
or destroy()
is found on the above " +
+ "object" + (runs.size() > 1 ? "s" : "") + " they will be run at when creating or destroying an instance.");
+ }
+
+ private void showConditions(RuleBase rule) {
+ List conditions = rule.getConditions();
+ if (conditions.size() == 0) return;
+
+ println("Given that the following condition" + + (conditions.size() == 1 ? " is" : "s are") + " met.
" + + "" + condition.getName() + "
HTTP header " +
+ ("notequal".equals(condition.getOperator()) ? "does NOT match" : "matches") + " the value " +
+ "" + condition.getValue() + "
");
+ } else {
+ println("" + condition.getType() + "
" +
+ (condition.getName() == null ? "" : "" + condition.getName() + "
") +
+ "is " +
+ ("greater".equals(condition.getOperator()) ? "greater than" : "") +
+ ("less".equals(condition.getOperator()) ? "less than" : "") +
+ ("equal".equals(condition.getOperator()) ? "equal to" : "") +
+ ("notequal".equals(condition.getOperator()) ? "NOT equal to" : "") +
+ ("greaterorequal".equals(condition.getOperator()) ? "is greater than or equal to" : "") +
+ ("lessorequal".equals(condition.getOperator()) ? "is less than or equal to" : "") +
+ "
the value " +
+ (StringUtils.isBlank(condition.getValue()) ? condition.getName() : condition.getValue()) + "
");
+ }
+ if (j < conditions.size() - 1) {
+ println("" + condition.getNext() + "
");
+ }
+ println("Detects include request URL if called within a RequestDispatcher include. - */ - public String getPathWithinApplication(HttpServletRequest request) { - String requestUri = request.getRequestURI(); - if (requestUri == null) requestUri = ""; - String decodedRequestUri = decodeRequestString(request, requestUri); - String contextPath = getContextPath(request); - String path; - if (StringUtils.startsWithIgnoreCase(decodedRequestUri, contextPath) && !conf.isUseContext()) { - // Normal case: URI contains context path. - path = decodedRequestUri.substring(contextPath.length()); - - } else if (!StringUtils.startsWithIgnoreCase(decodedRequestUri, contextPath) && conf.isUseContext()) { - // add the context path on - path = contextPath + decodedRequestUri; - - } else { - path = decodedRequestUri; - } - return StringUtils.isBlank(path) ? "/" : path; - } - - /** - * Return the context path for the given request, detecting an include request - * URL if called within a RequestDispatcher include. - *
As the value returned by request.getContextPath()
is not
- * decoded by the servlet container, this method will decode it.
- */
- public String getContextPath(HttpServletRequest request) {
- String contextPath = request.getContextPath();
- if ("/".equals(contextPath)) {
- // Invalid case, but happens for includes on Jetty: silently adapt it.
- contextPath = "";
- }
- return decodeRequestString(request, contextPath);
- }
-
- /**
- * Decode the string with a URLDecoder. The encoding will be taken
- * from the request, falling back to the default for your platform ("ISO-8859-1" on windows).
- */
- public String decodeRequestString(HttpServletRequest request, String source) {
- if (conf.isDecodeUsingEncodingHeader()) {
- String enc = request.getCharacterEncoding();
- if (enc != null) {
- try {
- return URLDecoder.decodeURL(source, enc);
- } catch (URISyntaxException ex) {
- if (log.isWarnEnabled()) {
- log.warn("Could not decode: " + source + " (header encoding: '" + enc + "'); exception: " + ex.getMessage());
- }
- }
- }
- }
- if (conf.isDecodeUsingCustomCharsetRequired()) {
- String enc = conf.getDecodeUsing();
- if (enc != null) {
- try {
- return URLDecoder.decodeURL(source, enc);
- } catch (URISyntaxException ex) {
- if (log.isWarnEnabled()) {
- log.warn("Could not decode: " + source + " (encoding: '" + enc + "') using default encoding; exception: " + ex.getMessage());
- }
- }
- }
- }
- return source;
- }
-
-
- private RuleChain getNewChain(final HttpServletRequest hsRequest, FilterChain parentChain) {
-
- String originalUrl = getPathWithinApplication(hsRequest);
-
- if (originalUrl == null) {
- // for some reason the engine is not giving us the url
- // this isn't good
- log.debug("unable to fetch request uri from request. This shouldn't happen, it may indicate that " +
- "the web application server has a bug or that the request was not pased correctly.");
- return null;
- }
-
- if (log.isDebugEnabled()) {
- log.debug("processing request for " + originalUrl);
- }
-
- // add the query string on uri (note, some web app containers do this)
- if (originalUrl != null && originalUrl.indexOf("?") == -1 && conf.isUseQueryString()) {
- String query = hsRequest.getQueryString();
- if (query != null) {
- query = query.trim();
- if (query.length() > 0) {
- originalUrl = originalUrl + "?" + query;
- log.debug("query string added");
- }
- }
- }
-
- if (!conf.isOk()) {
- // when conf cannot be loaded for some sort of error
- // continue as normal without looking at the non-existent rules
- log.debug("configuration is not ok. not rewriting request.");
- return null;
- }
-
- final List rules = conf.getRules();
- if (rules.size() == 0) {
- // no rules defined
- log.debug("there are no rules setup. not rewriting request.");
- return null;
- }
-
- return new RuleChain(this, originalUrl, parentChain);
- }
-
-
- /**
- * Handle an exception thrown by a Run element.
- */
- public RewrittenUrl handleInvocationTargetException(final HttpServletRequest hsRequest,
- final HttpServletResponse hsResponse, InvocationTargetException e)
- throws ServletException, IOException {
-
- Throwable originalThrowable = getOriginalException(e);
-
- if (log.isDebugEnabled()) {
- log.debug("attampting to find catch for exception " + originalThrowable.getClass().getName());
- }
-
- List catchElems = conf.getCatchElems();
- for (int i = 0; i < catchElems.size(); i++) {
- CatchElem catchElem = (CatchElem) catchElems.get(i);
- if (!catchElem.matches(originalThrowable)) continue;
- try {
- return catchElem.execute(hsRequest, hsResponse, originalThrowable);
-
- } catch (InvocationTargetException invocationExceptionInner) {
- originalThrowable = getOriginalException(invocationExceptionInner);
- log.warn("had exception processing catch, trying the rest of the catches with " +
- originalThrowable.getClass().getName());
- }
- }
-
- if (log.isDebugEnabled()) {
- log.debug("exception unhandled", e);
- }
- if (originalThrowable instanceof Error) throw (Error) originalThrowable;
- if (originalThrowable instanceof RuntimeException) throw (RuntimeException) originalThrowable;
- if (originalThrowable instanceof ServletException) throw (ServletException) originalThrowable;
- if (originalThrowable instanceof IOException) throw (IOException) originalThrowable;
- throw new ServletException(originalThrowable);
- }
-
- /**
- * Get the original exception that caused the InvocationTargetException.
- *
- * @param e the InvocationTargetException
- * @return the original exception.
- * @throws javax.servlet.ServletException If the exception is a servlet exception, it will be thrown.
- */
- private Throwable getOriginalException(InvocationTargetException e) throws ServletException {
- Throwable originalThrowable = e.getTargetException();
- if (originalThrowable == null) {
- originalThrowable = e.getCause();
- if (originalThrowable == null) {
- throw new ServletException(e);
- }
- }
- // unwrap if exception is a ServletException
- if (originalThrowable instanceof ServletException) {
- ServletException se = (ServletException) originalThrowable;
- // go 5 deep to see if we can get a real exception
- for (int i = 0; i < 5 && se.getCause() instanceof ServletException; i++) {
- se = (ServletException) se.getCause();
- }
- if (se.getCause() instanceof InvocationTargetException) {
- return getOriginalException((InvocationTargetException) se.getCause());
- } else {
- throw se;
- }
- }
- return originalThrowable;
- }
-
-
- public Conf getConf() {
- return conf;
- }
-
-
- /**
- * Handles rewriting urls in jsp's etc, i.e. response.encodeURL() is overriden in the response wrapper.
- *
- * @param hsResponse response
- * @param hsRequest request
- * @param encodeUrlHasBeenRun if encodeUrl has already been run on the originalOutboundUrl speficy this to be true
- * @param outboundUrl url
- * @return RewrittenOutboundUrl
- * @see UrlRewriteWrappedResponse
- */
- protected RewrittenOutboundUrl processEncodeURL(HttpServletResponse hsResponse, HttpServletRequest hsRequest,
- boolean encodeUrlHasBeenRun, String outboundUrl) {
-
- if (log.isDebugEnabled()) {
- log.debug("processing outbound url for " + outboundUrl);
- }
-
- if (outboundUrl == null) {
- // this probably means encode called with no url
- return new RewrittenOutboundUrl(null, true);
- }
-
- // attempt to match the rules
- boolean finalEncodeOutboundUrl = true;
- String finalToUrl = outboundUrl;
- final List outboundRules = conf.getOutboundRules();
- try {
- for (int i = 0; i < outboundRules.size(); i++) {
- final OutboundRule outboundRule = (OutboundRule) outboundRules.get(i);
- if (!encodeUrlHasBeenRun && outboundRule.isEncodeFirst()) {
- continue;
- }
- if (encodeUrlHasBeenRun && !outboundRule.isEncodeFirst()) {
- continue;
- }
- final RewrittenOutboundUrl rewrittenUrl = outboundRule.execute(finalToUrl, hsRequest, hsResponse);
- if (rewrittenUrl != null) {
- // means this rule has matched
- if (log.isDebugEnabled()) {
- log.debug("\"" + outboundRule.getDisplayName() + "\" matched");
- }
- finalToUrl = rewrittenUrl.getTarget();
- finalEncodeOutboundUrl = rewrittenUrl.isEncode();
- if (outboundRule.isLast()) {
- log.debug("rule is last");
- // there can be no more matches on this request
- break;
- }
- }
- }
- } catch (InvocationTargetException e) {
- try {
- handleInvocationTargetException(hsRequest, hsResponse, e);
- } catch (ServletException e1) {
- log.error(e1);
- } catch (IOException e1) {
- log.error(e1);
- }
- }
-
- return new RewrittenOutboundUrl(finalToUrl, finalEncodeOutboundUrl);
- }
-
- /**
- * Destory the rewriter gracefully.
- */
- public void destroy() {
- conf.destroy();
- }
-
-}
-
-
-
+/**
+ * Copyright (c) 2005-2023, Paul Tuckey
+ * All rights reserved.
+ * ====================================================================
+ * Licensed under the BSD License. Text as follows.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite;
+
+import org.tuckey.web.filters.urlrewrite.utils.Log;
+import org.tuckey.web.filters.urlrewrite.utils.StringUtils;
+import org.tuckey.web.filters.urlrewrite.utils.URLDecoder;
+
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URISyntaxException;
+import java.util.List;
+
+/**
+ * The main rewriter.
+ *
+ * @author Paul Tuckey
+ * @version $Revision: 52 $ $Date: 2007-02-26 07:00:28 +1300 (Mon, 26 Feb 2007) $
+ */
+public class UrlRewriter {
+
+ private static Log log = Log.getLog(UrlRewriter.class);
+
+ /**
+ * The conf for this filter.
+ */
+ private Conf conf;
+
+ public UrlRewriter(Conf conf) {
+ this.conf = conf;
+ }
+
+ /**
+ * Helpful for testing but otherwise, don't use.
+ */
+ public RewrittenUrl processRequest(final HttpServletRequest hsRequest,
+ final HttpServletResponse hsResponse)
+ throws IOException, ServletException, InvocationTargetException {
+ RuleChain chain = getNewChain(hsRequest, null);
+ if (chain == null) return null;
+ chain.process(hsRequest, hsResponse);
+ return chain.getFinalRewrittenRequest();
+ }
+
+ /**
+ * The main method called for each request that this filter is mapped for.
+ *
+ * @param hsRequest The request to process.
+ * @return returns true when response has been handled by url rewriter false when it hasn't.
+ */
+ public boolean processRequest(final HttpServletRequest hsRequest, final HttpServletResponse hsResponse,
+ FilterChain parentChain)
+ throws IOException, ServletException {
+ RuleChain chain = getNewChain(hsRequest, parentChain);
+ if (chain == null) return false;
+ chain.doRules(hsRequest, hsResponse);
+ return chain.isResponseHandled();
+ }
+
+
+ /**
+ * Return the path within the web application for the given request.
+ *
Detects include request URL if called within a RequestDispatcher include. + */ + public String getPathWithinApplication(HttpServletRequest request) { + String requestUri = request.getRequestURI(); + if (requestUri == null) requestUri = ""; + String decodedRequestUri = decodeRequestString(request, requestUri); + String contextPath = getContextPath(request); + String path; + if (StringUtils.startsWithIgnoreCase(decodedRequestUri, contextPath) && !conf.isUseContext()) { + // Normal case: URI contains context path. + path = decodedRequestUri.substring(contextPath.length()); + + } else if (!StringUtils.startsWithIgnoreCase(decodedRequestUri, contextPath) && conf.isUseContext()) { + // add the context path on + path = contextPath + decodedRequestUri; + + } else { + path = decodedRequestUri; + } + return StringUtils.isBlank(path) ? "/" : path; + } + + /** + * Return the context path for the given request, detecting an include request + * URL if called within a RequestDispatcher include. + *
As the value returned by request.getContextPath()
is not
+ * decoded by the servlet container, this method will decode it.
+ */
+ public String getContextPath(HttpServletRequest request) {
+ String contextPath = request.getContextPath();
+ if ("/".equals(contextPath)) {
+ // Invalid case, but happens for includes on Jetty: silently adapt it.
+ contextPath = "";
+ }
+ return decodeRequestString(request, contextPath);
+ }
+
+ /**
+ * Decode the string with a URLDecoder. The encoding will be taken
+ * from the request, falling back to the default for your platform ("ISO-8859-1" on windows).
+ */
+ public String decodeRequestString(HttpServletRequest request, String source) {
+ if (conf.isDecodeUsingEncodingHeader()) {
+ String enc = request.getCharacterEncoding();
+ if (enc != null) {
+ try {
+ return URLDecoder.decodeURL(source, enc);
+ } catch (URISyntaxException ex) {
+ if (log.isWarnEnabled()) {
+ log.warn("Could not decode: " + source + " (header encoding: '" + enc + "'); exception: " + ex.getMessage());
+ }
+ }
+ }
+ }
+ if (conf.isDecodeUsingCustomCharsetRequired()) {
+ String enc = conf.getDecodeUsing();
+ if (enc != null) {
+ try {
+ return URLDecoder.decodeURL(source, enc);
+ } catch (URISyntaxException ex) {
+ if (log.isWarnEnabled()) {
+ log.warn("Could not decode: " + source + " (encoding: '" + enc + "') using default encoding; exception: " + ex.getMessage());
+ }
+ }
+ }
+ }
+ return source;
+ }
+
+
+ private RuleChain getNewChain(final HttpServletRequest hsRequest, FilterChain parentChain) {
+
+ String originalUrl = getPathWithinApplication(hsRequest);
+
+ if (originalUrl == null) {
+ // for some reason the engine is not giving us the url
+ // this isn't good
+ log.debug("unable to fetch request uri from request. This shouldn't happen, it may indicate that " +
+ "the web application server has a bug or that the request was not pased correctly.");
+ return null;
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("processing request for " + originalUrl);
+ }
+
+ // add the query string on uri (note, some web app containers do this)
+ if (originalUrl != null && originalUrl.indexOf("?") == -1 && conf.isUseQueryString()) {
+ String query = hsRequest.getQueryString();
+ if (query != null) {
+ query = query.trim();
+ if (query.length() > 0) {
+ originalUrl = originalUrl + "?" + query;
+ log.debug("query string added");
+ }
+ }
+ }
+
+ if (!conf.isOk()) {
+ // when conf cannot be loaded for some sort of error
+ // continue as normal without looking at the non-existent rules
+ log.debug("configuration is not ok. not rewriting request.");
+ return null;
+ }
+
+ final List rules = conf.getRules();
+ if (rules.size() == 0) {
+ // no rules defined
+ log.debug("there are no rules setup. not rewriting request.");
+ return null;
+ }
+
+ return new RuleChain(this, originalUrl, parentChain);
+ }
+
+
+ /**
+ * Handle an exception thrown by a Run element.
+ */
+ public RewrittenUrl handleInvocationTargetException(final HttpServletRequest hsRequest,
+ final HttpServletResponse hsResponse, InvocationTargetException e)
+ throws ServletException, IOException {
+
+ Throwable originalThrowable = getOriginalException(e);
+
+ if (log.isDebugEnabled()) {
+ log.debug("attampting to find catch for exception " + originalThrowable.getClass().getName());
+ }
+
+ List catchElems = conf.getCatchElems();
+ for (int i = 0; i < catchElems.size(); i++) {
+ CatchElem catchElem = (CatchElem) catchElems.get(i);
+ if (!catchElem.matches(originalThrowable)) continue;
+ try {
+ return catchElem.execute(hsRequest, hsResponse, originalThrowable);
+
+ } catch (InvocationTargetException invocationExceptionInner) {
+ originalThrowable = getOriginalException(invocationExceptionInner);
+ log.warn("had exception processing catch, trying the rest of the catches with " +
+ originalThrowable.getClass().getName());
+ }
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("exception unhandled", e);
+ }
+ if (originalThrowable instanceof Error) throw (Error) originalThrowable;
+ if (originalThrowable instanceof RuntimeException) throw (RuntimeException) originalThrowable;
+ if (originalThrowable instanceof ServletException) throw (ServletException) originalThrowable;
+ if (originalThrowable instanceof IOException) throw (IOException) originalThrowable;
+ throw new ServletException(originalThrowable);
+ }
+
+ /**
+ * Get the original exception that caused the InvocationTargetException.
+ *
+ * @param e the InvocationTargetException
+ * @return the original exception.
+ * @throws javax.servlet.ServletException If the exception is a servlet exception, it will be thrown.
+ */
+ private Throwable getOriginalException(InvocationTargetException e) throws ServletException {
+ Throwable originalThrowable = e.getTargetException();
+ if (originalThrowable == null) {
+ originalThrowable = e.getCause();
+ if (originalThrowable == null) {
+ throw new ServletException(e);
+ }
+ }
+ // unwrap if exception is a ServletException
+ if (originalThrowable instanceof ServletException) {
+ ServletException se = (ServletException) originalThrowable;
+ // go 5 deep to see if we can get a real exception
+ for (int i = 0; i < 5 && se.getCause() instanceof ServletException; i++) {
+ se = (ServletException) se.getCause();
+ }
+ if (se.getCause() instanceof InvocationTargetException) {
+ return getOriginalException((InvocationTargetException) se.getCause());
+ } else {
+ throw se;
+ }
+ }
+ return originalThrowable;
+ }
+
+
+ public Conf getConf() {
+ return conf;
+ }
+
+
+ /**
+ * Handles rewriting urls in jsp's etc, i.e. response.encodeURL() is overriden in the response wrapper.
+ *
+ * @param hsResponse response
+ * @param hsRequest request
+ * @param encodeUrlHasBeenRun if encodeUrl has already been run on the originalOutboundUrl speficy this to be true
+ * @param outboundUrl url
+ * @return RewrittenOutboundUrl
+ * @see UrlRewriteWrappedResponse
+ */
+ protected RewrittenOutboundUrl processEncodeURL(HttpServletResponse hsResponse, HttpServletRequest hsRequest,
+ boolean encodeUrlHasBeenRun, String outboundUrl) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("processing outbound url for " + outboundUrl);
+ }
+
+ if (outboundUrl == null) {
+ // this probably means encode called with no url
+ return new RewrittenOutboundUrl(null, true);
+ }
+
+ // attempt to match the rules
+ boolean finalEncodeOutboundUrl = true;
+ String finalToUrl = outboundUrl;
+ final List outboundRules = conf.getOutboundRules();
+ try {
+ for (int i = 0; i < outboundRules.size(); i++) {
+ final OutboundRule outboundRule = (OutboundRule) outboundRules.get(i);
+ if (!encodeUrlHasBeenRun && outboundRule.isEncodeFirst()) {
+ continue;
+ }
+ if (encodeUrlHasBeenRun && !outboundRule.isEncodeFirst()) {
+ continue;
+ }
+ final RewrittenOutboundUrl rewrittenUrl = outboundRule.execute(finalToUrl, hsRequest, hsResponse);
+ if (rewrittenUrl != null) {
+ // means this rule has matched
+ if (log.isDebugEnabled()) {
+ log.debug("\"" + outboundRule.getDisplayName() + "\" matched");
+ }
+ finalToUrl = rewrittenUrl.getTarget();
+ finalEncodeOutboundUrl = rewrittenUrl.isEncode();
+ if (outboundRule.isLast()) {
+ log.debug("rule is last");
+ // there can be no more matches on this request
+ break;
+ }
+ }
+ }
+ } catch (InvocationTargetException e) {
+ try {
+ handleInvocationTargetException(hsRequest, hsResponse, e);
+ } catch (ServletException e1) {
+ log.error(e1);
+ } catch (IOException e1) {
+ log.error(e1);
+ }
+ }
+
+ return new RewrittenOutboundUrl(finalToUrl, finalEncodeOutboundUrl);
+ }
+
+ /**
+ * Destory the rewriter gracefully.
+ */
+ public void destroy() {
+ conf.destroy();
+ }
+
+}
+
+
+
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteMatch.java b/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteMatch.java
index 94946a1f..211b0aa5 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteMatch.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteMatch.java
@@ -1,74 +1,74 @@
-/**
- * Copyright (c) 2005-2007, Paul Tuckey
- * All rights reserved.
- * ====================================================================
- * Licensed under the BSD License. Text as follows.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * - Neither the name tuckey.org nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- */
-package org.tuckey.web.filters.urlrewrite.extend;
-
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-import jakarta.servlet.ServletException;
-import java.io.IOException;
-
-/**
- * Service the request with a clean object.
- * Perform any business logic data retrival etc then prepare an object for presentation of the data.
- */
-public class RewriteMatch {
-
- /**
- * When future rules are processed they need to have a URL to compare against. If this method is not implemented
- * then the url before this rule will be used. If isLast() returns true then this will never be called.
- * @return String
- */
- public String getMatchingUrl() {
- return null;
- }
-
- /**
- * If this rule has been matched and has not been "stolen" by another rule then process the request.
- *
- * If you return true then the filter chain will NOT continue.
- *
- * @return boolean true if the request was rewritten, false if not.
- */
- public boolean execute(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- // do nothing by default
- return true;
- }
-
-}
-
-
-
-
+/**
+ * Copyright (c) 2005-2023, Paul Tuckey
+ * All rights reserved.
+ * ====================================================================
+ * Licensed under the BSD License. Text as follows.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite.extend;
+
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.servlet.ServletException;
+import java.io.IOException;
+
+/**
+ * Service the request with a clean object.
+ * Perform any business logic data retrival etc then prepare an object for presentation of the data.
+ */
+public class RewriteMatch {
+
+ /**
+ * When future rules are processed they need to have a URL to compare against. If this method is not implemented
+ * then the url before this rule will be used. If isLast() returns true then this will never be called.
+ * @return String
+ */
+ public String getMatchingUrl() {
+ return null;
+ }
+
+ /**
+ * If this rule has been matched and has not been "stolen" by another rule then process the request.
+ *
+ * If you return true then the filter chain will NOT continue.
+ *
+ * @return boolean true if the request was rewritten, false if not.
+ */
+ public boolean execute(HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException {
+ // do nothing by default
+ return true;
+ }
+
+}
+
+
+
+
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteRule.java b/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteRule.java
index b4a0a02a..ee0a0142 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteRule.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteRule.java
@@ -1,74 +1,74 @@
-/**
- * Copyright (c) 2005-2007, Paul Tuckey
- * All rights reserved.
- * ====================================================================
- * Licensed under the BSD License. Text as follows.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * - Neither the name tuckey.org nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- */
-package org.tuckey.web.filters.urlrewrite.extend;
-
-import jakarta.servlet.ServletContext;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-
-/**
- * A RewriteRule is basically the class that will figure out the answer to "Can we service this http request?". If we
- * can we return a match object that will actually service the request.
- */
-public class RewriteRule {
-
- /**
- * Initialise the rule.
- * If you return false here the rule will be marked as disabled.
- */
- public boolean initialise(ServletContext servletContext) {
- // by default do nothing
- return true;
- }
-
- /**
- * Prepare to be shut down. There will be no more calls to "matches" after this is called.
- */
- public void destroy() {
- // by default do nothing
- }
-
- /**
- * Can we match the current request? null means no. Return a valid RuleMatch object or
- * new SimpleRewriteMatch() (or an object that extends RewriteMatch) if this rule matches.
- *
- * @param request
- * @param response
- */
- public RewriteMatch matches(HttpServletRequest request, HttpServletResponse response) {
- return null;
- }
-
-}
+/**
+ * Copyright (c) 2005-2023, Paul Tuckey
+ * All rights reserved.
+ * ====================================================================
+ * Licensed under the BSD License. Text as follows.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite.extend;
+
+import jakarta.servlet.ServletContext;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+
+/**
+ * A RewriteRule is basically the class that will figure out the answer to "Can we service this http request?". If we
+ * can we return a match object that will actually service the request.
+ */
+public class RewriteRule {
+
+ /**
+ * Initialise the rule.
+ * If you return false here the rule will be marked as disabled.
+ */
+ public boolean initialise(ServletContext servletContext) {
+ // by default do nothing
+ return true;
+ }
+
+ /**
+ * Prepare to be shut down. There will be no more calls to "matches" after this is called.
+ */
+ public void destroy() {
+ // by default do nothing
+ }
+
+ /**
+ * Can we match the current request? null means no. Return a valid RuleMatch object or
+ * new SimpleRewriteMatch() (or an object that extends RewriteMatch) if this rule matches.
+ *
+ * @param request
+ * @param response
+ */
+ public RewriteMatch matches(HttpServletRequest request, HttpServletResponse response) {
+ return null;
+ }
+
+}
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/functions/CssVarFunction.java b/src/main/java/org/tuckey/web/filters/urlrewrite/functions/CssVarFunction.java
index db9120ba..8734e506 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/functions/CssVarFunction.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/functions/CssVarFunction.java
@@ -1,103 +1,137 @@
-package org.tuckey.web.filters.urlrewrite.functions;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-
-/**
- * todo: turn into a css vars filter plugin
- * Quick and dirty limited implementation of css Variables in Java
- *
+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + *
+ * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewrite.functions; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + + +/** + * todo: turn into a css vars filter plugin + * Quick and dirty limited implementation of css Variables in Java + *
+ * http://disruptive-innovations.com/zoo/cssvariables/ + * http://trac.webkit.org/browser/trunk/LayoutTests/fast/css/variables + */ +public class CssVarFunction { + + /* + + set variables, these bay be overriden by request attributes + +@variables { + gadgetBodyLinkColor: #c0c0c0; +} + +h1 { + border-color: var(gadgetBodyLinkColor); +} + + */ + + + static Pattern VARIABLE_SET_PATTERN = Pattern.compile("\\s*([a-zA-Z0-9-]+)\\s*\\:(.*);"); + static Pattern VARIABLE_REF_PATTERN = Pattern.compile("var\\(([a-zA-Z0-9-]+)\\)"); + static Pattern VARIABLES_BLOCK_START_PATTERN = Pattern.compile("@variables"); + + public static void parse(InputStream cssFile, Map variables, OutputStream os) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(cssFile)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os)); + Map defaultVariables = new HashMap(); + + if (variables == null) variables = new HashMap(); + String line; + boolean readingVars = false; + boolean emitNewLine = false; + while ((line = br.readLine()) != null) { + + if (emitNewLine && !readingVars) bw.newLine(); + emitNewLine = true; + + if (!readingVars && VARIABLES_BLOCK_START_PATTERN.matcher(line).find()) readingVars = true; + + if (readingVars) { + Matcher m = VARIABLE_SET_PATTERN.matcher(line); + while (m.find()) { + defaultVariables.put(m.group(1), m.group(2)); + } + } + if (!readingVars) { + Matcher m2 = VARIABLE_REF_PATTERN.matcher(line); + StringBuffer sb = new StringBuffer(); + while (m2.find()) { + String var = m2.group(1); + String varValue = (String) variables.get(var); + if (varValue == null) varValue = (String) defaultVariables.get(var); + if (varValue == null) varValue = ""; + m2.appendReplacement(sb, varValue); + } + m2.appendTail(sb); + line = sb.toString(); + + bw.write(line); + } + if (readingVars && line.matches("}")) { + readingVars = false; + emitNewLine = false; + } + } + bw.flush(); + } + + public static String parse(String css, Map variables) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ByteArrayInputStream bais = new ByteArrayInputStream(css.getBytes()); + try { + parse(bais, variables, baos); + } catch (IOException e) { + throw new RuntimeException(e); + } + return baos.toString(); + } + +} + diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/functions/StringFunctions.java b/src/main/java/org/tuckey/web/filters/urlrewrite/functions/StringFunctions.java index b4315feb..30d24f69 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/functions/StringFunctions.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/functions/StringFunctions.java @@ -1,166 +1,200 @@ -package org.tuckey.web.filters.urlrewrite.functions; - -import org.tuckey.web.filters.urlrewrite.substitution.SubstitutionContext; -import org.tuckey.web.filters.urlrewrite.substitution.SubstitutionFilterChain; -import org.tuckey.web.filters.urlrewrite.utils.Log; - -import java.io.UnsupportedEncodingException; -import java.net.URISyntaxException; -import java.net.URLDecoder; -import java.net.URLEncoder; -import java.nio.charset.Charset; -import java.util.regex.Pattern; - - -public class StringFunctions { - - private static Log log = Log.getLog(StringFunctions.class); - private static final Pattern FIND_COLON_PATTERN = Pattern.compile("(? + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + *+ * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewrite.functions; + +import org.tuckey.web.filters.urlrewrite.substitution.SubstitutionContext; +import org.tuckey.web.filters.urlrewrite.substitution.SubstitutionFilterChain; +import org.tuckey.web.filters.urlrewrite.utils.Log; + +import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.nio.charset.Charset; +import java.util.regex.Pattern; + + +public class StringFunctions { + + private static Log log = Log.getLog(StringFunctions.class); + private static final Pattern FIND_COLON_PATTERN = Pattern.compile("(? + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + *
+ * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewrite.sample; + +import org.tuckey.web.filters.urlrewrite.Conf; +import org.w3c.dom.Document; + +import java.io.InputStream; + + +public class SampleConfExt extends Conf { + + public SampleConfExt() { + // do something + } + + protected synchronized void loadDom(InputStream inputStream) { + // do something + super.loadDom(inputStream); + } + + protected void processConfDoc(Document doc) { + // do something else + super.processConfDoc(doc); + } +} diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleMultiUrlRewriteFilter.java b/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleMultiUrlRewriteFilter.java index c3b18bd7..c20b9aa3 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleMultiUrlRewriteFilter.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleMultiUrlRewriteFilter.java @@ -1,49 +1,83 @@ -package org.tuckey.web.filters.urlrewrite.sample; - -import org.tuckey.web.filters.urlrewrite.Conf; -import org.tuckey.web.filters.urlrewrite.UrlRewriteFilter; -import org.tuckey.web.filters.urlrewrite.UrlRewriter; - -import jakarta.servlet.FilterChain; -import jakarta.servlet.FilterConfig; -import jakarta.servlet.ServletException; -import jakarta.servlet.ServletRequest; -import jakarta.servlet.ServletResponse; -import java.io.FileInputStream; -import java.util.ArrayList; -import java.util.List; - -/** - * Sample of how you might load multiple configuration files. (NOT to be used verbatim!!) - */ -public class SampleMultiUrlRewriteFilter extends UrlRewriteFilter { - - private List urlrewriters = new ArrayList(); - - public void loadUrlRewriter(FilterConfig filterConfig) throws ServletException { - // add configurations - try { - Conf conf1 = new Conf(filterConfig.getServletContext(), new FileInputStream("someconf.xml"), "someconf.xml", ""); - urlrewriters.add(new UrlRewriter(conf1)); - - Conf conf2 = new SampleConfExt(); - urlrewriters.add(new UrlRewriter(conf2)); - - } catch (Exception e) { - throw new ServletException(e); - } - } - - public UrlRewriter getUrlRewriter(ServletRequest request, ServletResponse response, FilterChain chain) { - // do some logic to decide what urlrewriter to use (possibly do a reload check on the conf file) - return (UrlRewriter) urlrewriters.get(0); - } - - public void destroyUrlRewriter() { - for (int i = 0; i < urlrewriters.size(); i++) { - UrlRewriter urlRewriter = (UrlRewriter) urlrewriters.get(i); - urlRewriter.destroy(); - } - } - -} +/** + * Copyright (c) 2005-2023, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + *
+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + *
+ * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewrite.sample; + +import org.tuckey.web.filters.urlrewrite.Conf; +import org.tuckey.web.filters.urlrewrite.UrlRewriteFilter; +import org.tuckey.web.filters.urlrewrite.UrlRewriter; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import java.io.FileInputStream; +import java.util.ArrayList; +import java.util.List; + +/** + * Sample of how you might load multiple configuration files. (NOT to be used verbatim!!) + */ +public class SampleMultiUrlRewriteFilter extends UrlRewriteFilter { + + private List urlrewriters = new ArrayList(); + + public void loadUrlRewriter(FilterConfig filterConfig) throws ServletException { + // add configurations + try { + Conf conf1 = new Conf(filterConfig.getServletContext(), new FileInputStream("someconf.xml"), "someconf.xml", ""); + urlrewriters.add(new UrlRewriter(conf1)); + + Conf conf2 = new SampleConfExt(); + urlrewriters.add(new UrlRewriter(conf2)); + + } catch (Exception e) { + throw new ServletException(e); + } + } + + public UrlRewriter getUrlRewriter(ServletRequest request, ServletResponse response, FilterChain chain) { + // do some logic to decide what urlrewriter to use (possibly do a reload check on the conf file) + return (UrlRewriter) urlrewriters.get(0); + } + + public void destroyUrlRewriter() { + for (int i = 0; i < urlrewriters.size(); i++) { + UrlRewriter urlRewriter = (UrlRewriter) urlrewriters.get(i); + urlRewriter.destroy(); + } + } + +} diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteMatch.java b/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteMatch.java index 36a35ce1..7be22824 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteMatch.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteMatch.java @@ -1,73 +1,73 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite.sample; - -import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; - -import jakarta.servlet.RequestDispatcher; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import java.io.IOException; - - -/** - * A sample of how you might write a custom match. - */ -class SampleRewriteMatch extends RewriteMatch { - private int id; - - SampleRewriteMatch(int i) { - id = i; - } - - int getId() { - return id; - } - - public boolean execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - - // lookup things in the db based on id - - // do something like forward to a jsp - request.setAttribute("sampleRewriteMatch", this); - RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/jsp/some-view.jsp"); - rd.forward(request, response); - // in the jsp you can use request.getAttribute("sampleRewriteMatch") to fetch this object - - return true; - } - +/** + * Copyright (c) 2005-2023, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewrite.sample; + +import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; + + +/** + * A sample of how you might write a custom match. + */ +class SampleRewriteMatch extends RewriteMatch { + private int id; + + SampleRewriteMatch(int i) { + id = i; + } + + int getId() { + return id; + } + + public boolean execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // lookup things in the db based on id + + // do something like forward to a jsp + request.setAttribute("sampleRewriteMatch", this); + RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/jsp/some-view.jsp"); + rd.forward(request, response); + // in the jsp you can use request.getAttribute("sampleRewriteMatch") to fetch this object + + return true; + } + } \ No newline at end of file diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteRule.java b/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteRule.java index 49c6fad2..9de0a9d7 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteRule.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteRule.java @@ -1,68 +1,68 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite.sample; - -import org.tuckey.web.filters.urlrewrite.extend.RewriteRule; -import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -/** - * A sample of how you might write a custom rule. - */ -public class SampleRewriteRule extends RewriteRule { - - - public RewriteMatch matches(HttpServletRequest request, HttpServletResponse response) { - - // return null if we don't want the request - if (!request.getRequestURI().startsWith("/staff/")) return null; - - Integer id = null; - try { - // grab the things out of the url we need - id = Integer.valueOf(request.getRequestURI().replaceFirst( - "/staff/([0-9]+)/", "$1")); - } catch (NumberFormatException e) { - // if we don't get a good id then return null - return null; - } - - // match required with clean parameters - return new SampleRewriteMatch(id.intValue()); - } - -} +/** + * Copyright (c) 2005-2023, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewrite.sample; + +import org.tuckey.web.filters.urlrewrite.extend.RewriteRule; +import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/** + * A sample of how you might write a custom rule. + */ +public class SampleRewriteRule extends RewriteRule { + + + public RewriteMatch matches(HttpServletRequest request, HttpServletResponse response) { + + // return null if we don't want the request + if (!request.getRequestURI().startsWith("/staff/")) return null; + + Integer id = null; + try { + // grab the things out of the url we need + id = Integer.valueOf(request.getRequestURI().replaceFirst( + "/staff/([0-9]+)/", "$1")); + } catch (NumberFormatException e) { + // if we don't get a good id then return null + return null; + } + + // match required with clean parameters + return new SampleRewriteMatch(id.intValue()); + } + +} diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/BackReferenceReplacer.java b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/BackReferenceReplacer.java index 969f8c53..f875bf81 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/BackReferenceReplacer.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/BackReferenceReplacer.java @@ -1,135 +1,135 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite.substitution; - -import org.tuckey.web.filters.urlrewrite.ConditionMatch; -import org.tuckey.web.filters.urlrewrite.utils.Log; -import org.tuckey.web.filters.urlrewrite.utils.StringMatchingMatcher; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Back references (eg, %1, %2 etc) replacer. - * - * @author Paul Tuckey - * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $ - */ -public class BackReferenceReplacer implements SubstitutionFilter { - - private static Log log = Log.getLog(BackReferenceReplacer.class); - - private static Pattern backRefPattern = Pattern.compile("(? 0) { - - Matcher backRefMatcher = backRefPattern.matcher(subjectOfReplacement); - - StringBuffer sb = new StringBuffer(); - boolean anyMatches = false; - int lastAppendPosition = 0; - while (backRefMatcher.find()) { - anyMatches = true; - int groupCount = backRefMatcher.groupCount(); - if (groupCount < 1) { - log.error("group count on backref finder regex is not as expected"); - if (log.isDebugEnabled()) { - log.error("backRefMatcher: " + backRefMatcher.toString()); - } - continue; - } - String varStr = backRefMatcher.group(1); - - boolean validBackref = false; - int varInt = 0; - log.debug("found " + varStr); - // now grab this match from lastConditionMatchMatcher - try { - varInt = Integer.parseInt(varStr); - if (varInt > lastCondMatcherGroupCount) { - log.error("backref %" + varInt + " not found in conditon "); - if (log.isDebugEnabled()) { - log.debug("condition matcher: " + lastConditionMatchMatcher.toString()); - } - } else { - validBackref = true; - } - } catch (NumberFormatException nfe) { - log.error("could not parse backref " + varStr + " to number"); - } - String conditionMatch = ""; - if (validBackref) { - conditionMatch = lastConditionMatchMatcher.group(varInt); - } - String stringBeforeMatch = subjectOfReplacement.substring(lastAppendPosition, backRefMatcher.start()); - sb.append(nextFilter.substitute(stringBeforeMatch, ctx)); - sb.append(conditionMatch); - lastAppendPosition = backRefMatcher.end(); - } - if (anyMatches) { - String stringAfterMatch = subjectOfReplacement.substring(lastAppendPosition); - sb.append(nextFilter.substitute(stringAfterMatch, ctx)); - if (log.isDebugEnabled()) log.debug("replaced sb is " + sb); - return sb.toString(); - } - } - } - - return nextFilter.substitute(subjectOfReplacement, ctx); - } - - -} +/** + * Copyright (c) 2005-2023, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewrite.substitution; + +import org.tuckey.web.filters.urlrewrite.ConditionMatch; +import org.tuckey.web.filters.urlrewrite.utils.Log; +import org.tuckey.web.filters.urlrewrite.utils.StringMatchingMatcher; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Back references (eg, %1, %2 etc) replacer. + * + * @author Paul Tuckey + * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $ + */ +public class BackReferenceReplacer implements SubstitutionFilter { + + private static Log log = Log.getLog(BackReferenceReplacer.class); + + private static Pattern backRefPattern = Pattern.compile("(? 0) { + + Matcher backRefMatcher = backRefPattern.matcher(subjectOfReplacement); + + StringBuffer sb = new StringBuffer(); + boolean anyMatches = false; + int lastAppendPosition = 0; + while (backRefMatcher.find()) { + anyMatches = true; + int groupCount = backRefMatcher.groupCount(); + if (groupCount < 1) { + log.error("group count on backref finder regex is not as expected"); + if (log.isDebugEnabled()) { + log.error("backRefMatcher: " + backRefMatcher.toString()); + } + continue; + } + String varStr = backRefMatcher.group(1); + + boolean validBackref = false; + int varInt = 0; + log.debug("found " + varStr); + // now grab this match from lastConditionMatchMatcher + try { + varInt = Integer.parseInt(varStr); + if (varInt > lastCondMatcherGroupCount) { + log.error("backref %" + varInt + " not found in conditon "); + if (log.isDebugEnabled()) { + log.debug("condition matcher: " + lastConditionMatchMatcher.toString()); + } + } else { + validBackref = true; + } + } catch (NumberFormatException nfe) { + log.error("could not parse backref " + varStr + " to number"); + } + String conditionMatch = ""; + if (validBackref) { + conditionMatch = lastConditionMatchMatcher.group(varInt); + } + String stringBeforeMatch = subjectOfReplacement.substring(lastAppendPosition, backRefMatcher.start()); + sb.append(nextFilter.substitute(stringBeforeMatch, ctx)); + sb.append(conditionMatch); + lastAppendPosition = backRefMatcher.end(); + } + if (anyMatches) { + String stringAfterMatch = subjectOfReplacement.substring(lastAppendPosition); + sb.append(nextFilter.substitute(stringAfterMatch, ctx)); + if (log.isDebugEnabled()) log.debug("replaced sb is " + sb); + return sb.toString(); + } + } + } + + return nextFilter.substitute(subjectOfReplacement, ctx); + } + + +} diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/ChainedSubstitutionFilters.java b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/ChainedSubstitutionFilters.java index a48085a3..7bf5b02f 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/ChainedSubstitutionFilters.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/ChainedSubstitutionFilters.java @@ -1,55 +1,89 @@ -package org.tuckey.web.filters.urlrewrite.substitution; - -import jakarta.servlet.ServletContext; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - - -public class ChainedSubstitutionFilters implements SubstitutionFilterChain { - - private List filters; - private int nextFilter = 0; - - public ChainedSubstitutionFilters(List filters) { - this.filters = filters; - } - - public String substitute(String string, SubstitutionContext ctx){ - if(nextFilter >= filters.size()) - return string; - String ret = ((SubstitutionFilter)filters.get(nextFilter++)).substitute(string, ctx, this); - nextFilter--; - return ret; - } - - public static String substitute(String string, SubstitutionFilter singleFilter){ - ArrayList list = new ArrayList(1); - list.add(singleFilter); - SubstitutionFilterChain filterChain = new ChainedSubstitutionFilters(list); - return filterChain.substitute(string, null); - } - - public static SubstitutionFilterChain getDefaultSubstitutionChain( - boolean withPattern, boolean withFunction, boolean withVariable, - boolean withBackReference) { - return getDefaultSubstitutionChain(withPattern, withFunction, withVariable, withBackReference, null); - } - - public static SubstitutionFilterChain getDefaultSubstitutionChain(boolean withPattern, boolean withFunction, boolean withVariable, boolean withBackReference, ServletContext sc){ - List substitutionFilters = new LinkedList(); - - if(withPattern) - substitutionFilters.add(new PatternReplacer()); - if(withFunction) - substitutionFilters.add(new FunctionReplacer()); - if(withVariable) - substitutionFilters.add(sc == null ? new VariableReplacer() : new VariableReplacer(sc)); - if(withBackReference) - substitutionFilters.add(new BackReferenceReplacer()); - substitutionFilters.add(new MatcherReplacer()); - substitutionFilters.add(new UnescapeReplacer()); - - return new ChainedSubstitutionFilters(substitutionFilters); - } -} +/** + * Copyright (c) 2005-2023, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + *
+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + *
+ * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewrite.substitution; + +import jakarta.servlet.ServletContext; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + + +public class ChainedSubstitutionFilters implements SubstitutionFilterChain { + + private List filters; + private int nextFilter = 0; + + public ChainedSubstitutionFilters(List filters) { + this.filters = filters; + } + + public String substitute(String string, SubstitutionContext ctx){ + if(nextFilter >= filters.size()) + return string; + String ret = ((SubstitutionFilter)filters.get(nextFilter++)).substitute(string, ctx, this); + nextFilter--; + return ret; + } + + public static String substitute(String string, SubstitutionFilter singleFilter){ + ArrayList list = new ArrayList(1); + list.add(singleFilter); + SubstitutionFilterChain filterChain = new ChainedSubstitutionFilters(list); + return filterChain.substitute(string, null); + } + + public static SubstitutionFilterChain getDefaultSubstitutionChain( + boolean withPattern, boolean withFunction, boolean withVariable, + boolean withBackReference) { + return getDefaultSubstitutionChain(withPattern, withFunction, withVariable, withBackReference, null); + } + + public static SubstitutionFilterChain getDefaultSubstitutionChain(boolean withPattern, boolean withFunction, boolean withVariable, boolean withBackReference, ServletContext sc){ + List substitutionFilters = new LinkedList(); + + if(withPattern) + substitutionFilters.add(new PatternReplacer()); + if(withFunction) + substitutionFilters.add(new FunctionReplacer()); + if(withVariable) + substitutionFilters.add(sc == null ? new VariableReplacer() : new VariableReplacer(sc)); + if(withBackReference) + substitutionFilters.add(new BackReferenceReplacer()); + substitutionFilters.add(new MatcherReplacer()); + substitutionFilters.add(new UnescapeReplacer()); + + return new ChainedSubstitutionFilters(substitutionFilters); + } +} diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/FunctionReplacer.java b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/FunctionReplacer.java index 30b73556..3688af69 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/FunctionReplacer.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/FunctionReplacer.java @@ -1,158 +1,158 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite.substitution; - -import org.tuckey.web.filters.urlrewrite.functions.StringFunctions; -import org.tuckey.web.filters.urlrewrite.utils.Log; - -import java.util.Collections; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Helper class for function replacement. - * - * @author Paul Tuckey - * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $ - */ -public class FunctionReplacer implements SubstitutionFilter { - - private static Log log = Log.getLog(VariableReplacer.class); - - private static Pattern functionPattern = Pattern.compile("(? conditionMatcherGroupCount) { - log.error("backref %" + varInt + " not found in conditon "); - if (log.isDebugEnabled()) { - log.debug("condition matcher: " + conditionMatcher.toString()); - } - } else { - validBackref = true; - } - } catch (NumberFormatException nfe) { - log.error("could not parse backref " + varStr + " to number"); - } - String conditionMatch = null; - if (validBackref) { - conditionMatch = conditionMatcher.group(varInt); - } - String stringBeforeMatch = replacePattern.substring(lastAppendPosition, backRefMatcher.start()); - sb.append(nextFilter.substitute(stringBeforeMatch, ctx)); - if (conditionMatch != null) - sb.append(conditionMatch); - lastAppendPosition = backRefMatcher.end(); - } - if (anyMatches) { - String stringAfterMatch = replacePattern.substring(lastAppendPosition); - sb.append(nextFilter.substitute(stringAfterMatch, ctx)); - if (log.isDebugEnabled()) log.debug("replaced sb is " + sb); - return sb.toString(); - } - return nextFilter.substitute(replacePattern, ctx); - } - -} +/** + * Copyright (c) 2005-2023, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewrite.substitution; + +import org.tuckey.web.filters.urlrewrite.utils.Log; +import org.tuckey.web.filters.urlrewrite.utils.StringMatchingMatcher; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Back references (eg, $1, $2 etc) replacer. + * + * @author Paul Tuckey + * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $ + */ +public class MatcherReplacer implements SubstitutionFilter { + + private static Log log = Log.getLog(MatcherReplacer.class); + + private static Pattern backRefPattern = Pattern.compile("(? conditionMatcherGroupCount) { + log.error("backref %" + varInt + " not found in conditon "); + if (log.isDebugEnabled()) { + log.debug("condition matcher: " + conditionMatcher.toString()); + } + } else { + validBackref = true; + } + } catch (NumberFormatException nfe) { + log.error("could not parse backref " + varStr + " to number"); + } + String conditionMatch = null; + if (validBackref) { + conditionMatch = conditionMatcher.group(varInt); + } + String stringBeforeMatch = replacePattern.substring(lastAppendPosition, backRefMatcher.start()); + sb.append(nextFilter.substitute(stringBeforeMatch, ctx)); + if (conditionMatch != null) + sb.append(conditionMatch); + lastAppendPosition = backRefMatcher.end(); + } + if (anyMatches) { + String stringAfterMatch = replacePattern.substring(lastAppendPosition); + sb.append(nextFilter.substitute(stringAfterMatch, ctx)); + if (log.isDebugEnabled()) log.debug("replaced sb is " + sb); + return sb.toString(); + } + return nextFilter.substitute(replacePattern, ctx); + } + +} diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/PatternReplacer.java b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/PatternReplacer.java index aa383d06..e35a7f6d 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/PatternReplacer.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/PatternReplacer.java @@ -1,75 +1,75 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite.substitution; - -import org.tuckey.web.filters.urlrewrite.utils.StringMatchingMatcher; - -/** - * Replaces each match of the condition to the given substituted pattern - * - * @author Paul Tuckey - * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $ - */ -public class PatternReplacer implements SubstitutionFilter { - - public String substitute(String from, SubstitutionContext ctx, - SubstitutionFilterChain nextFilter) { - - StringMatchingMatcher conditionMatcher = ctx.getMatcher(); - conditionMatcher.reset(); - StringBuffer sb = new StringBuffer(); - int lastMatchEnd = 0; - while (conditionMatcher.find()) { - // we do not substitute on the non-matched string since it is straight from the URL - String notMatched = from.substring(lastMatchEnd, conditionMatcher.start()); - sb.append(notMatched); - // we will replace the matched string with the appropriately expanded pattern - String substitutedReplacement = nextFilter.substitute(ctx.getReplacePattern(), ctx); - sb.append(substitutedReplacement); - lastMatchEnd = conditionMatcher.end(); - // get out of there for wildcard patterns - if (!conditionMatcher.isMultipleMatchingSupported() || notMatched.isEmpty()) - break; - if (conditionMatcher.hitEnd()){ - break; - } - } - // put the remaining ending non-matched string - if (lastMatchEnd < from.length()) - sb.append(from.substring(lastMatchEnd)); - return sb.toString(); - } - -} +/** + * Copyright (c) 2005-2023, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewrite.substitution; + +import org.tuckey.web.filters.urlrewrite.utils.StringMatchingMatcher; + +/** + * Replaces each match of the condition to the given substituted pattern + * + * @author Paul Tuckey + * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $ + */ +public class PatternReplacer implements SubstitutionFilter { + + public String substitute(String from, SubstitutionContext ctx, + SubstitutionFilterChain nextFilter) { + + StringMatchingMatcher conditionMatcher = ctx.getMatcher(); + conditionMatcher.reset(); + StringBuffer sb = new StringBuffer(); + int lastMatchEnd = 0; + while (conditionMatcher.find()) { + // we do not substitute on the non-matched string since it is straight from the URL + String notMatched = from.substring(lastMatchEnd, conditionMatcher.start()); + sb.append(notMatched); + // we will replace the matched string with the appropriately expanded pattern + String substitutedReplacement = nextFilter.substitute(ctx.getReplacePattern(), ctx); + sb.append(substitutedReplacement); + lastMatchEnd = conditionMatcher.end(); + // get out of there for wildcard patterns + if (!conditionMatcher.isMultipleMatchingSupported() || notMatched.isEmpty()) + break; + if (conditionMatcher.hitEnd()){ + break; + } + } + // put the remaining ending non-matched string + if (lastMatchEnd < from.length()) + sb.append(from.substring(lastMatchEnd)); + return sb.toString(); + } + +} diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/SubstitutionContext.java b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/SubstitutionContext.java index 7d53e9d4..4f2be14c 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/SubstitutionContext.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/SubstitutionContext.java @@ -1,42 +1,76 @@ -package org.tuckey.web.filters.urlrewrite.substitution; - -import org.tuckey.web.filters.urlrewrite.ConditionMatch; -import org.tuckey.web.filters.urlrewrite.utils.StringMatchingMatcher; - -import jakarta.servlet.http.HttpServletRequest; - -public class SubstitutionContext { - - - private HttpServletRequest hsRequest; - private StringMatchingMatcher matcher; - private ConditionMatch lastConditionMatch; - private String replacePattern; - - public SubstitutionContext(HttpServletRequest hsRequest, - StringMatchingMatcher matcher, ConditionMatch lastConditionMatch, - String replacePattern) { - super(); - this.hsRequest = hsRequest; - this.matcher = matcher; - this.lastConditionMatch = lastConditionMatch; - this.replacePattern = replacePattern; - } - - public HttpServletRequest getHsRequest() { - return hsRequest; - } - - public StringMatchingMatcher getMatcher() { - return matcher; - } - - public ConditionMatch getLastConditionMatch() { - return lastConditionMatch; - } - - public String getReplacePattern() { - return replacePattern; - } - -} +/** + * Copyright (c) 2005-2023, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + *
+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + *
+ * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewrite.substitution; + +import org.tuckey.web.filters.urlrewrite.ConditionMatch; +import org.tuckey.web.filters.urlrewrite.utils.StringMatchingMatcher; + +import jakarta.servlet.http.HttpServletRequest; + +public class SubstitutionContext { + + + private HttpServletRequest hsRequest; + private StringMatchingMatcher matcher; + private ConditionMatch lastConditionMatch; + private String replacePattern; + + public SubstitutionContext(HttpServletRequest hsRequest, + StringMatchingMatcher matcher, ConditionMatch lastConditionMatch, + String replacePattern) { + super(); + this.hsRequest = hsRequest; + this.matcher = matcher; + this.lastConditionMatch = lastConditionMatch; + this.replacePattern = replacePattern; + } + + public HttpServletRequest getHsRequest() { + return hsRequest; + } + + public StringMatchingMatcher getMatcher() { + return matcher; + } + + public ConditionMatch getLastConditionMatch() { + return lastConditionMatch; + } + + public String getReplacePattern() { + return replacePattern; + } + +} diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/SubstitutionFilter.java b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/SubstitutionFilter.java index f5c5fc69..ec67d8c6 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/SubstitutionFilter.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/SubstitutionFilter.java @@ -1,5 +1,39 @@ -package org.tuckey.web.filters.urlrewrite.substitution; - -public interface SubstitutionFilter { - public String substitute(String string, SubstitutionContext ctx, SubstitutionFilterChain nextFilter); -} +/** + * Copyright (c) 2005-2023, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + *
+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + *
+ * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewrite.substitution; + +public interface SubstitutionFilter { + public String substitute(String string, SubstitutionContext ctx, SubstitutionFilterChain nextFilter); +} diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/SubstitutionFilterChain.java b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/SubstitutionFilterChain.java index 5b472247..f7d08691 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/SubstitutionFilterChain.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/SubstitutionFilterChain.java @@ -1,7 +1,41 @@ -package org.tuckey.web.filters.urlrewrite.substitution; - -public interface SubstitutionFilterChain { - - public String substitute(String string, SubstitutionContext ctx); - -} +/** + * Copyright (c) 2005-2023, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + *
+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + *
+ * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewrite.substitution; + +public interface SubstitutionFilterChain { + + public String substitute(String string, SubstitutionContext ctx); + +} diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/UnescapeReplacer.java b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/UnescapeReplacer.java index aa582bb1..45130ffa 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/UnescapeReplacer.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/UnescapeReplacer.java @@ -1,51 +1,51 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite.substitution; - -/** - * Removes escape sequences from the string (\) - * - * @author Paul Tuckey - * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $ - */ -public class UnescapeReplacer implements SubstitutionFilter { - - public String substitute(String from, SubstitutionContext ctx, - SubstitutionFilterChain nextFilter) { - String unescaped = from.replaceAll("(? 0) notesBuffer.append("\n"); - String noteLine = StringUtils.trim(line.substring(1)); - notesBuffer.append(noteLine); - - } else if (line.startsWith("RewriteBase")) { - log.info("RewriteBase not supported, ignored"); - - } else if (line.startsWith("RewriteCond")) { - Condition condition = processRewriteCond(line); - if (condition != null) conditionsBuffer.add(condition); - - } else if (line.startsWith("RewriteEngine")) { - processRewriteEngine(conf, line); - - } else if (line.startsWith("RewriteLock")) { - log.error("RewriteLock not supported, ignored"); - - } else if (line.startsWith("RewriteLogLevel")) { - logLevelStr = parseLogLevel(logLevelStr, line); - - } else if (line.startsWith("RewriteLog")) { - logTypeStr = parseLogType(logTypeStr, line); - - } else if (line.startsWith("RewriteMap")) { - log.error("RewriteMap not supported, ignored"); - - } else if (line.startsWith("RewriteOptions")) { - log.error("RewriteOptions not supported, ignored"); - - } else if (line.startsWith("RewriteRule")) { - parseRule(conf, conditionsBuffer, notesBuffer, line); - notesBuffer = new StringBuffer(); - conditionsBuffer = new ArrayList(); - } else { - log.error("Unknown line: " + line); - } - } - if (logTypeStr != null || logLevelStr != null) { - String logStr = (logTypeStr == null ? "" : logTypeStr) + (logLevelStr == null ? "" : ":" + logLevelStr); - log.debug("setting log to: " + logStr); - Log.setLevel(logStr); - } - if (conditionsBuffer.size() > 0) { - log.error("conditions left over without a rule"); - } - } - - private void parseRule(Conf conf, List conditionsBuffer, StringBuffer notesBuffer, String line) { - NormalRule rule = processRule(line); - for (int j = 0; j < conditionsBuffer.size(); j++) { - Condition condition = (Condition) conditionsBuffer.get(j); - rule.addCondition(condition); - } - if (notesBuffer.length() > 0) rule.setNote(notesBuffer.toString()); - conf.addRule(rule); - } - - private String parseLogType(String logTypeStr, String line) { - Matcher logTypeMatcher = LOG_TYPE_PATTERN.matcher(line); - if (logTypeMatcher.matches()) { - logTypeStr = StringUtils.trimToNull(logTypeMatcher.group(1)); - if (logTypeStr != null) { - logTypeStr = logTypeStr.replaceAll("\"", ""); - log.debug("RewriteLog parsed as " + logTypeStr); - } - } - return logTypeStr; - } - - private String parseLogLevel(String logLevelStr, String line) { - log.debug("found a RewriteLogLevel"); - Matcher logLevelMatcher = LOG_LEVEL_PATTERN.matcher(line); - if (logLevelMatcher.matches()) { - int logLevel = NumberUtils.stringToInt(logLevelMatcher.group(1)); - if (logLevel <= 1) logLevelStr = "FATAL"; - else if (logLevel == 2) logLevelStr = "ERROR"; - else if (logLevel == 3) logLevelStr = "INFO"; - else if (logLevel == 4) logLevelStr = "WARN"; - else if (logLevel >= 5) logLevelStr = "DEBUG"; - log.debug("RewriteLogLevel parsed as " + logLevel); - - } else { - log.error("cannot parse " + line); - } - return logLevelStr; - } - - private NormalRule processRule(String line) { - NormalRule rule = new NormalRule(); - Matcher ruleMatcher = RULE_PATTERN.matcher(line); - if (ruleMatcher.matches()) { - String rulePartStr = StringUtils.trimToNull(ruleMatcher.group(1)); - if (rulePartStr != null) { - log.debug("got rule " + rulePartStr); - String[] ruleParts = rulePartStr.split("\\s"); - int partCounter = 0; - for (int j = 0; j < ruleParts.length; j++) { - String part = StringUtils.trimToNull(ruleParts[j]); - if (part == null) continue; - partCounter++; - log.debug("parsed rule part " + part); - if (partCounter == 1) { - rule.setFrom(part); - } - if (partCounter == 2) { - if (!"-".equals(part)) { - Matcher matcher = TO_VARIABLE_PATTERN.matcher(part); - if (matcher.find()) { - String knownType = getType(matcher.group(0).toString()); - if (knownType != "") { - part = part.replace(matcher.group(0).toString(), "%{" + knownType + "}"); - } - } - } - rule.setTo(part); - } - if (part.startsWith("[") && part.endsWith("]")) { - processRuleFlags(rule, part); - } - } - } else { - log.error("could not parse rule from " + line); - } - } else { - log.error("cannot parse " + line); - } - return rule; - } - - private void processRewriteEngine(Conf conf, String line) { - boolean enabled = true; - Matcher engineMatcher = ENGINE_PATTERN.matcher(line); - if (engineMatcher.matches()) { - String enabledStr = StringUtils.trim(engineMatcher.group(1)); - log.debug("RewriteEngine value parsed as '" + enabledStr + "'"); - if ("0".equalsIgnoreCase(enabledStr) || - "false".equalsIgnoreCase(enabledStr) || - "no".equalsIgnoreCase(enabledStr) || - "off".equalsIgnoreCase(enabledStr)) enabled = false; - log.debug("RewriteEngine as boolean '" + enabled + "'"); - } else { - log.error("cannot parse " + line); - } - conf.setEngineEnabled(enabled); - } - - private void processRuleFlags(NormalRule rule, String part) { - String rawFlags = StringUtils.trimToNull(part.substring(1, part.length() - 1)); - if (rawFlags != null) { - String[] flags = rawFlags.split(","); - for (int k = 0; k < flags.length; k++) { - String flag = flags[k]; - String flagValue = null; - if (flag.indexOf("=") != -1) { - flagValue = flag.substring(flag.indexOf("=") + 1); - flag = flag.substring(0, flag.indexOf("=")); - } - flag = flag.toLowerCase(); - /* - # 'chain|C' (chained with next rule) - This flag chains the current rule with the next rule (which itself can be chained with the following rule, and so on). This has the following effect: if a rule matches, then processing continues as usual - the flag has no effect. If the rule does not match, then all following chained rules are skipped. For instance, it can be used to remove the ``.www'' part, inside a per-directory rule set, when you let an external redirect happen (where the ``.www'' part should not occur!). - */ - if ("chain".equalsIgnoreCase(flag) || "C".equalsIgnoreCase(flag)) { - log.info("chain flag [C] not supported"); - } - /* - # 'cookie|CO=NAME:VAL:domain[:lifetime[:path]]' (set cookie) - This sets a cookie in the client's browser. The cookie's name is specified by NAME and the value is VAL. The domain field is the domain of the cookie, such as '.apache.org', the optional lifetime is the lifetime of the cookie in minutes, and the optional path is the path of the cookie - */ - if ("cookie".equalsIgnoreCase(flag) || "CO".equalsIgnoreCase(flag)) { - SetAttribute set = new SetAttribute(); - set.setType("cookie"); - String cookieName = flagValue; - String cookieValue = null; - if (flagValue != null) { - int colon = flagValue.indexOf(":"); - if (colon != -1) { - cookieValue = flagValue.substring(colon + 1); - cookieName = flagValue.substring(0, colon); - } - } - set.setName(cookieName); - // NOTE: The colon separated domain, lifetime, path are - // handled by SetAttribute.setValue() - set.setValue(cookieValue); - rule.addSetAttribute(set); - } - /* - # 'env|E=VAR:VAL' (set environment variable) - This forces an environment variable named VAR to be set to the value VAL, where VAL can contain regexp backreferences ($N and %N) which will be expanded. You can use this flag more than once, to set more than one variable. The variables can later be dereferenced in many situations, most commonly from within XSSI (via ) or CGI ($ENV{'VAR'}). You can also dereference the variable in a later RewriteCond pattern, using %{ENV:VAR}. Use this to strip information from URLs, while maintaining a record of that information. - */ - if ("env".equalsIgnoreCase(flag) || "E".equalsIgnoreCase(flag)) { - log.info("env flag [E] not supported"); - } - /* - # 'forbidden|F' (force URL to be forbidden) - This forces the current URL to be forbidden - it immediately sends back a HTTP response of 403 (FORBIDDEN). Use this flag in conjunction with appropriate RewriteConds to conditionally block some URLs. - */ - if ("forbidden".equalsIgnoreCase(flag) || "F".equalsIgnoreCase(flag)) { - SetAttribute set = new SetAttribute(); - set.setType("status"); - set.setValue("403"); - rule.addSetAttribute(set); - } - /* - # 'gone|G' (force URL to be gone) - This forces the current URL to be gone - it immediately sends back a HTTP response of 410 (GONE). Use this flag to mark pages which no longer exist as gone. - */ - if ("gone".equalsIgnoreCase(flag) || "G".equalsIgnoreCase(flag)) { - SetAttribute set = new SetAttribute(); - set.setType("status"); - set.setValue("410"); - rule.addSetAttribute(set); - } - /* - # 'last|L' (last rule) - Stop the rewriting process here and don't apply any more rewrite rules. This corresponds to the Perl last command or the break command in C. Use this flag to prevent the currently rewritten URL from being rewritten further by following rules. For example, use it to rewrite the root-path URL ('/') to a real one, e.g., '/e/www/'. - */ - if ("last".equalsIgnoreCase(flag) || "L".equalsIgnoreCase(flag)) { - rule.setToLast("true"); - } - /* - # 'next|N' (next round) - Re-run the rewriting process (starting again with the first rewriting rule). This time, the URL to match is no longer the original URL, but rather the URL returned by the last rewriting rule. This corresponds to the Perl next command or the continue command in C. Use this flag to restart the rewriting process - to immediately go to the top of the loop. - Be careful not to create an infinite loop! - */ - if ("next".equalsIgnoreCase(flag) || "N".equalsIgnoreCase(flag)) { - log.info("next flag [N] not supported"); - } - /* - # 'nocase|NC' (no case) - This makes the Pattern case-insensitive, ignoring difference between 'A-Z' and 'a-z' when Pattern is matched against the current URL. - */ - if ("nocase".equalsIgnoreCase(flag) || "NC".equalsIgnoreCase(flag)) { - rule.setFromCaseSensitive(false); - } else { - rule.setFromCaseSensitive(true); - } - /* - # 'noescape|NE' (no URI escaping of output) - This flag prevents mod_rewrite from applying the usual URI escaping rules to the result of a rewrite. Ordinarily, special characters (such as '%', '$', ';', and so on) will be escaped into their hexcode equivalents ('%25', '%24', and '%3B', respectively); this flag prevents this from happening. This allows percent symbols to appear in the output, as in - - RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE] - which would turn '/foo/zed' into a safe request for '/bar?arg=P1=zed'. - */ - if ("noescape".equalsIgnoreCase(flag) || "NE".equalsIgnoreCase(flag)) { - rule.setEncodeToUrl(false); - } - /* - # 'nosubreq|NS' ( not for internal sub-requests) - This flag forces the rewrite engine to skip a rewrite rule if the current request is an internal sub-request. For instance, sub-requests occur internally in Apache when mod_include tries to find out information about possible directory default files (index.xxx). On sub-requests it is not always useful, and can even cause errors, if the complete set of rules are applied. Use this flag to exclude some rules. - To decide whether or not to use this rule: if you prefix URLs with CGI-scripts, to force them to be processed by the CGI-script, it's likely that you will run into problems (or significant overhead) on sub-requests. In these cases, use this flag. - */ - if ("nosubreq".equalsIgnoreCase(flag) || "NS".equalsIgnoreCase(flag)) { - log.info("nosubreq flag [NS] not supported"); - } - /* - # 'proxy|P' (force proxy) - This flag forces the substitution part to be internally sent as a proxy request and immediately (rewrite processing stops here) put through the proxy module. You must make sure that the substitution string is a valid URI (typically starting with http://hostname) which can be handled by the Apache proxy module. If not, you will get an error from the proxy module. Use this flag to achieve a more powerful implementation of the ProxyPass directive, to map remote content into the namespace of the local server. - - Note: mod_proxy must be enabled in order to use this flag. - */ - if ("proxy".equalsIgnoreCase(flag) || "P".equalsIgnoreCase(flag)) { - rule.setToType("proxy"); - } - /* - # 'passthrough|PT' (pass through to next handler) - This flag forces the rewrite engine to set the uri field of the internal request_rec structure to the value of the filename field. This flag is just a hack to enable post-processing of the output of RewriteRule directives, using Alias, ScriptAlias, Redirect, and other directives from various URI-to-filename translators. For example, to rewrite /abc to /def using mod_rewrite, and then /def to /ghi using mod_alias: - - RewriteRule ^/abc(.*) /def$1 [PT] - Alias /def /ghi - If you omit the PT flag, mod_rewrite will rewrite uri=/abc/... to filename=/def/... as a full API-compliant URI-to-filename translator should do. Then mod_alias will try to do a URI-to-filename transition, which will fail. - - Note: You must use this flag if you want to mix directives from different modules which allow URL-to-filename translators. The typical example is the use of mod_alias and mod_rewrite. - */ - if ("passthrough".equalsIgnoreCase(flag) || "PT".equalsIgnoreCase(flag)) { - rule.setToType("forward"); - } - /* - # 'qsappend|QSA' (query string append) - This flag forces the rewrite engine to append a query string part of the substitution string to the existing string, instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule. - */ - if ("qsappend".equalsIgnoreCase(flag) || "QSA".equalsIgnoreCase(flag)) { - rule.setQueryStringAppend("true"); - } - /* - # 'redirect|R [=code]' (force redirect) - Prefix Substitution with http://thishost[:thisport]/ (which makes the new URL a URI) to force a external redirection. If no code is given, a HTTP response of 302 (MOVED TEMPORARILY) will be returned. If you want to use other response codes in the range 300-400, simply specify the appropriate number or use one of the following symbolic names: temp (default), permanent, seeother. Use this for rules to canonicalize the URL and return it to the client - to translate ``/~'' into ``/u/'', or to always append a slash to /u/user, etc. - Note: When you use this flag, make sure that the substitution field is a valid URL! Otherwise, you will be redirecting to an invalid location. Remember that this flag on its own will only prepend http://thishost[:thisport]/ to the URL, and rewriting will continue. Usually, you will want to stop rewriting at this point, and redirect immediately. To stop rewriting, you should add the 'L' flag. - */ - if ("redirect".equalsIgnoreCase(flag) || "R".equalsIgnoreCase(flag)) { - if ("301".equals(flagValue)) { - rule.setToType("permanent-redirect"); - } else if ("302".equals(flagValue)) { - rule.setToType("temporary-redirect"); - } else { - rule.setToType("redirect"); - } - } - /* - # 'skip|S=num' (skip next rule(s)) - This flag forces the rewriting engine to skip the next num rules in sequence, if the current rule matches. Use this to make pseudo if-then-else constructs: The last rule of the then-clause becomes skip=N, where N is the number of rules in the else-clause. (This is not the same as the 'chain|C' flag!) - */ - if ("skip".equalsIgnoreCase(flag) || "S".equalsIgnoreCase(flag)) { - log.info("Skip flag [S] not supported"); - } - /* - # 'type|T=MIME-type' (force MIME type) - Force the MIME-type of the target file to be MIME-type. This can be used to set up the content-type based on some conditions. For example, the following snippet allows .php files to be displayed by mod_php if they are called with the .phps extension: - */ - if ("type".equalsIgnoreCase(flag) || "T".equalsIgnoreCase(flag)) { - SetAttribute set = new SetAttribute(); - set.setType("content-type"); - set.setValue(flagValue); - rule.addSetAttribute(set); - } - - } - - } else { - log.error("cannot parse flags from " + part); - } - } - - private Condition processRewriteCond(String rewriteCondLine) { - log.debug("about to parse condition"); - Condition condition = new Condition(); - Matcher condMatcher = CONDITION_PATTERN.matcher(rewriteCondLine); - if (condMatcher.matches()) { - String conditionParts = StringUtils.trimToNull(condMatcher.group(1)); - if (conditionParts != null) { - String[] condParts = conditionParts.split(" "); - for (int i = 0; i < condParts.length; i++) { - String part = StringUtils.trimToNull(condParts[i]); - if (part == null) continue; - if (part.equalsIgnoreCase("%{HTTP_USER_AGENT}")) { - condition.setType("header"); - condition.setName("user-agent"); - } else if (part.equalsIgnoreCase("%{HTTP_REFERER}")) { - condition.setType("header"); - condition.setName("referer"); - } else if (part.equalsIgnoreCase("%{HTTP_COOKIE}")) { - condition.setType("header"); - condition.setName("cookie"); - } else if (part.equalsIgnoreCase("%{HTTP_FORWARDED}")) { - condition.setType("header"); - condition.setName("forwarded"); - } else if (part.equalsIgnoreCase("%{HTTP_PROXY_CONNECTION}")) { - condition.setType("header"); - condition.setName("proxy-connection"); - } else if (part.equalsIgnoreCase("%{HTTP_ACCEPT}")) { - condition.setType("header"); - condition.setName("accept"); - } else if (part.equalsIgnoreCase("%{HTTP_HOST}")) { - condition.setType("server-name"); - - } else if (part.equalsIgnoreCase("%{REMOTE_ADDR}")) { - condition.setType("remote-addr"); - } else if (part.equalsIgnoreCase("%{REMOTE_HOST}")) { - condition.setType("remote-host"); - } else if (part.equalsIgnoreCase("%{REMOTE_USER}")) { - condition.setType("remote-user"); - } else if (part.equalsIgnoreCase("%{REQUEST_METHOD}")) { - condition.setType("method"); - } else if (part.equalsIgnoreCase("%{QUERY_STRING}")) { - condition.setType("query-string"); - - } else if (part.equalsIgnoreCase("%{TIME_YEAR}")) { - condition.setType("year"); - } else if (part.equalsIgnoreCase("%{TIME_MON}")) { - condition.setType("month"); - } else if (part.equalsIgnoreCase("%{TIME_DAY}")) { - condition.setType("dayofmonth"); - } else if (part.equalsIgnoreCase("%{TIME_WDAY}")) { - condition.setType("dayofweek"); - } else if (part.equalsIgnoreCase("%{TIME_HOUR}")) { - condition.setType("hourofday"); - } else if (part.equalsIgnoreCase("%{TIME_MIN}")) { - condition.setType("minute"); - } else if (part.equalsIgnoreCase("%{TIME_SEC}")) { - condition.setType("second"); - - } else if (part.equalsIgnoreCase("%{PATH_INFO}")) { - condition.setType("path-info"); - } else if (part.equalsIgnoreCase("%{AUTH_TYPE}")) { - condition.setType("auth-type"); - } else if (part.equalsIgnoreCase("%{SERVER_PORT}")) { - condition.setType("port"); - } else if (part.equalsIgnoreCase("%{REQUEST_URI}") || part.equalsIgnoreCase("$1")) { - condition.setType("request-uri"); - } else if (part.equalsIgnoreCase("%{REQUEST_FILENAME}")) { - condition.setType("request-filename"); - - } else if (part.equals("-f") || part.equals("-F")) { - condition.setOperator("isfile"); - } else if (part.equals("-d")) { - condition.setOperator("isdir"); - } else if (part.equalsIgnoreCase("-s")) { - condition.setOperator("isfilewithsize"); - } else if (part.equals("!-f") || part.equals("!-F")) { - condition.setOperator("notfile"); - } else if (part.equals("!-d")) { - condition.setOperator("notdir"); - } else if (part.equalsIgnoreCase("!-s")) { - condition.setOperator("notfilewithsize"); - - //todo: bits below this comment - } else if (part.equalsIgnoreCase("%{REMOTE_PORT}")) { - log.error("REMOTE_PORT currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{REMOTE_IDENT}")) { - log.error("REMOTE_IDENT currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{SCRIPT_FILENAME}")) { - log.error("SCRIPT_FILENAME currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{DOCUMENT_ROOT}")) { - log.error("DOCUMENT_ROOT currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{SERVER_ADMIN}")) { - log.error("SERVER_ADMIN currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{SERVER_NAME}")) { - log.error("SERVER_NAME currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{SERVER_ADDR}")) { - log.error("SERVER_ADDR currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{SERVER_PROTOCOL}")) { - log.error("SERVER_PROTOCOL currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{SERVER_SOFTWARE}")) { - log.error("SERVER_SOFTWARE currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{TIME}")) { - log.error("TIME currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{API_VERSION}")) { - log.error("API_VERSION currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{THE_REQUEST}")) { - log.error("THE_REQUEST currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{IS_SUBREQ}")) { - log.error("IS_SUBREQ currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{HTTPS}")) { - log.error("HTTPS currently unsupported, ignoring"); - //todo: note https in mod_rewrite means "on" in URF land it means true - - } else { - if(part.startsWith("!")) { - condition.setOperator("notequal"); - condition.setValue(part.replaceFirst("^!", "")); - } else { - condition.setValue(part); - } - } - - } - } else { - log.error("could not parse condition from " + rewriteCondLine); - } - } else { - log.error("cannot parse " + rewriteCondLine); - } - return condition; - } - - - - public String getType(String part) { - if (part.equalsIgnoreCase("%{HTTP_USER_AGENT}")) { - return "header:user-agent"; - } else if (part.equalsIgnoreCase("%{HTTP_REFERER}")) { - return "header:referer"; - } else if (part.equalsIgnoreCase("%{HTTP_COOKIE}")) { - return "header:cookie"; - } else if (part.equalsIgnoreCase("%{HTTP_FORWARDED}")) { - return "header:forwarded"; - } else if (part.equalsIgnoreCase("%{HTTP_PROXY_CONNECTION}")) { - return "header:proxy-connection"; - } else if (part.equalsIgnoreCase("%{HTTP_ACCEPT}")) { - return "header:accept"; - } else if (part.equalsIgnoreCase("%{HTTP_HOST}")) { - return "server-name"; - - } else if (part.equalsIgnoreCase("%{REMOTE_ADDR}")) { - return "remote-addr"; - } else if (part.equalsIgnoreCase("%{REMOTE_HOST}")) { - return "remote-host"; - } else if (part.equalsIgnoreCase("%{REMOTE_USER}")) { - return "remote-user"; - } else if (part.equalsIgnoreCase("%{REQUEST_METHOD}")) { - return "method"; - } else if (part.equalsIgnoreCase("%{QUERY_STRING}")) { - return "query-string"; - - } else if (part.equalsIgnoreCase("%{TIME_YEAR}")) { - return "year"; - } else if (part.equalsIgnoreCase("%{TIME_MON}")) { - return "month"; - } else if (part.equalsIgnoreCase("%{TIME_DAY}")) { - return "dayofmonth"; - } else if (part.equalsIgnoreCase("%{TIME_WDAY}")) { - return "dayofweek"; - } else if (part.equalsIgnoreCase("%{TIME_HOUR}")) { - return "hourofday"; - } else if (part.equalsIgnoreCase("%{TIME_MIN}")) { - return "minute"; - } else if (part.equalsIgnoreCase("%{TIME_SEC}")) { - return "second"; - - } else if (part.equalsIgnoreCase("%{PATH_INFO}")) { - return "path-info"; - } else if (part.equalsIgnoreCase("%{AUTH_TYPE}")) { - return "auth-type"; - } else if (part.equalsIgnoreCase("%{SERVER_PORT}")) { - return "port"; - } else if (part.equalsIgnoreCase("%{REQUEST_URI}") || part.equalsIgnoreCase("$1")) { - return "request-uri"; - } else if (part.equalsIgnoreCase("%{REQUEST_FILENAME}")) { - return "request-filename"; - - } else if (part.equalsIgnoreCase("%{REMOTE_PORT}")) { - log.error("REMOTE_PORT currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{REMOTE_IDENT}")) { - log.error("REMOTE_IDENT currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{SCRIPT_FILENAME}")) { - log.error("SCRIPT_FILENAME currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{DOCUMENT_ROOT}")) { - log.error("DOCUMENT_ROOT currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{SERVER_ADMIN}")) { - log.error("SERVER_ADMIN currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{SERVER_NAME}")) { - log.error("SERVER_NAME currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{SERVER_ADDR}")) { - log.error("SERVER_ADDR currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{SERVER_PROTOCOL}")) { - log.error("SERVER_PROTOCOL currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{SERVER_SOFTWARE}")) { - log.error("SERVER_SOFTWARE currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{TIME}")) { - log.error("TIME currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{API_VERSION}")) { - log.error("API_VERSION currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{THE_REQUEST}")) { - log.error("THE_REQUEST currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{IS_SUBREQ}")) { - log.error("IS_SUBREQ currently unsupported, ignoring"); - } else if (part.equalsIgnoreCase("%{HTTPS}")) { - log.error("HTTPS currently unsupported, ignoring"); - } - - return ""; - } -} +/** + * Copyright (c) 2005-2023, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + *
+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + *
+ * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite.utils;
+
+import org.tuckey.web.filters.urlrewrite.Condition;
+import org.tuckey.web.filters.urlrewrite.Conf;
+import org.tuckey.web.filters.urlrewrite.NormalRule;
+import org.tuckey.web.filters.urlrewrite.SetAttribute;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Loader to enable loading of mod_rewrite style configuration for UrlRewriteFilter.
+ */
+public class ModRewriteConfLoader {
+
+ private static Log log = Log.getLog(ModRewriteConfLoader.class);
+
+ private final Pattern LOG_LEVEL_PATTERN = Pattern.compile("RewriteLogLevel\\s+([0-9]+)\\s*$");
+ private final Pattern LOG_TYPE_PATTERN = Pattern.compile("RewriteLog\\s+(.*)$");
+ private final Pattern ENGINE_PATTERN = Pattern.compile("RewriteEngine\\s+([a-zA-Z0-9]+)\\s*$");
+ private final Pattern CONDITION_PATTERN = Pattern.compile("RewriteCond\\s+(.*)$");
+ private final Pattern RULE_PATTERN = Pattern.compile("RewriteRule\\s+(.*)$");
+ private final Pattern TO_VARIABLE_PATTERN = Pattern.compile("(? 0) notesBuffer.append("\n");
+ String noteLine = StringUtils.trim(line.substring(1));
+ notesBuffer.append(noteLine);
+
+ } else if (line.startsWith("RewriteBase")) {
+ log.info("RewriteBase not supported, ignored");
+
+ } else if (line.startsWith("RewriteCond")) {
+ Condition condition = processRewriteCond(line);
+ if (condition != null) conditionsBuffer.add(condition);
+
+ } else if (line.startsWith("RewriteEngine")) {
+ processRewriteEngine(conf, line);
+
+ } else if (line.startsWith("RewriteLock")) {
+ log.error("RewriteLock not supported, ignored");
+
+ } else if (line.startsWith("RewriteLogLevel")) {
+ logLevelStr = parseLogLevel(logLevelStr, line);
+
+ } else if (line.startsWith("RewriteLog")) {
+ logTypeStr = parseLogType(logTypeStr, line);
+
+ } else if (line.startsWith("RewriteMap")) {
+ log.error("RewriteMap not supported, ignored");
+
+ } else if (line.startsWith("RewriteOptions")) {
+ log.error("RewriteOptions not supported, ignored");
+
+ } else if (line.startsWith("RewriteRule")) {
+ parseRule(conf, conditionsBuffer, notesBuffer, line);
+ notesBuffer = new StringBuffer();
+ conditionsBuffer = new ArrayList();
+ } else {
+ log.error("Unknown line: " + line);
+ }
+ }
+ if (logTypeStr != null || logLevelStr != null) {
+ String logStr = (logTypeStr == null ? "" : logTypeStr) + (logLevelStr == null ? "" : ":" + logLevelStr);
+ log.debug("setting log to: " + logStr);
+ Log.setLevel(logStr);
+ }
+ if (conditionsBuffer.size() > 0) {
+ log.error("conditions left over without a rule");
+ }
+ }
+
+ private void parseRule(Conf conf, List conditionsBuffer, StringBuffer notesBuffer, String line) {
+ NormalRule rule = processRule(line);
+ for (int j = 0; j < conditionsBuffer.size(); j++) {
+ Condition condition = (Condition) conditionsBuffer.get(j);
+ rule.addCondition(condition);
+ }
+ if (notesBuffer.length() > 0) rule.setNote(notesBuffer.toString());
+ conf.addRule(rule);
+ }
+
+ private String parseLogType(String logTypeStr, String line) {
+ Matcher logTypeMatcher = LOG_TYPE_PATTERN.matcher(line);
+ if (logTypeMatcher.matches()) {
+ logTypeStr = StringUtils.trimToNull(logTypeMatcher.group(1));
+ if (logTypeStr != null) {
+ logTypeStr = logTypeStr.replaceAll("\"", "");
+ log.debug("RewriteLog parsed as " + logTypeStr);
+ }
+ }
+ return logTypeStr;
+ }
+
+ private String parseLogLevel(String logLevelStr, String line) {
+ log.debug("found a RewriteLogLevel");
+ Matcher logLevelMatcher = LOG_LEVEL_PATTERN.matcher(line);
+ if (logLevelMatcher.matches()) {
+ int logLevel = NumberUtils.stringToInt(logLevelMatcher.group(1));
+ if (logLevel <= 1) logLevelStr = "FATAL";
+ else if (logLevel == 2) logLevelStr = "ERROR";
+ else if (logLevel == 3) logLevelStr = "INFO";
+ else if (logLevel == 4) logLevelStr = "WARN";
+ else if (logLevel >= 5) logLevelStr = "DEBUG";
+ log.debug("RewriteLogLevel parsed as " + logLevel);
+
+ } else {
+ log.error("cannot parse " + line);
+ }
+ return logLevelStr;
+ }
+
+ private NormalRule processRule(String line) {
+ NormalRule rule = new NormalRule();
+ Matcher ruleMatcher = RULE_PATTERN.matcher(line);
+ if (ruleMatcher.matches()) {
+ String rulePartStr = StringUtils.trimToNull(ruleMatcher.group(1));
+ if (rulePartStr != null) {
+ log.debug("got rule " + rulePartStr);
+ String[] ruleParts = rulePartStr.split("\\s");
+ int partCounter = 0;
+ for (int j = 0; j < ruleParts.length; j++) {
+ String part = StringUtils.trimToNull(ruleParts[j]);
+ if (part == null) continue;
+ partCounter++;
+ log.debug("parsed rule part " + part);
+ if (partCounter == 1) {
+ rule.setFrom(part);
+ }
+ if (partCounter == 2) {
+ if (!"-".equals(part)) {
+ Matcher matcher = TO_VARIABLE_PATTERN.matcher(part);
+ if (matcher.find()) {
+ String knownType = getType(matcher.group(0).toString());
+ if (knownType != "") {
+ part = part.replace(matcher.group(0).toString(), "%{" + knownType + "}");
+ }
+ }
+ }
+ rule.setTo(part);
+ }
+ if (part.startsWith("[") && part.endsWith("]")) {
+ processRuleFlags(rule, part);
+ }
+ }
+ } else {
+ log.error("could not parse rule from " + line);
+ }
+ } else {
+ log.error("cannot parse " + line);
+ }
+ return rule;
+ }
+
+ private void processRewriteEngine(Conf conf, String line) {
+ boolean enabled = true;
+ Matcher engineMatcher = ENGINE_PATTERN.matcher(line);
+ if (engineMatcher.matches()) {
+ String enabledStr = StringUtils.trim(engineMatcher.group(1));
+ log.debug("RewriteEngine value parsed as '" + enabledStr + "'");
+ if ("0".equalsIgnoreCase(enabledStr) ||
+ "false".equalsIgnoreCase(enabledStr) ||
+ "no".equalsIgnoreCase(enabledStr) ||
+ "off".equalsIgnoreCase(enabledStr)) enabled = false;
+ log.debug("RewriteEngine as boolean '" + enabled + "'");
+ } else {
+ log.error("cannot parse " + line);
+ }
+ conf.setEngineEnabled(enabled);
+ }
+
+ private void processRuleFlags(NormalRule rule, String part) {
+ String rawFlags = StringUtils.trimToNull(part.substring(1, part.length() - 1));
+ if (rawFlags != null) {
+ String[] flags = rawFlags.split(",");
+ for (int k = 0; k < flags.length; k++) {
+ String flag = flags[k];
+ String flagValue = null;
+ if (flag.indexOf("=") != -1) {
+ flagValue = flag.substring(flag.indexOf("=") + 1);
+ flag = flag.substring(0, flag.indexOf("="));
+ }
+ flag = flag.toLowerCase();
+ /*
+ # 'chain|C' (chained with next rule)
+ This flag chains the current rule with the next rule (which itself can be chained with the following rule, and so on). This has the following effect: if a rule matches, then processing continues as usual - the flag has no effect. If the rule does not match, then all following chained rules are skipped. For instance, it can be used to remove the ``.www'' part, inside a per-directory rule set, when you let an external redirect happen (where the ``.www'' part should not occur!).
+ */
+ if ("chain".equalsIgnoreCase(flag) || "C".equalsIgnoreCase(flag)) {
+ log.info("chain flag [C] not supported");
+ }
+ /*
+ # 'cookie|CO=NAME:VAL:domain[:lifetime[:path]]' (set cookie)
+ This sets a cookie in the client's browser. The cookie's name is specified by NAME and the value is VAL. The domain field is the domain of the cookie, such as '.apache.org', the optional lifetime is the lifetime of the cookie in minutes, and the optional path is the path of the cookie
+ */
+ if ("cookie".equalsIgnoreCase(flag) || "CO".equalsIgnoreCase(flag)) {
+ SetAttribute set = new SetAttribute();
+ set.setType("cookie");
+ String cookieName = flagValue;
+ String cookieValue = null;
+ if (flagValue != null) {
+ int colon = flagValue.indexOf(":");
+ if (colon != -1) {
+ cookieValue = flagValue.substring(colon + 1);
+ cookieName = flagValue.substring(0, colon);
+ }
+ }
+ set.setName(cookieName);
+ // NOTE: The colon separated domain, lifetime, path are
+ // handled by SetAttribute.setValue()
+ set.setValue(cookieValue);
+ rule.addSetAttribute(set);
+ }
+ /*
+ # 'env|E=VAR:VAL' (set environment variable)
+ This forces an environment variable named VAR to be set to the value VAL, where VAL can contain regexp backreferences ($N and %N) which will be expanded. You can use this flag more than once, to set more than one variable. The variables can later be dereferenced in many situations, most commonly from within XSSI (via ) or CGI ($ENV{'VAR'}). You can also dereference the variable in a later RewriteCond pattern, using %{ENV:VAR}. Use this to strip information from URLs, while maintaining a record of that information.
+ */
+ if ("env".equalsIgnoreCase(flag) || "E".equalsIgnoreCase(flag)) {
+ log.info("env flag [E] not supported");
+ }
+ /*
+ # 'forbidden|F' (force URL to be forbidden)
+ This forces the current URL to be forbidden - it immediately sends back a HTTP response of 403 (FORBIDDEN). Use this flag in conjunction with appropriate RewriteConds to conditionally block some URLs.
+ */
+ if ("forbidden".equalsIgnoreCase(flag) || "F".equalsIgnoreCase(flag)) {
+ SetAttribute set = new SetAttribute();
+ set.setType("status");
+ set.setValue("403");
+ rule.addSetAttribute(set);
+ }
+ /*
+ # 'gone|G' (force URL to be gone)
+ This forces the current URL to be gone - it immediately sends back a HTTP response of 410 (GONE). Use this flag to mark pages which no longer exist as gone.
+ */
+ if ("gone".equalsIgnoreCase(flag) || "G".equalsIgnoreCase(flag)) {
+ SetAttribute set = new SetAttribute();
+ set.setType("status");
+ set.setValue("410");
+ rule.addSetAttribute(set);
+ }
+ /*
+ # 'last|L' (last rule)
+ Stop the rewriting process here and don't apply any more rewrite rules. This corresponds to the Perl last command or the break command in C. Use this flag to prevent the currently rewritten URL from being rewritten further by following rules. For example, use it to rewrite the root-path URL ('/') to a real one, e.g., '/e/www/'.
+ */
+ if ("last".equalsIgnoreCase(flag) || "L".equalsIgnoreCase(flag)) {
+ rule.setToLast("true");
+ }
+ /*
+ # 'next|N' (next round)
+ Re-run the rewriting process (starting again with the first rewriting rule). This time, the URL to match is no longer the original URL, but rather the URL returned by the last rewriting rule. This corresponds to the Perl next command or the continue command in C. Use this flag to restart the rewriting process - to immediately go to the top of the loop.
+ Be careful not to create an infinite loop!
+ */
+ if ("next".equalsIgnoreCase(flag) || "N".equalsIgnoreCase(flag)) {
+ log.info("next flag [N] not supported");
+ }
+ /*
+ # 'nocase|NC' (no case)
+ This makes the Pattern case-insensitive, ignoring difference between 'A-Z' and 'a-z' when Pattern is matched against the current URL.
+ */
+ if ("nocase".equalsIgnoreCase(flag) || "NC".equalsIgnoreCase(flag)) {
+ rule.setFromCaseSensitive(false);
+ } else {
+ rule.setFromCaseSensitive(true);
+ }
+ /*
+ # 'noescape|NE' (no URI escaping of output)
+ This flag prevents mod_rewrite from applying the usual URI escaping rules to the result of a rewrite. Ordinarily, special characters (such as '%', '$', ';', and so on) will be escaped into their hexcode equivalents ('%25', '%24', and '%3B', respectively); this flag prevents this from happening. This allows percent symbols to appear in the output, as in
+
+ RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]
+ which would turn '/foo/zed' into a safe request for '/bar?arg=P1=zed'.
+ */
+ if ("noescape".equalsIgnoreCase(flag) || "NE".equalsIgnoreCase(flag)) {
+ rule.setEncodeToUrl(false);
+ }
+ /*
+ # 'nosubreq|NS' ( not for internal sub-requests)
+ This flag forces the rewrite engine to skip a rewrite rule if the current request is an internal sub-request. For instance, sub-requests occur internally in Apache when mod_include tries to find out information about possible directory default files (index.xxx). On sub-requests it is not always useful, and can even cause errors, if the complete set of rules are applied. Use this flag to exclude some rules.
+ To decide whether or not to use this rule: if you prefix URLs with CGI-scripts, to force them to be processed by the CGI-script, it's likely that you will run into problems (or significant overhead) on sub-requests. In these cases, use this flag.
+ */
+ if ("nosubreq".equalsIgnoreCase(flag) || "NS".equalsIgnoreCase(flag)) {
+ log.info("nosubreq flag [NS] not supported");
+ }
+ /*
+ # 'proxy|P' (force proxy)
+ This flag forces the substitution part to be internally sent as a proxy request and immediately (rewrite processing stops here) put through the proxy module. You must make sure that the substitution string is a valid URI (typically starting with http://hostname) which can be handled by the Apache proxy module. If not, you will get an error from the proxy module. Use this flag to achieve a more powerful implementation of the ProxyPass directive, to map remote content into the namespace of the local server.
+
+ Note: mod_proxy must be enabled in order to use this flag.
+ */
+ if ("proxy".equalsIgnoreCase(flag) || "P".equalsIgnoreCase(flag)) {
+ rule.setToType("proxy");
+ }
+ /*
+ # 'passthrough|PT' (pass through to next handler)
+ This flag forces the rewrite engine to set the uri field of the internal request_rec structure to the value of the filename field. This flag is just a hack to enable post-processing of the output of RewriteRule directives, using Alias, ScriptAlias, Redirect, and other directives from various URI-to-filename translators. For example, to rewrite /abc to /def using mod_rewrite, and then /def to /ghi using mod_alias:
+
+ RewriteRule ^/abc(.*) /def$1 [PT]
+ Alias /def /ghi
+ If you omit the PT flag, mod_rewrite will rewrite uri=/abc/... to filename=/def/... as a full API-compliant URI-to-filename translator should do. Then mod_alias will try to do a URI-to-filename transition, which will fail.
+
+ Note: You must use this flag if you want to mix directives from different modules which allow URL-to-filename translators. The typical example is the use of mod_alias and mod_rewrite.
+ */
+ if ("passthrough".equalsIgnoreCase(flag) || "PT".equalsIgnoreCase(flag)) {
+ rule.setToType("forward");
+ }
+ /*
+ # 'qsappend|QSA' (query string append)
+ This flag forces the rewrite engine to append a query string part of the substitution string to the existing string, instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.
+ */
+ if ("qsappend".equalsIgnoreCase(flag) || "QSA".equalsIgnoreCase(flag)) {
+ rule.setQueryStringAppend("true");
+ }
+ /*
+ # 'redirect|R [=code]' (force redirect)
+ Prefix Substitution with http://thishost[:thisport]/ (which makes the new URL a URI) to force a external redirection. If no code is given, a HTTP response of 302 (MOVED TEMPORARILY) will be returned. If you want to use other response codes in the range 300-400, simply specify the appropriate number or use one of the following symbolic names: temp (default), permanent, seeother. Use this for rules to canonicalize the URL and return it to the client - to translate ``/~'' into ``/u/'', or to always append a slash to /u/user, etc.
+ Note: When you use this flag, make sure that the substitution field is a valid URL! Otherwise, you will be redirecting to an invalid location. Remember that this flag on its own will only prepend http://thishost[:thisport]/ to the URL, and rewriting will continue. Usually, you will want to stop rewriting at this point, and redirect immediately. To stop rewriting, you should add the 'L' flag.
+ */
+ if ("redirect".equalsIgnoreCase(flag) || "R".equalsIgnoreCase(flag)) {
+ if ("301".equals(flagValue)) {
+ rule.setToType("permanent-redirect");
+ } else if ("302".equals(flagValue)) {
+ rule.setToType("temporary-redirect");
+ } else {
+ rule.setToType("redirect");
+ }
+ }
+ /*
+ # 'skip|S=num' (skip next rule(s))
+ This flag forces the rewriting engine to skip the next num rules in sequence, if the current rule matches. Use this to make pseudo if-then-else constructs: The last rule of the then-clause becomes skip=N, where N is the number of rules in the else-clause. (This is not the same as the 'chain|C' flag!)
+ */
+ if ("skip".equalsIgnoreCase(flag) || "S".equalsIgnoreCase(flag)) {
+ log.info("Skip flag [S] not supported");
+ }
+ /*
+ # 'type|T=MIME-type' (force MIME type)
+ Force the MIME-type of the target file to be MIME-type. This can be used to set up the content-type based on some conditions. For example, the following snippet allows .php files to be displayed by mod_php if they are called with the .phps extension:
+ */
+ if ("type".equalsIgnoreCase(flag) || "T".equalsIgnoreCase(flag)) {
+ SetAttribute set = new SetAttribute();
+ set.setType("content-type");
+ set.setValue(flagValue);
+ rule.addSetAttribute(set);
+ }
+
+ }
+
+ } else {
+ log.error("cannot parse flags from " + part);
+ }
+ }
+
+ private Condition processRewriteCond(String rewriteCondLine) {
+ log.debug("about to parse condition");
+ Condition condition = new Condition();
+ Matcher condMatcher = CONDITION_PATTERN.matcher(rewriteCondLine);
+ if (condMatcher.matches()) {
+ String conditionParts = StringUtils.trimToNull(condMatcher.group(1));
+ if (conditionParts != null) {
+ String[] condParts = conditionParts.split(" ");
+ for (int i = 0; i < condParts.length; i++) {
+ String part = StringUtils.trimToNull(condParts[i]);
+ if (part == null) continue;
+ if (part.equalsIgnoreCase("%{HTTP_USER_AGENT}")) {
+ condition.setType("header");
+ condition.setName("user-agent");
+ } else if (part.equalsIgnoreCase("%{HTTP_REFERER}")) {
+ condition.setType("header");
+ condition.setName("referer");
+ } else if (part.equalsIgnoreCase("%{HTTP_COOKIE}")) {
+ condition.setType("header");
+ condition.setName("cookie");
+ } else if (part.equalsIgnoreCase("%{HTTP_FORWARDED}")) {
+ condition.setType("header");
+ condition.setName("forwarded");
+ } else if (part.equalsIgnoreCase("%{HTTP_PROXY_CONNECTION}")) {
+ condition.setType("header");
+ condition.setName("proxy-connection");
+ } else if (part.equalsIgnoreCase("%{HTTP_ACCEPT}")) {
+ condition.setType("header");
+ condition.setName("accept");
+ } else if (part.equalsIgnoreCase("%{HTTP_HOST}")) {
+ condition.setType("server-name");
+
+ } else if (part.equalsIgnoreCase("%{REMOTE_ADDR}")) {
+ condition.setType("remote-addr");
+ } else if (part.equalsIgnoreCase("%{REMOTE_HOST}")) {
+ condition.setType("remote-host");
+ } else if (part.equalsIgnoreCase("%{REMOTE_USER}")) {
+ condition.setType("remote-user");
+ } else if (part.equalsIgnoreCase("%{REQUEST_METHOD}")) {
+ condition.setType("method");
+ } else if (part.equalsIgnoreCase("%{QUERY_STRING}")) {
+ condition.setType("query-string");
+
+ } else if (part.equalsIgnoreCase("%{TIME_YEAR}")) {
+ condition.setType("year");
+ } else if (part.equalsIgnoreCase("%{TIME_MON}")) {
+ condition.setType("month");
+ } else if (part.equalsIgnoreCase("%{TIME_DAY}")) {
+ condition.setType("dayofmonth");
+ } else if (part.equalsIgnoreCase("%{TIME_WDAY}")) {
+ condition.setType("dayofweek");
+ } else if (part.equalsIgnoreCase("%{TIME_HOUR}")) {
+ condition.setType("hourofday");
+ } else if (part.equalsIgnoreCase("%{TIME_MIN}")) {
+ condition.setType("minute");
+ } else if (part.equalsIgnoreCase("%{TIME_SEC}")) {
+ condition.setType("second");
+
+ } else if (part.equalsIgnoreCase("%{PATH_INFO}")) {
+ condition.setType("path-info");
+ } else if (part.equalsIgnoreCase("%{AUTH_TYPE}")) {
+ condition.setType("auth-type");
+ } else if (part.equalsIgnoreCase("%{SERVER_PORT}")) {
+ condition.setType("port");
+ } else if (part.equalsIgnoreCase("%{REQUEST_URI}") || part.equalsIgnoreCase("$1")) {
+ condition.setType("request-uri");
+ } else if (part.equalsIgnoreCase("%{REQUEST_FILENAME}")) {
+ condition.setType("request-filename");
+
+ } else if (part.equals("-f") || part.equals("-F")) {
+ condition.setOperator("isfile");
+ } else if (part.equals("-d")) {
+ condition.setOperator("isdir");
+ } else if (part.equalsIgnoreCase("-s")) {
+ condition.setOperator("isfilewithsize");
+ } else if (part.equals("!-f") || part.equals("!-F")) {
+ condition.setOperator("notfile");
+ } else if (part.equals("!-d")) {
+ condition.setOperator("notdir");
+ } else if (part.equalsIgnoreCase("!-s")) {
+ condition.setOperator("notfilewithsize");
+
+ //todo: bits below this comment
+ } else if (part.equalsIgnoreCase("%{REMOTE_PORT}")) {
+ log.error("REMOTE_PORT currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{REMOTE_IDENT}")) {
+ log.error("REMOTE_IDENT currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{SCRIPT_FILENAME}")) {
+ log.error("SCRIPT_FILENAME currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{DOCUMENT_ROOT}")) {
+ log.error("DOCUMENT_ROOT currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{SERVER_ADMIN}")) {
+ log.error("SERVER_ADMIN currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{SERVER_NAME}")) {
+ log.error("SERVER_NAME currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{SERVER_ADDR}")) {
+ log.error("SERVER_ADDR currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{SERVER_PROTOCOL}")) {
+ log.error("SERVER_PROTOCOL currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{SERVER_SOFTWARE}")) {
+ log.error("SERVER_SOFTWARE currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{TIME}")) {
+ log.error("TIME currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{API_VERSION}")) {
+ log.error("API_VERSION currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{THE_REQUEST}")) {
+ log.error("THE_REQUEST currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{IS_SUBREQ}")) {
+ log.error("IS_SUBREQ currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{HTTPS}")) {
+ log.error("HTTPS currently unsupported, ignoring");
+ //todo: note https in mod_rewrite means "on" in URF land it means true
+
+ } else {
+ if(part.startsWith("!")) {
+ condition.setOperator("notequal");
+ condition.setValue(part.replaceFirst("^!", ""));
+ } else {
+ condition.setValue(part);
+ }
+ }
+
+ }
+ } else {
+ log.error("could not parse condition from " + rewriteCondLine);
+ }
+ } else {
+ log.error("cannot parse " + rewriteCondLine);
+ }
+ return condition;
+ }
+
+
+
+ public String getType(String part) {
+ if (part.equalsIgnoreCase("%{HTTP_USER_AGENT}")) {
+ return "header:user-agent";
+ } else if (part.equalsIgnoreCase("%{HTTP_REFERER}")) {
+ return "header:referer";
+ } else if (part.equalsIgnoreCase("%{HTTP_COOKIE}")) {
+ return "header:cookie";
+ } else if (part.equalsIgnoreCase("%{HTTP_FORWARDED}")) {
+ return "header:forwarded";
+ } else if (part.equalsIgnoreCase("%{HTTP_PROXY_CONNECTION}")) {
+ return "header:proxy-connection";
+ } else if (part.equalsIgnoreCase("%{HTTP_ACCEPT}")) {
+ return "header:accept";
+ } else if (part.equalsIgnoreCase("%{HTTP_HOST}")) {
+ return "server-name";
+
+ } else if (part.equalsIgnoreCase("%{REMOTE_ADDR}")) {
+ return "remote-addr";
+ } else if (part.equalsIgnoreCase("%{REMOTE_HOST}")) {
+ return "remote-host";
+ } else if (part.equalsIgnoreCase("%{REMOTE_USER}")) {
+ return "remote-user";
+ } else if (part.equalsIgnoreCase("%{REQUEST_METHOD}")) {
+ return "method";
+ } else if (part.equalsIgnoreCase("%{QUERY_STRING}")) {
+ return "query-string";
+
+ } else if (part.equalsIgnoreCase("%{TIME_YEAR}")) {
+ return "year";
+ } else if (part.equalsIgnoreCase("%{TIME_MON}")) {
+ return "month";
+ } else if (part.equalsIgnoreCase("%{TIME_DAY}")) {
+ return "dayofmonth";
+ } else if (part.equalsIgnoreCase("%{TIME_WDAY}")) {
+ return "dayofweek";
+ } else if (part.equalsIgnoreCase("%{TIME_HOUR}")) {
+ return "hourofday";
+ } else if (part.equalsIgnoreCase("%{TIME_MIN}")) {
+ return "minute";
+ } else if (part.equalsIgnoreCase("%{TIME_SEC}")) {
+ return "second";
+
+ } else if (part.equalsIgnoreCase("%{PATH_INFO}")) {
+ return "path-info";
+ } else if (part.equalsIgnoreCase("%{AUTH_TYPE}")) {
+ return "auth-type";
+ } else if (part.equalsIgnoreCase("%{SERVER_PORT}")) {
+ return "port";
+ } else if (part.equalsIgnoreCase("%{REQUEST_URI}") || part.equalsIgnoreCase("$1")) {
+ return "request-uri";
+ } else if (part.equalsIgnoreCase("%{REQUEST_FILENAME}")) {
+ return "request-filename";
+
+ } else if (part.equalsIgnoreCase("%{REMOTE_PORT}")) {
+ log.error("REMOTE_PORT currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{REMOTE_IDENT}")) {
+ log.error("REMOTE_IDENT currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{SCRIPT_FILENAME}")) {
+ log.error("SCRIPT_FILENAME currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{DOCUMENT_ROOT}")) {
+ log.error("DOCUMENT_ROOT currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{SERVER_ADMIN}")) {
+ log.error("SERVER_ADMIN currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{SERVER_NAME}")) {
+ log.error("SERVER_NAME currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{SERVER_ADDR}")) {
+ log.error("SERVER_ADDR currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{SERVER_PROTOCOL}")) {
+ log.error("SERVER_PROTOCOL currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{SERVER_SOFTWARE}")) {
+ log.error("SERVER_SOFTWARE currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{TIME}")) {
+ log.error("TIME currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{API_VERSION}")) {
+ log.error("API_VERSION currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{THE_REQUEST}")) {
+ log.error("THE_REQUEST currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{IS_SUBREQ}")) {
+ log.error("IS_SUBREQ currently unsupported, ignoring");
+ } else if (part.equalsIgnoreCase("%{HTTPS}")) {
+ log.error("HTTPS currently unsupported, ignoring");
+ }
+
+ return "";
+ }
+}
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/NumberUtils.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/NumberUtils.java
index 9012595a..ea31957b 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/NumberUtils.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/NumberUtils.java
@@ -1,69 +1,69 @@
-/**
- * Copyright (c) 2005-2007, Paul Tuckey
- * All rights reserved.
- * ====================================================================
- * Licensed under the BSD License. Text as follows.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * - Neither the name tuckey.org nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- */
-package org.tuckey.web.filters.urlrewrite.utils;
-
-/**
- * Written in the style of commons-lang NumberUtils with only the with only two methods.
- *
- * @author Paul Tuckey
- * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $
- */
-public class NumberUtils {
-
- public static int stringToInt(final String str) {
- return stringToInt(str, 0);
- }
-
- public static int stringToInt(final String str, final int defaultValue) {
- try {
- return Integer.parseInt(str);
- } catch (NumberFormatException nfe) {
- return defaultValue;
- }
- }
-
- public static long stringToLong(final String str) {
- return stringToLong(str, 0);
- }
-
- public static long stringToLong(final String str, final long defaultValue) {
- try {
- return Long.parseLong(str);
- } catch (NumberFormatException nfe) {
- return defaultValue;
- }
- }
-
-}
+/**
+ * Copyright (c) 2005-2023, Paul Tuckey
+ * All rights reserved.
+ * ====================================================================
+ * Licensed under the BSD License. Text as follows.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite.utils;
+
+/**
+ * Written in the style of commons-lang NumberUtils with only the with only two methods.
+ *
+ * @author Paul Tuckey
+ * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $
+ */
+public class NumberUtils {
+
+ public static int stringToInt(final String str) {
+ return stringToInt(str, 0);
+ }
+
+ public static int stringToInt(final String str, final int defaultValue) {
+ try {
+ return Integer.parseInt(str);
+ } catch (NumberFormatException nfe) {
+ return defaultValue;
+ }
+ }
+
+ public static long stringToLong(final String str) {
+ return stringToLong(str, 0);
+ }
+
+ public static long stringToLong(final String str, final long defaultValue) {
+ try {
+ return Long.parseLong(str);
+ } catch (NumberFormatException nfe) {
+ return defaultValue;
+ }
+ }
+
+}
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/RegexMatcher.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/RegexMatcher.java
index 0cc24710..5925991c 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/RegexMatcher.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/RegexMatcher.java
@@ -1,101 +1,101 @@
-/**
- * Copyright (c) 2005-2007, Paul Tuckey
- * All rights reserved.
- * ====================================================================
- * Licensed under the BSD License. Text as follows.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * - Neither the name tuckey.org nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- */
-package org.tuckey.web.filters.urlrewrite.utils;
-
-import java.util.regex.Matcher;
-
-/**
- * Simple wrapper for java.util.regex.Matcher.
- *
- * @see java.util.regex.Matcher
- */
-public class RegexMatcher implements StringMatchingMatcher {
-
- private Matcher matcher;
- private boolean found = false;
-
- public RegexMatcher(Matcher matcher) {
- this.matcher = matcher;
- }
-
- /**
- * @see Matcher#find
- */
- public boolean find() {
- found = matcher.find();
- return found;
- }
-
- public boolean isFound() {
- return found;
- }
-
- public void reset() {
- matcher.reset();
- found = false;
- }
-
- public String replaceAll(String replacement) {
- String replaced = matcher.replaceAll(replacement);
- reset();
- return replaced;
- }
-
- public int groupCount() {
- return matcher.groupCount();
- }
-
- public String group(int groupId) {
- return matcher.group(groupId);
- }
-
- public int end() {
- return matcher.end();
- }
-
- public int start() {
- return matcher.start();
- }
-
- public boolean isMultipleMatchingSupported() {
- return true;
- }
-
- public boolean hitEnd(){
- return matcher.hitEnd();
- }
-
-
-}
+/**
+ * Copyright (c) 2005-2023, Paul Tuckey
+ * All rights reserved.
+ * ====================================================================
+ * Licensed under the BSD License. Text as follows.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite.utils;
+
+import java.util.regex.Matcher;
+
+/**
+ * Simple wrapper for java.util.regex.Matcher.
+ *
+ * @see java.util.regex.Matcher
+ */
+public class RegexMatcher implements StringMatchingMatcher {
+
+ private Matcher matcher;
+ private boolean found = false;
+
+ public RegexMatcher(Matcher matcher) {
+ this.matcher = matcher;
+ }
+
+ /**
+ * @see Matcher#find
+ */
+ public boolean find() {
+ found = matcher.find();
+ return found;
+ }
+
+ public boolean isFound() {
+ return found;
+ }
+
+ public void reset() {
+ matcher.reset();
+ found = false;
+ }
+
+ public String replaceAll(String replacement) {
+ String replaced = matcher.replaceAll(replacement);
+ reset();
+ return replaced;
+ }
+
+ public int groupCount() {
+ return matcher.groupCount();
+ }
+
+ public String group(int groupId) {
+ return matcher.group(groupId);
+ }
+
+ public int end() {
+ return matcher.end();
+ }
+
+ public int start() {
+ return matcher.start();
+ }
+
+ public boolean isMultipleMatchingSupported() {
+ return true;
+ }
+
+ public boolean hitEnd(){
+ return matcher.hitEnd();
+ }
+
+
+}
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/RegexPattern.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/RegexPattern.java
index 87299339..dae84de4 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/RegexPattern.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/RegexPattern.java
@@ -1,67 +1,67 @@
-/**
- * Copyright (c) 2005-2007, Paul Tuckey
- * All rights reserved.
- * ====================================================================
- * Licensed under the BSD License. Text as follows.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * - Neither the name tuckey.org nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- */
-package org.tuckey.web.filters.urlrewrite.utils;
-
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
-
-/**
- * Simpe wrapper for java.util.regex.Pattern.
- *
- * @see java.util.regex.Pattern
- */
-public class RegexPattern implements StringMatchingPattern {
-
- private Pattern pattern;
-
- public RegexPattern(String patternStr, boolean caseSensitive)
- throws StringMatchingPatternSyntaxException {
- patternStr = (patternStr.charAt(0) == '.') ? '^' + patternStr : patternStr ;// otherwise matcher.find() matches twice
- try {
- if (caseSensitive) {
- pattern = Pattern.compile(patternStr);
- } else {
- pattern = Pattern.compile(patternStr, Pattern.CASE_INSENSITIVE);
- }
- } catch (PatternSyntaxException e) {
- throw new StringMatchingPatternSyntaxException(e);
- }
- }
-
- public StringMatchingMatcher matcher(String regex) {
- return new RegexMatcher(pattern.matcher(regex));
- }
-
-}
+/**
+ * Copyright (c) 2005-2023, Paul Tuckey
+ * All rights reserved.
+ * ====================================================================
+ * Licensed under the BSD License. Text as follows.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite.utils;
+
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * Simpe wrapper for java.util.regex.Pattern.
+ *
+ * @see java.util.regex.Pattern
+ */
+public class RegexPattern implements StringMatchingPattern {
+
+ private Pattern pattern;
+
+ public RegexPattern(String patternStr, boolean caseSensitive)
+ throws StringMatchingPatternSyntaxException {
+ patternStr = (patternStr.charAt(0) == '.') ? '^' + patternStr : patternStr ;// otherwise matcher.find() matches twice
+ try {
+ if (caseSensitive) {
+ pattern = Pattern.compile(patternStr);
+ } else {
+ pattern = Pattern.compile(patternStr, Pattern.CASE_INSENSITIVE);
+ }
+ } catch (PatternSyntaxException e) {
+ throw new StringMatchingPatternSyntaxException(e);
+ }
+ }
+
+ public StringMatchingMatcher matcher(String regex) {
+ return new RegexMatcher(pattern.matcher(regex));
+ }
+
+}
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/ServerNameMatcher.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/ServerNameMatcher.java
index 39bc11ed..795f68e5 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/ServerNameMatcher.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/ServerNameMatcher.java
@@ -1,81 +1,81 @@
-/**
- * Copyright (c) 2005-2007, Paul Tuckey
- * All rights reserved.
- * ====================================================================
- * Licensed under the BSD License. Text as follows.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * - Neither the name tuckey.org nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- */
-package org.tuckey.web.filters.urlrewrite.utils;
-
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Utility class for matching server names.
- *
- * @author Paul Tuckey
- * @version $Revision: 36 $ $Date: 2006-09-19 18:32:39 +1200 (Tue, 19 Sep 2006) $
- */
-public class ServerNameMatcher {
-
- private static Log log = Log.getLog(ServerNameMatcher.class);
-
- private List patterns = new ArrayList();
- WildcardHelper wh = new WildcardHelper();
-
- public ServerNameMatcher(String options) {
- String[] enableOnHostsArr = options.split(",");
- for (int i = 0; i < enableOnHostsArr.length; i++) {
- String s = enableOnHostsArr[i];
- if (StringUtils.isBlank(s)) continue;
- String rawPattern = StringUtils.trim(enableOnHostsArr[i]).toLowerCase();
- int[] compiledPattern = wh.compilePattern(rawPattern);
- patterns.add(compiledPattern);
- }
- }
-
- public boolean isMatch(String serverName) {
- log.debug("looking for hostname match on current server name " + serverName);
- if (patterns == null || StringUtils.isBlank(serverName)) {
- return false;
- }
- serverName = StringUtils.trim(serverName).toLowerCase();
- for (int i = 0; i < patterns.size(); i++) {
- int[] compiledPattern = (int[]) patterns.get(i);
- Map map = new HashMap();
- if (wh.match(map, serverName, compiledPattern)) return true;
- }
- return false;
- }
-
-}
+/**
+ * Copyright (c) 2005-2023, Paul Tuckey
+ * All rights reserved.
+ * ====================================================================
+ * Licensed under the BSD License. Text as follows.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite.utils;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Utility class for matching server names.
+ *
+ * @author Paul Tuckey
+ * @version $Revision: 36 $ $Date: 2006-09-19 18:32:39 +1200 (Tue, 19 Sep 2006) $
+ */
+public class ServerNameMatcher {
+
+ private static Log log = Log.getLog(ServerNameMatcher.class);
+
+ private List patterns = new ArrayList();
+ WildcardHelper wh = new WildcardHelper();
+
+ public ServerNameMatcher(String options) {
+ String[] enableOnHostsArr = options.split(",");
+ for (int i = 0; i < enableOnHostsArr.length; i++) {
+ String s = enableOnHostsArr[i];
+ if (StringUtils.isBlank(s)) continue;
+ String rawPattern = StringUtils.trim(enableOnHostsArr[i]).toLowerCase();
+ int[] compiledPattern = wh.compilePattern(rawPattern);
+ patterns.add(compiledPattern);
+ }
+ }
+
+ public boolean isMatch(String serverName) {
+ log.debug("looking for hostname match on current server name " + serverName);
+ if (patterns == null || StringUtils.isBlank(serverName)) {
+ return false;
+ }
+ serverName = StringUtils.trim(serverName).toLowerCase();
+ for (int i = 0; i < patterns.size(); i++) {
+ int[] compiledPattern = (int[]) patterns.get(i);
+ Map map = new HashMap();
+ if (wh.match(map, serverName, compiledPattern)) return true;
+ }
+ return false;
+ }
+
+}
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingMatcher.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingMatcher.java
index e9e4777a..11497f13 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingMatcher.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingMatcher.java
@@ -1,61 +1,61 @@
-/**
- * Copyright (c) 2005-2007, Paul Tuckey
- * All rights reserved.
- * ====================================================================
- * Licensed under the BSD License. Text as follows.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * - Neither the name tuckey.org nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- */
-package org.tuckey.web.filters.urlrewrite.utils;
-
-/**
- * A generic interface for StringMatching, method signature matches java.util.Matcher.
- *
- * @see java.util.regex.Matcher
- */
-public interface StringMatchingMatcher {
-
- public boolean find();
-
- boolean isMultipleMatchingSupported();
-
- int start();
-
- int end();
-
- void reset();
-
- public boolean isFound();
-
- int groupCount();
-
- String group(int groupId);
-
- public boolean hitEnd();
-}
+/**
+ * Copyright (c) 2005-2023, Paul Tuckey
+ * All rights reserved.
+ * ====================================================================
+ * Licensed under the BSD License. Text as follows.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite.utils;
+
+/**
+ * A generic interface for StringMatching, method signature matches java.util.Matcher.
+ *
+ * @see java.util.regex.Matcher
+ */
+public interface StringMatchingMatcher {
+
+ public boolean find();
+
+ boolean isMultipleMatchingSupported();
+
+ int start();
+
+ int end();
+
+ void reset();
+
+ public boolean isFound();
+
+ int groupCount();
+
+ String group(int groupId);
+
+ public boolean hitEnd();
+}
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingPattern.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingPattern.java
index ae94afe1..54af487f 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingPattern.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingPattern.java
@@ -1,45 +1,45 @@
-/**
- * Copyright (c) 2005-2007, Paul Tuckey
- * All rights reserved.
- * ====================================================================
- * Licensed under the BSD License. Text as follows.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * - Neither the name tuckey.org nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- */
-package org.tuckey.web.filters.urlrewrite.utils;
-
-/**
- *
- *
- */
-public interface StringMatchingPattern {
-
- public StringMatchingMatcher matcher(String matchStr);
-
-}
+/**
+ * Copyright (c) 2005-2023, Paul Tuckey
+ * All rights reserved.
+ * ====================================================================
+ * Licensed under the BSD License. Text as follows.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite.utils;
+
+/**
+ *
+ *
+ */
+public interface StringMatchingPattern {
+
+ public StringMatchingMatcher matcher(String matchStr);
+
+}
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingPatternSyntaxException.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingPatternSyntaxException.java
index c4474fac..f20c7db0 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingPatternSyntaxException.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingPatternSyntaxException.java
@@ -1,49 +1,49 @@
-/**
- * Copyright (c) 2005-2007, Paul Tuckey
- * All rights reserved.
- * ====================================================================
- * Licensed under the BSD License. Text as follows.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * - Neither the name tuckey.org nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- */
-package org.tuckey.web.filters.urlrewrite.utils;
-
-import java.util.regex.PatternSyntaxException;
-
-/**
- *
- *
- */
-public class StringMatchingPatternSyntaxException extends Exception {
- private static final long serialVersionUID = 4616654570576723975L;
-
- public StringMatchingPatternSyntaxException(PatternSyntaxException e) {
- super(e);
- }
-}
+/**
+ * Copyright (c) 2005-2023, Paul Tuckey
+ * All rights reserved.
+ * ====================================================================
+ * Licensed under the BSD License. Text as follows.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite.utils;
+
+import java.util.regex.PatternSyntaxException;
+
+/**
+ *
+ *
+ */
+public class StringMatchingPatternSyntaxException extends Exception {
+ private static final long serialVersionUID = 4616654570576723975L;
+
+ public StringMatchingPatternSyntaxException(PatternSyntaxException e) {
+ super(e);
+ }
+}
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringUtils.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringUtils.java
index 8fb9face..1035adea 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringUtils.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringUtils.java
@@ -1,102 +1,102 @@
-/**
- * Copyright (c) 2005-2007, Paul Tuckey
- * All rights reserved.
- * ====================================================================
- * Licensed under the BSD License. Text as follows.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * - Neither the name tuckey.org nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- */
-package org.tuckey.web.filters.urlrewrite.utils;
-
-/**
- * In the style of commons-lang StringUtils, but a bit smaller!.
- *
- * @author Paul Tuckey
- * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $
- */
-public class StringUtils {
-
- public static String trim(final String str) {
- if (str == null) {
- return null;
- }
- return str.trim();
- }
-
- public static String trimToNull(String str) {
- if (str == null) {
- return null;
- }
- str = str.trim();
- if ("".equals(str)) {
- return null;
- }
- return str;
- }
-
- public static boolean isBlank(final String str) {
- return str == null || "".equals(str) || "".equals(str.trim());
- }
-
- public static String notNull(final String str) {
- if (str == null) {
- return "";
- }
- return str;
- }
-
- public static String nl2br(String note) {
- if (note == null) return null;
- return note.replaceAll("\n", "
");
- }
-
- /**
- * Test if the given String starts with the specified prefix,
- * ignoring upper/lower case.
- *
- * @param str the String to check
- * @param prefix the prefix to look for
- * @see java.lang.String#startsWith
- */
- public static boolean startsWithIgnoreCase(String str, String prefix) {
- if (str == null || prefix == null) {
- return false;
- }
- if (str.startsWith(prefix)) {
- return true;
- }
- if (str.length() < prefix.length()) {
- return false;
- }
- String lcStr = str.substring(0, prefix.length()).toLowerCase();
- String lcPrefix = prefix.toLowerCase();
- return lcStr.equals(lcPrefix);
- }
-
-}
+/**
+ * Copyright (c) 2005-2023, Paul Tuckey
+ * All rights reserved.
+ * ====================================================================
+ * Licensed under the BSD License. Text as follows.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite.utils;
+
+/**
+ * In the style of commons-lang StringUtils, but a bit smaller!.
+ *
+ * @author Paul Tuckey
+ * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $
+ */
+public class StringUtils {
+
+ public static String trim(final String str) {
+ if (str == null) {
+ return null;
+ }
+ return str.trim();
+ }
+
+ public static String trimToNull(String str) {
+ if (str == null) {
+ return null;
+ }
+ str = str.trim();
+ if ("".equals(str)) {
+ return null;
+ }
+ return str;
+ }
+
+ public static boolean isBlank(final String str) {
+ return str == null || "".equals(str) || "".equals(str.trim());
+ }
+
+ public static String notNull(final String str) {
+ if (str == null) {
+ return "";
+ }
+ return str;
+ }
+
+ public static String nl2br(String note) {
+ if (note == null) return null;
+ return note.replaceAll("\n", "
");
+ }
+
+ /**
+ * Test if the given String starts with the specified prefix,
+ * ignoring upper/lower case.
+ *
+ * @param str the String to check
+ * @param prefix the prefix to look for
+ * @see java.lang.String#startsWith
+ */
+ public static boolean startsWithIgnoreCase(String str, String prefix) {
+ if (str == null || prefix == null) {
+ return false;
+ }
+ if (str.startsWith(prefix)) {
+ return true;
+ }
+ if (str.length() < prefix.length()) {
+ return false;
+ }
+ String lcStr = str.substring(0, prefix.length()).toLowerCase();
+ String lcPrefix = prefix.toLowerCase();
+ return lcStr.equals(lcPrefix);
+ }
+
+}
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/TypeUtils.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/TypeUtils.java
index 67f2d3f4..7467346b 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/TypeUtils.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/TypeUtils.java
@@ -1,113 +1,147 @@
-package org.tuckey.web.filters.urlrewrite.utils;
-
-import jakarta.servlet.ServletRequest;
-import jakarta.servlet.ServletResponse;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-
-
-public class TypeUtils {
-
-
- public static Class findClass(String param) {
- Class paramClass = null;
- if ("boolean".equals(param) || "bool".equals(param) || "z".equalsIgnoreCase(param)) paramClass = boolean.class;
- if ("byte".equals(param) || "b".equalsIgnoreCase(param)) paramClass = byte.class;
- if ("char".equals(param) || "c".equalsIgnoreCase(param)) paramClass = char.class;
- if ("short".equals(param) || "s".equalsIgnoreCase(param)) paramClass = short.class;
- if ("int".equals(param) || "i".equalsIgnoreCase(param)) paramClass = int.class;
- if ("long".equals(param) || "l".equalsIgnoreCase(param)) paramClass = long.class;
- if ("float".equals(param) || "f".equalsIgnoreCase(param)) paramClass = float.class;
- if ("double".equals(param) || "d".equalsIgnoreCase(param)) paramClass = double.class;
-
- if ("Boolean".equals(param) || "Bool".equals(param)) paramClass = Boolean.class;
- if ("Byte".equals(param)) paramClass = Byte.class;
- if ("Character".equalsIgnoreCase(param) || "C".equals(param)) paramClass = Character.class;
- if ("Short".equals(param)) paramClass = Short.class;
- if ("Integer".equals(param)) paramClass = Integer.class;
- if ("Long".equals(param)) paramClass = Long.class;
- if ("Float".equals(param)) paramClass = Float.class;
- if ("Double".equals(param)) paramClass = Double.class;
-
- if ("Class".equalsIgnoreCase(param)) paramClass = Class.class;
- if ("Number".equalsIgnoreCase(param)) paramClass = Number.class;
- if ("Object".equalsIgnoreCase(param)) paramClass = Object.class;
- if ("String".equalsIgnoreCase(param) || "str".equalsIgnoreCase(param)) paramClass = String.class;
-
- if ("HttpServletRequest".equalsIgnoreCase(param) || "req".equalsIgnoreCase(param) || "request".equalsIgnoreCase(param))
- paramClass = HttpServletRequest.class;
- if ("HttpServletResponse".equalsIgnoreCase(param) || "res".equalsIgnoreCase(param) || "response".equalsIgnoreCase(param))
- paramClass = HttpServletResponse.class;
- if ("ServletRequest".equalsIgnoreCase(param)) paramClass = ServletRequest.class;
- if ("ServletResponse".equalsIgnoreCase(param)) paramClass = ServletResponse.class;
- return paramClass;
- }
-
-
-
- public static Object getConvertedParam(Class runMethodParam, Object matchObj) {
- // see http://jakarta.apache.org/commons/beanutils/api/org/apache/commons/beanutils/MethodUtils.html
- // for how to handle methods better
- Object param = null;
- if (matchObj == null) {
- if (runMethodParam.isPrimitive()) {
- if (runMethodParam.equals(boolean.class)) param = Boolean.FALSE;
- else if (runMethodParam.equals(char.class)) param = Character.valueOf('\u0000');
- else if (runMethodParam.equals(byte.class)) param = Byte.valueOf((byte) 0);
- else if (runMethodParam.equals(short.class)) param = Short.valueOf((short) 0);
- else if (runMethodParam.equals(int.class)) param = Integer.valueOf(0);
- else if (runMethodParam.equals(long.class)) param = Long.valueOf(0L);
- else if (runMethodParam.equals(float.class)) param = Float.valueOf(0f);
- else if (runMethodParam.equals(double.class)) param = Double.valueOf(0d);
- }
- } else {
- if (runMethodParam.equals(Boolean.class) || runMethodParam.equals(boolean.class))
- param = Boolean.valueOf((String) matchObj);
- else if (runMethodParam.equals(Character.class) || runMethodParam.equals(char.class))
- param = Character.valueOf(((String) matchObj).charAt(0));
- else if (runMethodParam.equals(Byte.class) || runMethodParam.equals(byte.class))
- param = Byte.valueOf((String) matchObj);
- else if (runMethodParam.equals(Short.class) || runMethodParam.equals(short.class))
- param = Short.valueOf((String) matchObj);
- else if (runMethodParam.equals(Integer.class) || runMethodParam.equals(int.class))
- param = Integer.valueOf((String) matchObj);
- else if (runMethodParam.equals(Long.class) || runMethodParam.equals(long.class))
- param = Long.valueOf((String) matchObj);
- else if (runMethodParam.equals(Float.class) || runMethodParam.equals(float.class))
- param = Float.valueOf((String) matchObj);
- else if (runMethodParam.equals(Double.class) || runMethodParam.equals(double.class))
- param = Double.valueOf((String) matchObj);
- else if (matchObj instanceof Throwable &&
- runMethodParam.isAssignableFrom(matchObj.getClass()))
- param = matchObj;
- else {
- try {
- // last attempt
- param = runMethodParam.cast(matchObj);
- } catch (ClassCastException e) {
- // do nothing
- }
- }
- }
- return param;
- }
-
- public static String getMethodSignature(String methodStr, Class[] methodParams) {
- if (methodStr == null) return null;
- StringBuffer sb = new StringBuffer(methodStr);
- if (methodParams != null) {
- for (int i = 0; i < methodParams.length; i++) {
- Class runMethodParam = methodParams[i];
- if (runMethodParam == null) continue;
- if (i == 0) sb.append("(");
- if (i > 0) sb.append(", ");
- sb.append(runMethodParam.getName());
- if (i + 1 == methodParams.length) sb.append(")");
- }
- }
- return sb.toString();
- }
-
-
-
-}
+/**
+ * Copyright (c) 2005-2023, Paul Tuckey
+ * All rights reserved.
+ * ====================================================================
+ * Licensed under the BSD License. Text as follows.
+ *
+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + *
+ * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite.utils;
+
+import jakarta.servlet.ServletRequest;
+import jakarta.servlet.ServletResponse;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+
+
+public class TypeUtils {
+
+
+ public static Class findClass(String param) {
+ Class paramClass = null;
+ if ("boolean".equals(param) || "bool".equals(param) || "z".equalsIgnoreCase(param)) paramClass = boolean.class;
+ if ("byte".equals(param) || "b".equalsIgnoreCase(param)) paramClass = byte.class;
+ if ("char".equals(param) || "c".equalsIgnoreCase(param)) paramClass = char.class;
+ if ("short".equals(param) || "s".equalsIgnoreCase(param)) paramClass = short.class;
+ if ("int".equals(param) || "i".equalsIgnoreCase(param)) paramClass = int.class;
+ if ("long".equals(param) || "l".equalsIgnoreCase(param)) paramClass = long.class;
+ if ("float".equals(param) || "f".equalsIgnoreCase(param)) paramClass = float.class;
+ if ("double".equals(param) || "d".equalsIgnoreCase(param)) paramClass = double.class;
+
+ if ("Boolean".equals(param) || "Bool".equals(param)) paramClass = Boolean.class;
+ if ("Byte".equals(param)) paramClass = Byte.class;
+ if ("Character".equalsIgnoreCase(param) || "C".equals(param)) paramClass = Character.class;
+ if ("Short".equals(param)) paramClass = Short.class;
+ if ("Integer".equals(param)) paramClass = Integer.class;
+ if ("Long".equals(param)) paramClass = Long.class;
+ if ("Float".equals(param)) paramClass = Float.class;
+ if ("Double".equals(param)) paramClass = Double.class;
+
+ if ("Class".equalsIgnoreCase(param)) paramClass = Class.class;
+ if ("Number".equalsIgnoreCase(param)) paramClass = Number.class;
+ if ("Object".equalsIgnoreCase(param)) paramClass = Object.class;
+ if ("String".equalsIgnoreCase(param) || "str".equalsIgnoreCase(param)) paramClass = String.class;
+
+ if ("HttpServletRequest".equalsIgnoreCase(param) || "req".equalsIgnoreCase(param) || "request".equalsIgnoreCase(param))
+ paramClass = HttpServletRequest.class;
+ if ("HttpServletResponse".equalsIgnoreCase(param) || "res".equalsIgnoreCase(param) || "response".equalsIgnoreCase(param))
+ paramClass = HttpServletResponse.class;
+ if ("ServletRequest".equalsIgnoreCase(param)) paramClass = ServletRequest.class;
+ if ("ServletResponse".equalsIgnoreCase(param)) paramClass = ServletResponse.class;
+ return paramClass;
+ }
+
+
+
+ public static Object getConvertedParam(Class runMethodParam, Object matchObj) {
+ // see http://jakarta.apache.org/commons/beanutils/api/org/apache/commons/beanutils/MethodUtils.html
+ // for how to handle methods better
+ Object param = null;
+ if (matchObj == null) {
+ if (runMethodParam.isPrimitive()) {
+ if (runMethodParam.equals(boolean.class)) param = Boolean.FALSE;
+ else if (runMethodParam.equals(char.class)) param = Character.valueOf('\u0000');
+ else if (runMethodParam.equals(byte.class)) param = Byte.valueOf((byte) 0);
+ else if (runMethodParam.equals(short.class)) param = Short.valueOf((short) 0);
+ else if (runMethodParam.equals(int.class)) param = Integer.valueOf(0);
+ else if (runMethodParam.equals(long.class)) param = Long.valueOf(0L);
+ else if (runMethodParam.equals(float.class)) param = Float.valueOf(0f);
+ else if (runMethodParam.equals(double.class)) param = Double.valueOf(0d);
+ }
+ } else {
+ if (runMethodParam.equals(Boolean.class) || runMethodParam.equals(boolean.class))
+ param = Boolean.valueOf((String) matchObj);
+ else if (runMethodParam.equals(Character.class) || runMethodParam.equals(char.class))
+ param = Character.valueOf(((String) matchObj).charAt(0));
+ else if (runMethodParam.equals(Byte.class) || runMethodParam.equals(byte.class))
+ param = Byte.valueOf((String) matchObj);
+ else if (runMethodParam.equals(Short.class) || runMethodParam.equals(short.class))
+ param = Short.valueOf((String) matchObj);
+ else if (runMethodParam.equals(Integer.class) || runMethodParam.equals(int.class))
+ param = Integer.valueOf((String) matchObj);
+ else if (runMethodParam.equals(Long.class) || runMethodParam.equals(long.class))
+ param = Long.valueOf((String) matchObj);
+ else if (runMethodParam.equals(Float.class) || runMethodParam.equals(float.class))
+ param = Float.valueOf((String) matchObj);
+ else if (runMethodParam.equals(Double.class) || runMethodParam.equals(double.class))
+ param = Double.valueOf((String) matchObj);
+ else if (matchObj instanceof Throwable &&
+ runMethodParam.isAssignableFrom(matchObj.getClass()))
+ param = matchObj;
+ else {
+ try {
+ // last attempt
+ param = runMethodParam.cast(matchObj);
+ } catch (ClassCastException e) {
+ // do nothing
+ }
+ }
+ }
+ return param;
+ }
+
+ public static String getMethodSignature(String methodStr, Class[] methodParams) {
+ if (methodStr == null) return null;
+ StringBuffer sb = new StringBuffer(methodStr);
+ if (methodParams != null) {
+ for (int i = 0; i < methodParams.length; i++) {
+ Class runMethodParam = methodParams[i];
+ if (runMethodParam == null) continue;
+ if (i == 0) sb.append("(");
+ if (i > 0) sb.append(", ");
+ sb.append(runMethodParam.getName());
+ if (i + 1 == methodParams.length) sb.append(")");
+ }
+ }
+ return sb.toString();
+ }
+
+
+
+}
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/URLDecoder.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/URLDecoder.java
index 0210b85c..a61b523d 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/URLDecoder.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/URLDecoder.java
@@ -1,84 +1,118 @@
-package org.tuckey.web.filters.urlrewrite.utils;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URISyntaxException;
-
-public class URLDecoder {
-
- public static String decodeURL(String url, String charset) throws URISyntaxException{
- int queryPart = url.indexOf('?');
- String query = null;
- String path = url;
- if(queryPart != -1){
- query = url.substring(queryPart+1);
- path = url.substring(0, queryPart);
- }
- String decodedPath = decodePath(path, charset);
- if(query != null)
- return decodedPath + '?' + decodeQuery(query, charset);
- else
- return decodedPath;
- }
-
- public static String decodePath(String path, String charset) throws URISyntaxException{
- return decodeURLEncoded(path, false, charset);
- }
-
- public static String decodeQuery(String query, String charset) throws URISyntaxException{
- return decodeURLEncoded(query, true, charset);
- }
-
- public static String decodeURLEncoded(String part, boolean query, String charset) throws URISyntaxException{
- try{
- byte[] ascii = part.getBytes("ASCII");
- byte[] decoded = new byte[ascii.length];
- int j=0;
- for(int i=0;i
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite.utils;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URISyntaxException;
+
+public class URLDecoder {
+
+ public static String decodeURL(String url, String charset) throws URISyntaxException{
+ int queryPart = url.indexOf('?');
+ String query = null;
+ String path = url;
+ if(queryPart != -1){
+ query = url.substring(queryPart+1);
+ path = url.substring(0, queryPart);
+ }
+ String decodedPath = decodePath(path, charset);
+ if(query != null)
+ return decodedPath + '?' + decodeQuery(query, charset);
+ else
+ return decodedPath;
+ }
+
+ public static String decodePath(String path, String charset) throws URISyntaxException{
+ return decodeURLEncoded(path, false, charset);
+ }
+
+ public static String decodeQuery(String query, String charset) throws URISyntaxException{
+ return decodeURLEncoded(query, true, charset);
+ }
+
+ public static String decodeURLEncoded(String part, boolean query, String charset) throws URISyntaxException{
+ try{
+ byte[] ascii = part.getBytes("ASCII");
+ byte[] decoded = new byte[ascii.length];
+ int j=0;
+ for(int i=0;i
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite.utils;
+
+import java.io.UnsupportedEncodingException;
+import java.util.BitSet;
+
+/**
+ * URL-encoding utility for each URL part according to the RFC specs
+ * see the rfc at rfc2396
+ *
+ * @author stephane
+ */
+public class URLEncoder {
+
+ /**
+ * mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
+ */
+ public final static BitSet MARK = new BitSet();
+
+ static {
+ MARK.set('-');
+ MARK.set('_');
+ MARK.set('.');
+ MARK.set('!');
+ MARK.set('~');
+ MARK.set('*');
+ MARK.set('\'');
+ MARK.set('(');
+ MARK.set(')');
+ }
+
+ /**
+ * lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" |
+ * "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
+ */
+ public final static BitSet LOW_ALPHA = new BitSet();
+
+ static {
+ LOW_ALPHA.set('a');
+ LOW_ALPHA.set('b');
+ LOW_ALPHA.set('c');
+ LOW_ALPHA.set('d');
+ LOW_ALPHA.set('e');
+ LOW_ALPHA.set('f');
+ LOW_ALPHA.set('g');
+ LOW_ALPHA.set('h');
+ LOW_ALPHA.set('i');
+ LOW_ALPHA.set('j');
+ LOW_ALPHA.set('k');
+ LOW_ALPHA.set('l');
+ LOW_ALPHA.set('m');
+ LOW_ALPHA.set('n');
+ LOW_ALPHA.set('o');
+ LOW_ALPHA.set('p');
+ LOW_ALPHA.set('q');
+ LOW_ALPHA.set('r');
+ LOW_ALPHA.set('s');
+ LOW_ALPHA.set('t');
+ LOW_ALPHA.set('u');
+ LOW_ALPHA.set('v');
+ LOW_ALPHA.set('w');
+ LOW_ALPHA.set('x');
+ LOW_ALPHA.set('y');
+ LOW_ALPHA.set('z');
+ }
+
+ /**
+ * upalpha = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" |
+ * "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"
+ */
+ public final static BitSet UP_ALPHA = new BitSet();
+
+ static {
+ UP_ALPHA.set('A');
+ UP_ALPHA.set('B');
+ UP_ALPHA.set('C');
+ UP_ALPHA.set('D');
+ UP_ALPHA.set('E');
+ UP_ALPHA.set('F');
+ UP_ALPHA.set('G');
+ UP_ALPHA.set('H');
+ UP_ALPHA.set('I');
+ UP_ALPHA.set('J');
+ UP_ALPHA.set('K');
+ UP_ALPHA.set('L');
+ UP_ALPHA.set('M');
+ UP_ALPHA.set('N');
+ UP_ALPHA.set('O');
+ UP_ALPHA.set('P');
+ UP_ALPHA.set('Q');
+ UP_ALPHA.set('R');
+ UP_ALPHA.set('S');
+ UP_ALPHA.set('T');
+ UP_ALPHA.set('U');
+ UP_ALPHA.set('V');
+ UP_ALPHA.set('W');
+ UP_ALPHA.set('X');
+ UP_ALPHA.set('Y');
+ UP_ALPHA.set('Z');
+ }
+
+ /**
+ * alpha = lowalpha | upalpha
+ */
+ public final static BitSet ALPHA = new BitSet();
+
+ static {
+ ALPHA.or(LOW_ALPHA);
+ ALPHA.or(UP_ALPHA);
+ }
+
+ /**
+ * digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
+ */
+ public final static BitSet DIGIT = new BitSet();
+
+ static {
+ DIGIT.set('0');
+ DIGIT.set('1');
+ DIGIT.set('2');
+ DIGIT.set('3');
+ DIGIT.set('4');
+ DIGIT.set('5');
+ DIGIT.set('6');
+ DIGIT.set('7');
+ DIGIT.set('8');
+ DIGIT.set('9');
+ }
+
+ /**
+ * alphanum = alpha | digit
+ */
+ public final static BitSet ALPHANUM = new BitSet();
+
+ static {
+ ALPHANUM.or(ALPHA);
+ ALPHANUM.or(DIGIT);
+ }
+
+ /**
+ * unreserved = alphanum | mark
+ */
+ public final static BitSet UNRESERVED = new BitSet();
+
+ static {
+ UNRESERVED.or(ALPHANUM);
+ UNRESERVED.or(MARK);
+ }
+
+ /**
+ * pchar = unreserved | escaped | ":" | "@" | "&" | "=" | "+" | "$" | ","
+ *
+ * Note: we don't allow escaped here since we will escape it ourselves, so we don't want to allow them in the
+ * unescaped sequences
+ */
+ public final static BitSet PCHAR = new BitSet();
+
+ static {
+ PCHAR.or(UNRESERVED);
+ PCHAR.set(':');
+ PCHAR.set('@');
+ PCHAR.set('&');
+ PCHAR.set('=');
+ PCHAR.set('+');
+ PCHAR.set('$');
+ PCHAR.set(',');
+ }
+
+ /**
+ * Encodes a string to be a valid path parameter URL, which means it can contain PCHAR* only (do not put the leading
+ * ";" or it will be escaped.
+ *
+ */
+ public static String encodePathParam(final String pathParam, final String charset) throws UnsupportedEncodingException {
+ return encodePathSegment(pathParam, charset);
+ }
+
+ /**
+ * Encodes a string to be a valid path segment URL, which means it can contain PCHAR* only (do not put path
+ * parameters or they will be escaped.
+ *
+ */
+ public static String encodePathSegment(final String pathSegment, final String charset) throws UnsupportedEncodingException {
+ if (pathSegment == null) {
+ return null;
+ }
+ // start at *3 for the worst case when everything is %encoded on one byte
+ final StringBuffer encoded = new StringBuffer(pathSegment.length() * 3);
+ final char[] toEncode = pathSegment.toCharArray();
+ for (int i = 0; i < toEncode.length; i++) {
+ char c = toEncode[i];
+ if (PCHAR.get(c)) {
+ encoded.append(c);
+ } else {
+ final byte[] bytes = String.valueOf(c).getBytes(charset);
+ for (int j = 0; j < bytes.length; j++) {
+ byte b = bytes[j];
+ // make it unsigned
+ final int u8 = b & 0xFF;
+ encoded.append("%");
+ if (u8 < 16)
+ encoded.append("0");
+ encoded.append(Integer.toHexString(u8));
+ }
+ }
+ }
+ return encoded.toString();
+ }
+}
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardMatcher.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardMatcher.java
index 88953797..3b3d16e1 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardMatcher.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardMatcher.java
@@ -1,171 +1,171 @@
-/**
- * Copyright (c) 2005-2007, Paul Tuckey
- * All rights reserved.
- * ====================================================================
- * Licensed under the BSD License. Text as follows.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * - Neither the name tuckey.org nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- */
-package org.tuckey.web.filters.urlrewrite.utils;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Implements a regex like interface on top of WildcardMatcher, this is really just a convenience class
- * so that it's easier for us to program against regex and wildcard patterns.
- */
-public class WildcardMatcher implements StringMatchingMatcher {
-
- private static Log log = Log.getLog(WildcardMatcher.class);
-
-
- private WildcardHelper wh;
- private int[] compiledPattern;
- private String matchStr;
- private Map resultMap = new HashMap();
- private boolean found = false;
-
-
- public WildcardMatcher(WildcardHelper wh, String patternStr, String matchStr) {
- this.wh = wh;
- this.compiledPattern = wh.compilePattern(patternStr);
- this.matchStr = matchStr;
- }
-
- public boolean find() {
- found = wh.match(resultMap, matchStr, compiledPattern);
- return found;
- }
-
- public boolean isFound() {
- return found;
- }
-
- // the pattern for finding $1 $2 etc
- private static Pattern variablePattern = Pattern.compile("(? lastCondMatcherGroupCount) {
- log.error("variable $" + varInt + " not found");
- if (log.isDebugEnabled()) {
- log.debug("wildcard matcher: " + this.toString());
- }
- } else {
- validVariable = true;
- }
- } catch (NumberFormatException nfe) {
- log.error("could not parse variable " + varStr + " to number");
- }
- String conditionMatch = "";
- if (validVariable) {
- conditionMatch = this.group(varInt);
- }
- if (conditionMatch.contains("$")) {
- // ensure any remaining $'s in the matched string are escaped before appending the replacement
- conditionMatch = conditionMatch.replace("$", "\\$");
- }
- variableMatcher.appendReplacement(sb, conditionMatch);
- }
- variableMatcher.appendTail(sb);
- if (log.isDebugEnabled()) log.debug("replaced sb is " + sb);
- String result = sb.toString();
-
- Matcher escapedVariableMatcher = escapedVariablePattern.matcher(result);
- result = escapedVariableMatcher.replaceAll("$1");
-
- return result;
- }
-
- public int groupCount() {
- if (resultMap == null) return 0;
- return resultMap.size() == 0 ? 0 : resultMap.size() - 1;
- }
-
- public String group(int groupId) {
- if (resultMap == null) return null;
- return (String) resultMap.get("" + groupId);
- }
-
- public int end() {
- if(found)
- return matchStr.length();
- return -1;
- }
-
- public void reset() {
- }
-
- public int start() {
- if(found)
- return 0;
- return -1;
- }
-
- public boolean isMultipleMatchingSupported() {
- return false;
- }
-
- public String getMatchedString() {
- return matchStr;
- }
-
- @Override
- public boolean hitEnd() {
- return false;
- }
-
-}
+/**
+ * Copyright (c) 2005-2023, Paul Tuckey
+ * All rights reserved.
+ * ====================================================================
+ * Licensed under the BSD License. Text as follows.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Implements a regex like interface on top of WildcardMatcher, this is really just a convenience class
+ * so that it's easier for us to program against regex and wildcard patterns.
+ */
+public class WildcardMatcher implements StringMatchingMatcher {
+
+ private static Log log = Log.getLog(WildcardMatcher.class);
+
+
+ private WildcardHelper wh;
+ private int[] compiledPattern;
+ private String matchStr;
+ private Map resultMap = new HashMap();
+ private boolean found = false;
+
+
+ public WildcardMatcher(WildcardHelper wh, String patternStr, String matchStr) {
+ this.wh = wh;
+ this.compiledPattern = wh.compilePattern(patternStr);
+ this.matchStr = matchStr;
+ }
+
+ public boolean find() {
+ found = wh.match(resultMap, matchStr, compiledPattern);
+ return found;
+ }
+
+ public boolean isFound() {
+ return found;
+ }
+
+ // the pattern for finding $1 $2 etc
+ private static Pattern variablePattern = Pattern.compile("(? lastCondMatcherGroupCount) {
+ log.error("variable $" + varInt + " not found");
+ if (log.isDebugEnabled()) {
+ log.debug("wildcard matcher: " + this.toString());
+ }
+ } else {
+ validVariable = true;
+ }
+ } catch (NumberFormatException nfe) {
+ log.error("could not parse variable " + varStr + " to number");
+ }
+ String conditionMatch = "";
+ if (validVariable) {
+ conditionMatch = this.group(varInt);
+ }
+ if (conditionMatch.contains("$")) {
+ // ensure any remaining $'s in the matched string are escaped before appending the replacement
+ conditionMatch = conditionMatch.replace("$", "\\$");
+ }
+ variableMatcher.appendReplacement(sb, conditionMatch);
+ }
+ variableMatcher.appendTail(sb);
+ if (log.isDebugEnabled()) log.debug("replaced sb is " + sb);
+ String result = sb.toString();
+
+ Matcher escapedVariableMatcher = escapedVariablePattern.matcher(result);
+ result = escapedVariableMatcher.replaceAll("$1");
+
+ return result;
+ }
+
+ public int groupCount() {
+ if (resultMap == null) return 0;
+ return resultMap.size() == 0 ? 0 : resultMap.size() - 1;
+ }
+
+ public String group(int groupId) {
+ if (resultMap == null) return null;
+ return (String) resultMap.get("" + groupId);
+ }
+
+ public int end() {
+ if(found)
+ return matchStr.length();
+ return -1;
+ }
+
+ public void reset() {
+ }
+
+ public int start() {
+ if(found)
+ return 0;
+ return -1;
+ }
+
+ public boolean isMultipleMatchingSupported() {
+ return false;
+ }
+
+ public String getMatchedString() {
+ return matchStr;
+ }
+
+ @Override
+ public boolean hitEnd() {
+ return false;
+ }
+
+}
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardPattern.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardPattern.java
index 8b0f1515..21c1e5c4 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardPattern.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardPattern.java
@@ -1,55 +1,55 @@
-/**
- * Copyright (c) 2005-2007, Paul Tuckey
- * All rights reserved.
- * ====================================================================
- * Licensed under the BSD License. Text as follows.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * - Neither the name tuckey.org nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- */
-package org.tuckey.web.filters.urlrewrite.utils;
-
-/**
- *
- *
- */
-public class WildcardPattern implements StringMatchingPattern {
-
- WildcardHelper wh;
- private String patternStr;
-
- public WildcardPattern(String patternStr) {
- this.wh = new WildcardHelper();
- this.patternStr = patternStr;
- }
-
-
- public StringMatchingMatcher matcher(String matchStr) {
- return new WildcardMatcher(wh, patternStr, matchStr);
- }
-}
+/**
+ * Copyright (c) 2005-2023, Paul Tuckey
+ * All rights reserved.
+ * ====================================================================
+ * Licensed under the BSD License. Text as follows.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite.utils;
+
+/**
+ *
+ *
+ */
+public class WildcardPattern implements StringMatchingPattern {
+
+ WildcardHelper wh;
+ private String patternStr;
+
+ public WildcardPattern(String patternStr) {
+ this.wh = new WildcardHelper();
+ this.patternStr = patternStr;
+ }
+
+
+ public StringMatchingMatcher matcher(String matchStr) {
+ return new WildcardMatcher(wh, patternStr, matchStr);
+ }
+}
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/ConditionTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/ConditionTest.java
index 5814fd38..6874a888 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/ConditionTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/ConditionTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2005-2007, Paul Tuckey
+ * Copyright (c) 2005-2023, Paul Tuckey
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/ConfTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/ConfTest.java
index 2f2b367c..954183b2 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/ConfTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/ConfTest.java
@@ -1,147 +1,147 @@
-/**
- * Copyright (c) 2005-2007, Paul Tuckey
- * All rights reserved.
- * ====================================================================
- * Licensed under the BSD License. Text as follows.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * - Neither the name tuckey.org nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- */
-package org.tuckey.web.filters.urlrewrite;
-
-import junit.framework.TestCase;
-import org.tuckey.web.filters.urlrewrite.utils.Log;
-import org.tuckey.web.testhelper.MockServletContext;
-
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.util.List;
-
-
-/**
- * @author Paul Tuckey
- * @version $Revision: 44 $ $Date: 2006-11-02 12:29:14 +1300 (Thu, 02 Nov 2006) $
- */
-public class ConfTest extends TestCase {
-
- public static final String BASE_XML_PATH = "/org/tuckey/web/filters/urlrewrite/";
-
- public void setUp() {
- Log.setLevel("DEBUG");
- }
-
-
- public void testGoodNormalConf() throws FileNotFoundException {
- InputStream is = ConfTest.class.getResourceAsStream(BASE_XML_PATH + "conf-test1.xml");
- assertNotNull(is);
- Conf conf = new Conf(new MockServletContext(), is, "conf-test1.xml", "conf-test1.xml");
- assertTrue(conf.isOk());
- assertEquals("regex", conf.getDefaultMatchType());
- assertEquals(false, conf.isUseContext());
- assertEquals(false, conf.isUseQueryString());
- assertEquals("utf-8", conf.getDecodeUsing());
-
- List rules = conf.getRules();
- List outboundRules = conf.getOutboundRules();
- List catches = conf.getCatchElems();
-
- NormalRule rule = (NormalRule) rules.get(0);
- assertEquals("basicfrom1", rule.getFrom());
- assertEquals("basicto1", rule.getTo());
- assertFalse("rule 1 last not loading correctly", rule.isLast());
- assertEquals("forward", rule.getToType());
- assertEquals(false, rule.isEncodeToUrl());
- SetAttribute set = (SetAttribute) rule.getSetAttributes().get(0);
- assertEquals("name of set, it's " + set.getName(), "valuenull", set.getName());
- assertNull("value of set should be null, it's " + set.getValue(), set.getValue());
- assertEquals("othercontext", rule.getToContextStr());
-
- NormalRule rule1 = (NormalRule) rules.get(1);
- assertEquals("basicfrom2", rule1.getFrom());
- assertEquals("basicto2", rule1.getTo());
- assertTrue("rule 2 last not loading correctly", rule1.isLast());
- assertEquals("redirect", rule1.getToType());
- assertEquals("true", "" + rule1.isFromCaseSensitive());
- Condition cond = (Condition) rule1.getConditions().get(0);
- assertEquals("true", "" + cond.isCaseSensitive());
- assertEquals("greater", cond.getOperator());
-
- NormalRule rule2 = (NormalRule) rules.get(2);
- SetAttribute set2 = (SetAttribute) rule2.getSetAttributes().get(0);
- assertEquals("blah", set2.getName());
- assertEquals("$1", set2.getValue());
-
- ClassRule rule4 = (ClassRule) rules.get(4);
- assertEquals(true, rule4.isValid());
-
- ClassRule rule5 = (ClassRule) rules.get(5);
- assertEquals(true, rule5.isValid());
-
- NormalRule rule6 = (NormalRule) rules.get(6);
- Run run = (Run) rule6.getRuns().get(0);
- assertEquals("testValue", run.getInitParam("testName"));
-
- OutboundRule outboundRule = (OutboundRule) outboundRules.get(0);
- assertEquals("default encode on to test", outboundRule.getName());
- assertEquals(true, outboundRule.isEncodeToUrl());
-
- CatchElem catchElem = (CatchElem) catches.get(0);
- assertEquals(true, catchElem.isValid());
- }
-
-
- public void testNoDtdConf() throws FileNotFoundException {
- InputStream is = ConfTest.class.getResourceAsStream(BASE_XML_PATH + "conf-test-no-dtd.xml");
- assertNotNull(is);
- Conf conf = new Conf(is, "conf-test-no-dtd.xml");
- assertTrue(conf.isOk());
- assertFalse(conf.isDecodeUsingCustomCharsetRequired());
- }
-
- public void testConfDefaults() throws FileNotFoundException {
- System.out.println("testConfDefaults");
- Conf conf = new Conf(ConfTest.class.getResource("conf-test2.xml"));
- assertTrue("Conf should have loaded ok", conf.isOk());
- assertEquals("use context should be true", true, conf.isUseContext());
- assertEquals("use query string should be true", true, conf.isUseQueryString());
- assertEquals("utf-16", conf.getDecodeUsing());
- assertEquals("wildcard", conf.getDefaultMatchType());
- assertEquals("wildcard", ((NormalRule) conf.getRules().get(0)).getMatchType());
- assertEquals("regex", ((NormalRule) conf.getRules().get(1)).getMatchType());
- assertEquals("wildcard", ((NormalRule) conf.getRules().get(2)).getMatchType());
-
- assertEquals("Included Rule (rule 3)", ((Rule) conf.getRules().get(3)).getDisplayName());
- }
-
- public void testConfBadParse() throws FileNotFoundException {
- Conf conf = new Conf(ConfTest.class.getResource("conf-test-bad-parse.xml"));
- assertFalse("a validation error should make the conf fail to load", conf.isOk());
- }
-
-}
-
+/**
+ * Copyright (c) 2005-2023, Paul Tuckey
+ * All rights reserved.
+ * ====================================================================
+ * Licensed under the BSD License. Text as follows.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite;
+
+import junit.framework.TestCase;
+import org.tuckey.web.filters.urlrewrite.utils.Log;
+import org.tuckey.web.testhelper.MockServletContext;
+
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.List;
+
+
+/**
+ * @author Paul Tuckey
+ * @version $Revision: 44 $ $Date: 2006-11-02 12:29:14 +1300 (Thu, 02 Nov 2006) $
+ */
+public class ConfTest extends TestCase {
+
+ public static final String BASE_XML_PATH = "/org/tuckey/web/filters/urlrewrite/";
+
+ public void setUp() {
+ Log.setLevel("DEBUG");
+ }
+
+
+ public void testGoodNormalConf() throws FileNotFoundException {
+ InputStream is = ConfTest.class.getResourceAsStream(BASE_XML_PATH + "conf-test1.xml");
+ assertNotNull(is);
+ Conf conf = new Conf(new MockServletContext(), is, "conf-test1.xml", "conf-test1.xml");
+ assertTrue(conf.isOk());
+ assertEquals("regex", conf.getDefaultMatchType());
+ assertEquals(false, conf.isUseContext());
+ assertEquals(false, conf.isUseQueryString());
+ assertEquals("utf-8", conf.getDecodeUsing());
+
+ List rules = conf.getRules();
+ List outboundRules = conf.getOutboundRules();
+ List catches = conf.getCatchElems();
+
+ NormalRule rule = (NormalRule) rules.get(0);
+ assertEquals("basicfrom1", rule.getFrom());
+ assertEquals("basicto1", rule.getTo());
+ assertFalse("rule 1 last not loading correctly", rule.isLast());
+ assertEquals("forward", rule.getToType());
+ assertEquals(false, rule.isEncodeToUrl());
+ SetAttribute set = (SetAttribute) rule.getSetAttributes().get(0);
+ assertEquals("name of set, it's " + set.getName(), "valuenull", set.getName());
+ assertNull("value of set should be null, it's " + set.getValue(), set.getValue());
+ assertEquals("othercontext", rule.getToContextStr());
+
+ NormalRule rule1 = (NormalRule) rules.get(1);
+ assertEquals("basicfrom2", rule1.getFrom());
+ assertEquals("basicto2", rule1.getTo());
+ assertTrue("rule 2 last not loading correctly", rule1.isLast());
+ assertEquals("redirect", rule1.getToType());
+ assertEquals("true", "" + rule1.isFromCaseSensitive());
+ Condition cond = (Condition) rule1.getConditions().get(0);
+ assertEquals("true", "" + cond.isCaseSensitive());
+ assertEquals("greater", cond.getOperator());
+
+ NormalRule rule2 = (NormalRule) rules.get(2);
+ SetAttribute set2 = (SetAttribute) rule2.getSetAttributes().get(0);
+ assertEquals("blah", set2.getName());
+ assertEquals("$1", set2.getValue());
+
+ ClassRule rule4 = (ClassRule) rules.get(4);
+ assertEquals(true, rule4.isValid());
+
+ ClassRule rule5 = (ClassRule) rules.get(5);
+ assertEquals(true, rule5.isValid());
+
+ NormalRule rule6 = (NormalRule) rules.get(6);
+ Run run = (Run) rule6.getRuns().get(0);
+ assertEquals("testValue", run.getInitParam("testName"));
+
+ OutboundRule outboundRule = (OutboundRule) outboundRules.get(0);
+ assertEquals("default encode on to test", outboundRule.getName());
+ assertEquals(true, outboundRule.isEncodeToUrl());
+
+ CatchElem catchElem = (CatchElem) catches.get(0);
+ assertEquals(true, catchElem.isValid());
+ }
+
+
+ public void testNoDtdConf() throws FileNotFoundException {
+ InputStream is = ConfTest.class.getResourceAsStream(BASE_XML_PATH + "conf-test-no-dtd.xml");
+ assertNotNull(is);
+ Conf conf = new Conf(is, "conf-test-no-dtd.xml");
+ assertTrue(conf.isOk());
+ assertFalse(conf.isDecodeUsingCustomCharsetRequired());
+ }
+
+ public void testConfDefaults() throws FileNotFoundException {
+ System.out.println("testConfDefaults");
+ Conf conf = new Conf(ConfTest.class.getResource("conf-test2.xml"));
+ assertTrue("Conf should have loaded ok", conf.isOk());
+ assertEquals("use context should be true", true, conf.isUseContext());
+ assertEquals("use query string should be true", true, conf.isUseQueryString());
+ assertEquals("utf-16", conf.getDecodeUsing());
+ assertEquals("wildcard", conf.getDefaultMatchType());
+ assertEquals("wildcard", ((NormalRule) conf.getRules().get(0)).getMatchType());
+ assertEquals("regex", ((NormalRule) conf.getRules().get(1)).getMatchType());
+ assertEquals("wildcard", ((NormalRule) conf.getRules().get(2)).getMatchType());
+
+ assertEquals("Included Rule (rule 3)", ((Rule) conf.getRules().get(3)).getDisplayName());
+ }
+
+ public void testConfBadParse() throws FileNotFoundException {
+ Conf conf = new Conf(ConfTest.class.getResource("conf-test-bad-parse.xml"));
+ assertFalse("a validation error should make the conf fail to load", conf.isOk());
+ }
+
+}
+
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/OutboundRuleTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/OutboundRuleTest.java
index 771d2801..c95e8eb4 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/OutboundRuleTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/OutboundRuleTest.java
@@ -1,219 +1,219 @@
-/**
- * Copyright (c) 2005-2007, Paul Tuckey
- * All rights reserved.
- * ====================================================================
- * Licensed under the BSD License. Text as follows.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * - Neither the name tuckey.org nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- */
-package org.tuckey.web.filters.urlrewrite;
-
-import junit.framework.TestCase;
-import org.tuckey.web.filters.urlrewrite.utils.Log;
-import org.tuckey.web.testhelper.MockRequest;
-import org.tuckey.web.testhelper.MockResponse;
-
-/**
- * @author Paul Tuckey
- * @version $Revision: 52 $ $Date: 2007-02-26 07:00:28 +1300 (Mon, 26 Feb 2007) $
- */
-public class OutboundRuleTest extends TestCase {
-
- MockResponse response;
- MockRequest request;
-
- public void setUp() {
- Log.setLevel("DEBUG");
- response = new MockResponse();
- request = new MockRequest();
- }
-
-
- public void testOutboundQueryStr() {
- Conf conf = new Conf();
- OutboundRule rule1 = new OutboundRule();
- rule1.setFrom("^/jsp-examples/cal/links.jsp\\?id=([0-9]+)");
- rule1.setTo("/jsp-examples/cal/links/$1");
- conf.addOutboundRule(rule1);
- conf.initialise();
-
- UrlRewriter urlRewriter = new UrlRewriter(conf);
-
- MockRequest request = new MockRequest("/jsp-examples/cal/links.jsp?id=46");
- UrlRewriteWrappedResponse urlRewriteWrappedResponse = new UrlRewriteWrappedResponse(response, request, urlRewriter);
-
- assertEquals("/jsp-examples/cal/links/46;mockencoded=test", urlRewriteWrappedResponse.encodeURL("/jsp-examples/cal/links.jsp?id=46"));
-
- }
-
- public void testOutboundQueryStr2() {
- Conf conf = new Conf();
- OutboundRule rule1 = new OutboundRule();
- rule1.setFrom("^/storeitem.html\\?vid=20060621001&iid=([0-9]+)&cid=([0-9]+)$");
- rule1.setTo("/storeitem/id$1/c$2");
- conf.addOutboundRule(rule1);
- conf.initialise();
-
- UrlRewriter urlRewriter = new UrlRewriter(conf);
-
- UrlRewriteWrappedResponse urlRewriteWrappedResponse = new UrlRewriteWrappedResponse(response, request, urlRewriter);
- assertEquals("/storeitem/id666/c555;mockencoded=test", urlRewriteWrappedResponse.encodeURL("/storeitem.html?vid=20060621001&iid=666&cid=555"));
-
- }
-
- public void testOutboundQueryStr3() {
- Conf conf = new Conf();
- OutboundRule rule1 = new OutboundRule();
- rule1.setFrom("^/world\\.jsp\\?country=([a-z]+)&city=([a-z]+)$");
- rule1.setTo("/world/$1/$2");
- conf.addOutboundRule(rule1);
- conf.initialise();
-
- UrlRewriter urlRewriter = new UrlRewriter(conf);
-
- UrlRewriteWrappedResponse urlRewriteWrappedResponse = new UrlRewriteWrappedResponse(response, request, urlRewriter);
- assertEquals("/world/usa/nyc;mockencoded=test", urlRewriteWrappedResponse.encodeURL("/world.jsp?country=usa&city=nyc"));
-
- }
-
-
- public void testOutbound2() {
- // check mockencoded is being added
- UrlRewriteWrappedResponse urlRewriteWrappedResponse2 = new UrlRewriteWrappedResponse(response, request, null);
- assertEquals("a.jsp;mockencoded=test?aaa=bbb", urlRewriteWrappedResponse2.encodeURL("a.jsp?aaa=bbb"));
-
- // check we can strip it
- Conf conf = new Conf();
- OutboundRule rule1 = new OutboundRule();
- rule1.setFrom("^(.*);mockencoded=.*?(\\?.*)?$");
- rule1.setTo("$1$2");
- rule1.setEncodeFirst(true);
- conf.addOutboundRule(rule1);
- conf.initialise();
-
- UrlRewriter urlRewriter = new UrlRewriter(conf);
-
- UrlRewriteWrappedResponse urlRewriteWrappedResponse = new UrlRewriteWrappedResponse(response, request, urlRewriter);
- assertEquals("a.jsp?aaa=bbb", urlRewriteWrappedResponse.encodeURL("a.jsp?aaa=bbb"));
- assertEquals("a.jsp", urlRewriteWrappedResponse.encodeURL("a.jsp"));
- }
-
- /**
- * To: UrlRewrite
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/container-test/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java b/container-test/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java
index 5325c6e5..095df750 100644
--- a/container-test/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java
+++ b/container-test/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpITTest.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpITTest.java
index c6a512aa..14466c5a 100644
--- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpITTest.java
+++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpITTest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/CatchElem.java b/src/main/java/org/tuckey/web/filters/urlrewrite/CatchElem.java
index 512718e9..3bba790d 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/CatchElem.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/CatchElem.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/ClassRule.java b/src/main/java/org/tuckey/web/filters/urlrewrite/ClassRule.java
index 42af9269..cbd15efa 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/ClassRule.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/ClassRule.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/Condition.java b/src/main/java/org/tuckey/web/filters/urlrewrite/Condition.java
index 27a64256..45d72c2f 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/Condition.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/Condition.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/ConditionMatch.java b/src/main/java/org/tuckey/web/filters/urlrewrite/ConditionMatch.java
index e2b79c82..9fe18096 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/ConditionMatch.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/ConditionMatch.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/Conf.java b/src/main/java/org/tuckey/web/filters/urlrewrite/Conf.java
index 7b8068b3..f2852609 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/Conf.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/Conf.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/ConfHandler.java b/src/main/java/org/tuckey/web/filters/urlrewrite/ConfHandler.java
index 81a3e29c..f9065a72 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/ConfHandler.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/ConfHandler.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRewrittenUrl.java b/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRewrittenUrl.java
index b47492f4..884e0db6 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRewrittenUrl.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRewrittenUrl.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRule.java b/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRule.java
index ff8891d4..fdc4c0c2 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRule.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRule.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/OutboundRule.java b/src/main/java/org/tuckey/web/filters/urlrewrite/OutboundRule.java
index 98da38d7..9ca44845 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/OutboundRule.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/OutboundRule.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/RequestProxy.java b/src/main/java/org/tuckey/web/filters/urlrewrite/RequestProxy.java
index 663c5408..9ef65d94 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/RequestProxy.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/RequestProxy.java
@@ -1,337 +1,337 @@
-/**
- * Copyright (c) 2008, Paul Tuckey
- * All rights reserved.
- * ====================================================================
- * Licensed under the BSD License. Text as follows.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * - Neither the name tuckey.org nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- */
-package org.tuckey.web.filters.urlrewrite;
-
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HostConfiguration;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.ProxyHost;
-import org.apache.commons.httpclient.SimpleHttpConnectionManager;
-import org.apache.commons.httpclient.methods.*;
-import org.tuckey.web.filters.urlrewrite.utils.Log;
-import org.tuckey.web.filters.urlrewrite.utils.StringUtils;
-
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Enumeration;
-
-/**
- * This class is responsible for a proxy http request.
- * It takes the incoming request and then it creates a new request to the target address and copies the response of that proxy request
- * to the response of the original request.
- *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.ProxyHost;
+import org.apache.commons.httpclient.SimpleHttpConnectionManager;
+import org.apache.commons.httpclient.methods.*;
+import org.tuckey.web.filters.urlrewrite.utils.Log;
+import org.tuckey.web.filters.urlrewrite.utils.StringUtils;
+
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+
+/**
+ * This class is responsible for a proxy http request.
+ * It takes the incoming request and then it creates a new request to the target address and copies the response of that proxy request
+ * to the response of the original request.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/RewrittenUrl.java b/src/main/java/org/tuckey/web/filters/urlrewrite/RewrittenUrl.java
index f58d7b98..53b471a4 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/RewrittenUrl.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/RewrittenUrl.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlClass.java b/src/main/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlClass.java
index 06d589ec..556833e9 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlClass.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlClass.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/Rule.java b/src/main/java/org/tuckey/web/filters/urlrewrite/Rule.java
index ed086b44..98641b10 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/Rule.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/Rule.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/RuleBase.java b/src/main/java/org/tuckey/web/filters/urlrewrite/RuleBase.java
index 2cc1f0f7..c063cec6 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/RuleBase.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/RuleBase.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/RuleChain.java b/src/main/java/org/tuckey/web/filters/urlrewrite/RuleChain.java
index 0010cd8c..bdadf6a2 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/RuleChain.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/RuleChain.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/RuleExecutionOutput.java b/src/main/java/org/tuckey/web/filters/urlrewrite/RuleExecutionOutput.java
index 9e2e5f7c..78419902 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/RuleExecutionOutput.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/RuleExecutionOutput.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/Run.java b/src/main/java/org/tuckey/web/filters/urlrewrite/Run.java
index 1c74647f..aeb8e298 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/Run.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/Run.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/RunConfig.java b/src/main/java/org/tuckey/web/filters/urlrewrite/RunConfig.java
index 5b070185..62dad115 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/RunConfig.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/RunConfig.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/Runnable.java b/src/main/java/org/tuckey/web/filters/urlrewrite/Runnable.java
index c8bdf9b8..51b539a6 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/Runnable.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/Runnable.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/SetAttribute.java b/src/main/java/org/tuckey/web/filters/urlrewrite/SetAttribute.java
index c0676353..186c54c7 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/SetAttribute.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/SetAttribute.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -309,16 +309,16 @@ public boolean initialise() {
/**
* takes a string a number expression and converts it to a long.
* syntax: number type
- *
+ *
* Valid examples: "1 day", "2 days", "1 hour", "1 hour 2 minutes", "34 months"
- *
+ *
* Any positive number is valid
- *
+ *
* Valid types are: years, months, weeks, days, hours, minutes, seconds
- *
+ *
* note, this syntax is a direct copy of mod_expires syntax
* http://httpd.apache.org/docs/2.0/mod/mod_expires.html
- *
+ *
* note, a year is calculated as 365.25 days and a month as 365.25 days divided by 12.
*/
protected long parseTimeValue(String parsingValue) {
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/Status.java b/src/main/java/org/tuckey/web/filters/urlrewrite/Status.java
index 83478566..5ce354a1 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/Status.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/Status.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/TypeConverter.java b/src/main/java/org/tuckey/web/filters/urlrewrite/TypeConverter.java
index 9502064e..2449f193 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/TypeConverter.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/TypeConverter.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteDocTask.java b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteDocTask.java
index 5394e4a3..9a995e99 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteDocTask.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteDocTask.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteFilter.java b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteFilter.java
index cb90909b..1a4de935 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteFilter.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteFilter.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteServlet.java b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteServlet.java
index 3b11327f..8cf40b80 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteServlet.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteServlet.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -52,7 +52,7 @@
* Servlet for use if you cannot load filters in your environment for some strange reason. This will
* work very differently from the filter (obviously), but it can be used for "run" items where there
* is no "to".
- *
+ *
* This servlet just loads an instance of the filter and calls it as if it were the container.
*/
public class UrlRewriteServlet extends HttpServlet {
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedRequest.java b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedRequest.java
index 0d38481d..8ea8edce 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedRequest.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedRequest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedResponse.java b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedResponse.java
index 33629c7d..4a99a2d0 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedResponse.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedResponse.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriter.java b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriter.java
index 2aa878cb..6d93aa07 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriter.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriter.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteMatch.java b/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteMatch.java
index 211b0aa5..1873be10 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteMatch.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteMatch.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -56,7 +56,7 @@ public String getMatchingUrl() {
/**
* If this rule has been matched and has not been "stolen" by another rule then process the request.
- *
+ *
* If you return true then the filter chain will NOT continue.
*
* @return boolean true if the request was rewritten, false if not.
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteRule.java b/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteRule.java
index ee0a0142..9e02cde3 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteRule.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteRule.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/FilterServletOutputStream.java b/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/FilterServletOutputStream.java
index a7bcfa75..cafd2170 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/FilterServletOutputStream.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/FilterServletOutputStream.java
@@ -3,16 +3,16 @@
/**
* Modified version of:
* http://svn.terracotta.org/svn/ehcache/trunk/web/web/src/main/java/net/sf/ehcache/constructs/web/filter/FilterServletOutputStream.java
- *
+ *
*
* Copyright 2003-2009 Terracotta, Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/GenericResponseWrapper.java b/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/GenericResponseWrapper.java
index 9cb11ccc..90b03a34 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/GenericResponseWrapper.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/GenericResponseWrapper.java
@@ -3,16 +3,16 @@
/**
* Modified version of:
* http://svn.terracotta.org/svn/ehcache/trunk/web/web/src/main/java/net/sf/ehcache/constructs/web/GenericResponseWrapper.java
- *
+ *
*
* Copyright 2003-2009 Terracotta, Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/GzipFilter.java b/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/GzipFilter.java
index 3ead9fc0..18c594cf 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/GzipFilter.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/GzipFilter.java
@@ -3,15 +3,15 @@
/**
* Modified version of:
* http://svn.terracotta.org/svn/ehcache/trunk/web/web/src/main/java/net/sf/ehcache/constructs/web/filter/GzipFilter.java
- *
+ *
* Copyright 2003-2009 Terracotta, Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/ResponseUtil.java b/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/ResponseUtil.java
index a128e241..eb562beb 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/ResponseUtil.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/ResponseUtil.java
@@ -3,16 +3,16 @@
/**
* Modified version of:
* http://svn.terracotta.org/svn/ehcache/trunk/web/web/src/main/java/net/sf/ehcache/constructs/web/ResponseUtil.java
- *
+ *
*
* Copyright 2003-2009 Terracotta, Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/json/JsonRewriteMatch.java b/src/main/java/org/tuckey/web/filters/urlrewrite/json/JsonRewriteMatch.java
index 051f65d1..73595016 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/json/JsonRewriteMatch.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/json/JsonRewriteMatch.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteMatch.java b/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteMatch.java
index 7be22824..8fb8ccc6 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteMatch.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteMatch.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteRule.java b/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteRule.java
index 9de0a9d7..c5496c05 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteRule.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteRule.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/BackReferenceReplacer.java b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/BackReferenceReplacer.java
index f875bf81..094eeb7a 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/BackReferenceReplacer.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/BackReferenceReplacer.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/FunctionReplacer.java b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/FunctionReplacer.java
index 3688af69..519d2dc2 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/FunctionReplacer.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/FunctionReplacer.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/MatcherReplacer.java b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/MatcherReplacer.java
index d5bdfde7..8e763d8a 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/MatcherReplacer.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/MatcherReplacer.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/PatternReplacer.java b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/PatternReplacer.java
index e35a7f6d..8fe0ad26 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/PatternReplacer.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/PatternReplacer.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/UnescapeReplacer.java b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/UnescapeReplacer.java
index 45130ffa..f3eb94b3 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/UnescapeReplacer.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/UnescapeReplacer.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/VariableReplacer.java b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/VariableReplacer.java
index ab6eda6c..fa0b1dc3 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/VariableReplacer.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/VariableReplacer.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/Log.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/Log.java
index 7cf9230a..31227a6a 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/Log.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/Log.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/NumberUtils.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/NumberUtils.java
index ea31957b..ed6e7b92 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/NumberUtils.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/NumberUtils.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/RegexMatcher.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/RegexMatcher.java
index 5925991c..78db6a22 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/RegexMatcher.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/RegexMatcher.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/RegexPattern.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/RegexPattern.java
index dae84de4..25743744 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/RegexPattern.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/RegexPattern.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/ServerNameMatcher.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/ServerNameMatcher.java
index 795f68e5..b1b53510 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/ServerNameMatcher.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/ServerNameMatcher.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingMatcher.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingMatcher.java
index 11497f13..aac0e6bf 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingMatcher.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingMatcher.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingPattern.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingPattern.java
index 54af487f..4346a333 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingPattern.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingPattern.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingPatternSyntaxException.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingPatternSyntaxException.java
index f20c7db0..90164acc 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingPatternSyntaxException.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingPatternSyntaxException.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringUtils.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringUtils.java
index 1035adea..1bc2b981 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringUtils.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/StringUtils.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/URLEncoder.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/URLEncoder.java
index c9a20dd7..173c413f 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/URLEncoder.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/URLEncoder.java
@@ -182,7 +182,7 @@ public class URLEncoder {
/**
* pchar = unreserved | escaped | ":" | "@" | "&" | "=" | "+" | "$" | ","
- *
+ *
* Note: we don't allow escaped here since we will escape it ourselves, so we don't want to allow them in the
* unescaped sequences
*/
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardHelper.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardHelper.java
index 66366a04..86c7e83b 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardHelper.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardHelper.java
@@ -1,422 +1,422 @@
-/**
- * This class is a modified version of one found in Apache Cocoon.
- *
- * Copyright 2003-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.tuckey.web.filters.urlrewrite.utils;
-
-
-import java.util.Map;
-
-/**
- * This class is an utility class that perform wilcard-patterns matching and
- * isolation taken from Apache Cocoon.
- *
- * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $
- */
-public class WildcardHelper {
-
- /**
- * The int representing '*' in the pattern
+ * Copyright 2003-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.tuckey.web.filters.urlrewrite.utils;
+
+
+import java.util.Map;
+
+/**
+ * This class is an utility class that perform wilcard-patterns matching and
+ * isolation taken from Apache Cocoon.
+ *
+ * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $
+ */
+public class WildcardHelper {
+
+ /**
+ * The int representing '*' in the pattern
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardPattern.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardPattern.java
index 21c1e5c4..903fe20f 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardPattern.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardPattern.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/ConfTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/ConfTest.java
index 954183b2..297a6f90 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/ConfTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/ConfTest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/OutboundRuleTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/OutboundRuleTest.java
index c95e8eb4..f9c950e7 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/OutboundRuleTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/OutboundRuleTest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlTest.java
index 2ad2455d..ad59eb87 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlTest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/RuleTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/RuleTest.java
index 4aa47580..a0a69aa2 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/RuleTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/RuleTest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/RunTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/RunTest.java
index a7272fc1..b60c9e13 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/RunTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/RunTest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/SetAttributeTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/SetAttributeTest.java
index 6d79b71d..eb6bf2b0 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/SetAttributeTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/SetAttributeTest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/StatusTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/StatusTest.java
index 157a9c33..4649f6fd 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/StatusTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/StatusTest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/TestRewriteMatch.java b/src/test/java/org/tuckey/web/filters/urlrewrite/TestRewriteMatch.java
index 95255c79..01ecdd30 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/TestRewriteMatch.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/TestRewriteMatch.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/TestRuleObj.java b/src/test/java/org/tuckey/web/filters/urlrewrite/TestRuleObj.java
index aef0a02c..771e93da 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/TestRuleObj.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/TestRuleObj.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/TestServlet.java b/src/test/java/org/tuckey/web/filters/urlrewrite/TestServlet.java
index 86462a58..f28be40c 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/TestServlet.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/TestServlet.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/UrlDecoderTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/UrlDecoderTest.java
index 914a73db..e2b9faf8 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/UrlDecoderTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/UrlDecoderTest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriteFilterTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriteFilterTest.java
index 2262c130..645305bd 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriteFilterTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriteFilterTest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriteTestCaseTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriteTestCaseTest.java
index adede1f8..cc23f0b8 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriteTestCaseTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriteTestCaseTest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedResponseTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedResponseTest.java
index 28dcf3c4..caf27b81 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedResponseTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedResponseTest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriterTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriterTest.java
index 83ad802b..45352f18 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriterTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriterTest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/json/JsonRewriteMatchTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/json/JsonRewriteMatchTest.java
index 304e0783..7892cc9e 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/json/JsonRewriteMatchTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/json/JsonRewriteMatchTest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/test/MockRequestParser.java b/src/test/java/org/tuckey/web/filters/urlrewrite/test/MockRequestParser.java
index 0d847af2..0d7d1b77 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/test/MockRequestParser.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/test/MockRequestParser.java
@@ -1,128 +1,128 @@
-package org.tuckey.web.filters.urlrewrite.test;
-
-import org.tuckey.web.filters.urlrewrite.utils.Log;
-import org.tuckey.web.filters.urlrewrite.utils.StringUtils;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * todo: IN PROGRESS
- *
- * Class to decode a request from one of three inputs. Literally:
- *
- * /blah.jsp
- *
- * or
- *
- * GET /blah.jsp HTTP/1.1
- *
- * or
- *
- * GET /blah.jsp HTTP/1.1
- * user-agent: Mozilla 1.2.3
- * cookie: a:aaa
- *
- */
-public class MockRequestParser {
-
- private static Log log = Log.getLog(MockRequestParser.class);
-
- public MockRequest decodeRequest(String requestString) {
- return decodeRequest(requestString.split("\n"));
- }
-
- Pattern FIRST_LINE_PATTERN = Pattern.compile("^([A-Z]+) (.*) ([A-Z0-9/\\.]+)$");
-
- public MockRequest decodeRequest(String[] requestLines) {
- MockRequest request = new MockRequest();
- request.setRemoteAddr("127.0.0.1");
- request.setRemoteHost("localhost");
-
- String line1 = requestLines[0];
- Matcher line1Matcher = FIRST_LINE_PATTERN.matcher(line1);
-
- String requestPart;
- if (line1Matcher.matches()) {
- request.setMethod(line1Matcher.group(1));
- requestPart = line1Matcher.group(2);
- request.setScheme(line1Matcher.group(3));
- } else {
- requestPart = line1;
- }
-
- String requestUri = requestPart;
- int questionMarkIdx = requestPart.indexOf('?');
- if (questionMarkIdx != -1) {
- String queryString = requestPart.substring(questionMarkIdx + 1);
- setParams(request, queryString);
- requestUri = requestPart.substring(0, questionMarkIdx);
- }
- int semiColonIdx = requestUri.indexOf(';');
- if (semiColonIdx != -1) {
- String sessionId = requestUri.substring(semiColonIdx + 1);
- int equalsIdx = sessionId.indexOf('=');
- if ( equalsIdx != -1 ) {
- sessionId = sessionId.substring(equalsIdx+1);
- }
- request.setRequestedSessionId(sessionId);
- requestUri = requestUri.substring(0, semiColonIdx);
- }
- request.setRequestURI(requestUri);
-
- if (requestLines.length > 1) {
- boolean parsingBody = false;
- for (int i = 0; i < requestLines.length; i++) {
- if (i == 0) continue;
- String line = requestLines[i];
- if (!parsingBody) {
- if (line.length() == 0) {
- parsingBody = true;
- continue;
- }
- int colonIdx = line.indexOf(':');
- if (colonIdx < 1) {
- log.debug("cannot parse line " + line);
- continue;
- }
- String headerName = StringUtils.trimToNull(line.substring(0, colonIdx));
- String headerValue = StringUtils.trimToNull(line.substring(colonIdx + 1));
- if (headerName == null) {
- log.debug("cannot parse line " + line);
- continue;
- }
- request.setHeader(headerName, headerValue);
- if ("host".equals(headerName.toLowerCase())) {
- request.setServerName(headerValue);
- }
- } else {
- setParams(request, line);
- }
- }
- }
- return request;
- }
-
- private void setParams(MockRequest request, String queryString) {
- request.setQueryString(queryString);
- if (queryString.indexOf('&') != -1) {
- String[] paramSets = queryString.split("&");
- for (int i = 0; i < paramSets.length; i++) {
- addParamSet(request, paramSets[i]);
- }
- } else {
- addParamSet(request, queryString);
- }
- }
-
- private void addParamSet(MockRequest request, String paramSet) {
- if (paramSet.indexOf("=") != -1) {
- String[] nameVal = paramSet.split("=", 2);
- request.addParameter(nameVal[0], nameVal[1]);
- } else {
- log.info("cannot find value of request parameter " + paramSet);
- }
- }
-
-
-}
+package org.tuckey.web.filters.urlrewrite.test;
+
+import org.tuckey.web.filters.urlrewrite.utils.Log;
+import org.tuckey.web.filters.urlrewrite.utils.StringUtils;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * todo: IN PROGRESS
+ *
+ * Class to decode a request from one of three inputs. Literally:
+ *
+ * /blah.jsp
+ *
+ * or
+ *
+ * GET /blah.jsp HTTP/1.1
+ *
+ * or
+ *
+ * GET /blah.jsp HTTP/1.1
+ * user-agent: Mozilla 1.2.3
+ * cookie: a:aaa
+ *
+ */
+public class MockRequestParser {
+
+ private static Log log = Log.getLog(MockRequestParser.class);
+
+ public MockRequest decodeRequest(String requestString) {
+ return decodeRequest(requestString.split("\n"));
+ }
+
+ Pattern FIRST_LINE_PATTERN = Pattern.compile("^([A-Z]+) (.*) ([A-Z0-9/\\.]+)$");
+
+ public MockRequest decodeRequest(String[] requestLines) {
+ MockRequest request = new MockRequest();
+ request.setRemoteAddr("127.0.0.1");
+ request.setRemoteHost("localhost");
+
+ String line1 = requestLines[0];
+ Matcher line1Matcher = FIRST_LINE_PATTERN.matcher(line1);
+
+ String requestPart;
+ if (line1Matcher.matches()) {
+ request.setMethod(line1Matcher.group(1));
+ requestPart = line1Matcher.group(2);
+ request.setScheme(line1Matcher.group(3));
+ } else {
+ requestPart = line1;
+ }
+
+ String requestUri = requestPart;
+ int questionMarkIdx = requestPart.indexOf('?');
+ if (questionMarkIdx != -1) {
+ String queryString = requestPart.substring(questionMarkIdx + 1);
+ setParams(request, queryString);
+ requestUri = requestPart.substring(0, questionMarkIdx);
+ }
+ int semiColonIdx = requestUri.indexOf(';');
+ if (semiColonIdx != -1) {
+ String sessionId = requestUri.substring(semiColonIdx + 1);
+ int equalsIdx = sessionId.indexOf('=');
+ if ( equalsIdx != -1 ) {
+ sessionId = sessionId.substring(equalsIdx+1);
+ }
+ request.setRequestedSessionId(sessionId);
+ requestUri = requestUri.substring(0, semiColonIdx);
+ }
+ request.setRequestURI(requestUri);
+
+ if (requestLines.length > 1) {
+ boolean parsingBody = false;
+ for (int i = 0; i < requestLines.length; i++) {
+ if (i == 0) continue;
+ String line = requestLines[i];
+ if (!parsingBody) {
+ if (line.length() == 0) {
+ parsingBody = true;
+ continue;
+ }
+ int colonIdx = line.indexOf(':');
+ if (colonIdx < 1) {
+ log.debug("cannot parse line " + line);
+ continue;
+ }
+ String headerName = StringUtils.trimToNull(line.substring(0, colonIdx));
+ String headerValue = StringUtils.trimToNull(line.substring(colonIdx + 1));
+ if (headerName == null) {
+ log.debug("cannot parse line " + line);
+ continue;
+ }
+ request.setHeader(headerName, headerValue);
+ if ("host".equals(headerName.toLowerCase())) {
+ request.setServerName(headerValue);
+ }
+ } else {
+ setParams(request, line);
+ }
+ }
+ }
+ return request;
+ }
+
+ private void setParams(MockRequest request, String queryString) {
+ request.setQueryString(queryString);
+ if (queryString.indexOf('&') != -1) {
+ String[] paramSets = queryString.split("&");
+ for (int i = 0; i < paramSets.length; i++) {
+ addParamSet(request, paramSets[i]);
+ }
+ } else {
+ addParamSet(request, queryString);
+ }
+ }
+
+ private void addParamSet(MockRequest request, String paramSet) {
+ if (paramSet.indexOf("=") != -1) {
+ String[] nameVal = paramSet.split("=", 2);
+ request.addParameter(nameVal[0], nameVal[1]);
+ } else {
+ log.info("cannot find value of request parameter " + paramSet);
+ }
+ }
+
+
+}
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/test/MockRewriteMatch.java b/src/test/java/org/tuckey/web/filters/urlrewrite/test/MockRewriteMatch.java
index 6a69bc18..c37a642b 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/test/MockRewriteMatch.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/test/MockRewriteMatch.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/test/TestRunObj.java b/src/test/java/org/tuckey/web/filters/urlrewrite/test/TestRunObj.java
index c88864dd..0caa9e13 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/test/TestRunObj.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/test/TestRunObj.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/utils/LogTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/utils/LogTest.java
index 6f2d250a..7a817a37 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/utils/LogTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/utils/LogTest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingMatcherTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingMatcherTest.java
index 6983dfa4..7f2a520f 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingMatcherTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/utils/StringMatchingMatcherTest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/testhelper/BenchmarkRunner.java b/src/test/java/org/tuckey/web/testhelper/BenchmarkRunner.java
index a8b941ab..ca51e9ee 100644
--- a/src/test/java/org/tuckey/web/testhelper/BenchmarkRunner.java
+++ b/src/test/java/org/tuckey/web/testhelper/BenchmarkRunner.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/testhelper/MockFilterChain.java b/src/test/java/org/tuckey/web/testhelper/MockFilterChain.java
index 2866f303..58135e1f 100644
--- a/src/test/java/org/tuckey/web/testhelper/MockFilterChain.java
+++ b/src/test/java/org/tuckey/web/testhelper/MockFilterChain.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/testhelper/MockFilterConfig.java b/src/test/java/org/tuckey/web/testhelper/MockFilterConfig.java
index 776c993c..33cda02c 100644
--- a/src/test/java/org/tuckey/web/testhelper/MockFilterConfig.java
+++ b/src/test/java/org/tuckey/web/testhelper/MockFilterConfig.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/testhelper/MockRequest.java b/src/test/java/org/tuckey/web/testhelper/MockRequest.java
index e412abaf..c3e07bd2 100644
--- a/src/test/java/org/tuckey/web/testhelper/MockRequest.java
+++ b/src/test/java/org/tuckey/web/testhelper/MockRequest.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/testhelper/MockRequestDispatcher.java b/src/test/java/org/tuckey/web/testhelper/MockRequestDispatcher.java
index f0baba09..4281a3e4 100644
--- a/src/test/java/org/tuckey/web/testhelper/MockRequestDispatcher.java
+++ b/src/test/java/org/tuckey/web/testhelper/MockRequestDispatcher.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
diff --git a/src/test/java/org/tuckey/web/testhelper/MockResponse.java b/src/test/java/org/tuckey/web/testhelper/MockResponse.java
index 661e4ac0..d5e9b04b 100644
--- a/src/test/java/org/tuckey/web/testhelper/MockResponse.java
+++ b/src/test/java/org/tuckey/web/testhelper/MockResponse.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
* - Neither the name tuckey.org nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
From c8931eaeb879cb58e38badae26ee37b20055c56b Mon Sep 17 00:00:00 2001
From: Paul Tuckey
- * <%=response.encodeURL("/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0?somethingloi=1")%>
- *
- * <%=response.encodeURL("http://localhost:8080/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0?somethingloi=1")%>
- *
- * with the following output
- *
- * /boo.jsp;jsessionid=93DDACD0EB60D0B6301008A262DC58E4?somethingloi=1
- * /boo.jsp?somethingloi=1
- * http://localhost:8080/boo.jsp?somethingloi=1
- *
- * The last 2 outputs, where I've manually included the session id give
- * the rewrite I want, but the other one won't - regardless of the
- * encodefirst setting.
- *
- * My thinking is that encodefirst="true" attribue isn't behaving as
- * expected.
- */
- public void testOutboundJsess() {
- // check mockencoded is being added
-
- UrlRewriteWrappedResponse urlRewriteWrappedResponse2 = new UrlRewriteWrappedResponse(response, request, null);
-
- assertEquals("/boo.jsp;mockencoded=test?somethingloi=1",
- urlRewriteWrappedResponse2.encodeURL("/boo.jsp?somethingloi=1"));
- assertEquals("/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0;mockencoded=test?somethingloi=1",
- urlRewriteWrappedResponse2.encodeURL("/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0?somethingloi=1"));
- assertEquals("http://localhost:8080/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0?somethingloi=1",
- urlRewriteWrappedResponse2.encodeURL("http://localhost:8080/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0?somethingloi=1"));
-
- // check we can strip it
- Conf conf = new Conf();
- OutboundRule rule1 = new OutboundRule();
- rule1.setFrom("^(?![a-z]+:)(.*);jsessionid=.*?([\\?|\\#].*)?$");
- rule1.setTo("$1$2");
- rule1.setEncodeFirst(true);
- conf.addOutboundRule(rule1);
- conf.initialise();
-
- UrlRewriter urlRewriter = new UrlRewriter(conf);
-
- UrlRewriteWrappedResponse urlRewriteWrappedResponse = new UrlRewriteWrappedResponse(response, request, urlRewriter);
-
- assertEquals("/boo.jsp;mockencoded=test",
- urlRewriteWrappedResponse.encodeURL("/boo.jsp"));
- assertEquals("/boo.jsp;mockencoded=test?somethingloi=1",
- urlRewriteWrappedResponse.encodeURL("/boo.jsp?somethingloi=1"));
- assertEquals("/boo.jsp?somethingloi=1",
- urlRewriteWrappedResponse.encodeURL("/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0?somethingloi=1"));
- assertEquals("http://localhost:8080/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0?somethingloi=1",
- urlRewriteWrappedResponse.encodeURL("http://localhost:8080/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0?somethingloi=1"));
-
- }
-
- //todo: test multiple outbound rules with encodefirst on and off
-
-
-
- public void testVarWithSpaces() {
- Conf conf = new Conf();
- OutboundRule rule1 = new OutboundRule();
- rule1.setFrom("browse.ac\\?countryCode=([a-z]+)&stateCode=([a-z])&city=([a-z\\s]+)$");
- rule1.setTo("%{context-path}/location/$1/$2/$3");
- conf.addOutboundRule(rule1);
- conf.initialise();
-
- UrlRewriter urlRewriter = new UrlRewriter(conf);
-
- MockRequest request = new MockRequest("/");
- UrlRewriteWrappedResponse urlRewriteWrappedResponse = new UrlRewriteWrappedResponse(response, request, urlRewriter);
-
- assertEquals("browse.ac;mockencoded=test?countryCode=US&stateCode=NY&city=New York", urlRewriteWrappedResponse.encodeURL("browse.ac?countryCode=US&stateCode=NY&city=New York"));
-
- }
-
-
-}
-
-// "^/dir/([\\&a-zA-Z0-9\\s\\+\\/\\%&]+).([a-zA-Z\\s\\+&\\/]+).([a-zA-Z\\s]{2,})$"
+/**
+ * Copyright (c) 2005-2023, Paul Tuckey
+ * All rights reserved.
+ * ====================================================================
+ * Licensed under the BSD License. Text as follows.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite;
+
+import junit.framework.TestCase;
+import org.tuckey.web.filters.urlrewrite.utils.Log;
+import org.tuckey.web.testhelper.MockRequest;
+import org.tuckey.web.testhelper.MockResponse;
+
+/**
+ * @author Paul Tuckey
+ * @version $Revision: 52 $ $Date: 2007-02-26 07:00:28 +1300 (Mon, 26 Feb 2007) $
+ */
+public class OutboundRuleTest extends TestCase {
+
+ MockResponse response;
+ MockRequest request;
+
+ public void setUp() {
+ Log.setLevel("DEBUG");
+ response = new MockResponse();
+ request = new MockRequest();
+ }
+
+
+ public void testOutboundQueryStr() {
+ Conf conf = new Conf();
+ OutboundRule rule1 = new OutboundRule();
+ rule1.setFrom("^/jsp-examples/cal/links.jsp\\?id=([0-9]+)");
+ rule1.setTo("/jsp-examples/cal/links/$1");
+ conf.addOutboundRule(rule1);
+ conf.initialise();
+
+ UrlRewriter urlRewriter = new UrlRewriter(conf);
+
+ MockRequest request = new MockRequest("/jsp-examples/cal/links.jsp?id=46");
+ UrlRewriteWrappedResponse urlRewriteWrappedResponse = new UrlRewriteWrappedResponse(response, request, urlRewriter);
+
+ assertEquals("/jsp-examples/cal/links/46;mockencoded=test", urlRewriteWrappedResponse.encodeURL("/jsp-examples/cal/links.jsp?id=46"));
+
+ }
+
+ public void testOutboundQueryStr2() {
+ Conf conf = new Conf();
+ OutboundRule rule1 = new OutboundRule();
+ rule1.setFrom("^/storeitem.html\\?vid=20060621001&iid=([0-9]+)&cid=([0-9]+)$");
+ rule1.setTo("/storeitem/id$1/c$2");
+ conf.addOutboundRule(rule1);
+ conf.initialise();
+
+ UrlRewriter urlRewriter = new UrlRewriter(conf);
+
+ UrlRewriteWrappedResponse urlRewriteWrappedResponse = new UrlRewriteWrappedResponse(response, request, urlRewriter);
+ assertEquals("/storeitem/id666/c555;mockencoded=test", urlRewriteWrappedResponse.encodeURL("/storeitem.html?vid=20060621001&iid=666&cid=555"));
+
+ }
+
+ public void testOutboundQueryStr3() {
+ Conf conf = new Conf();
+ OutboundRule rule1 = new OutboundRule();
+ rule1.setFrom("^/world\\.jsp\\?country=([a-z]+)&city=([a-z]+)$");
+ rule1.setTo("/world/$1/$2");
+ conf.addOutboundRule(rule1);
+ conf.initialise();
+
+ UrlRewriter urlRewriter = new UrlRewriter(conf);
+
+ UrlRewriteWrappedResponse urlRewriteWrappedResponse = new UrlRewriteWrappedResponse(response, request, urlRewriter);
+ assertEquals("/world/usa/nyc;mockencoded=test", urlRewriteWrappedResponse.encodeURL("/world.jsp?country=usa&city=nyc"));
+
+ }
+
+
+ public void testOutbound2() {
+ // check mockencoded is being added
+ UrlRewriteWrappedResponse urlRewriteWrappedResponse2 = new UrlRewriteWrappedResponse(response, request, null);
+ assertEquals("a.jsp;mockencoded=test?aaa=bbb", urlRewriteWrappedResponse2.encodeURL("a.jsp?aaa=bbb"));
+
+ // check we can strip it
+ Conf conf = new Conf();
+ OutboundRule rule1 = new OutboundRule();
+ rule1.setFrom("^(.*);mockencoded=.*?(\\?.*)?$");
+ rule1.setTo("$1$2");
+ rule1.setEncodeFirst(true);
+ conf.addOutboundRule(rule1);
+ conf.initialise();
+
+ UrlRewriter urlRewriter = new UrlRewriter(conf);
+
+ UrlRewriteWrappedResponse urlRewriteWrappedResponse = new UrlRewriteWrappedResponse(response, request, urlRewriter);
+ assertEquals("a.jsp?aaa=bbb", urlRewriteWrappedResponse.encodeURL("a.jsp?aaa=bbb"));
+ assertEquals("a.jsp", urlRewriteWrappedResponse.encodeURL("a.jsp"));
+ }
+
+ /**
+ * To: UrlRewrite
+ * <%=response.encodeURL("/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0?somethingloi=1")%>
+ *
+ * <%=response.encodeURL("http://localhost:8080/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0?somethingloi=1")%>
+ *
+ * with the following output
+ *
+ * /boo.jsp;jsessionid=93DDACD0EB60D0B6301008A262DC58E4?somethingloi=1
+ * /boo.jsp?somethingloi=1
+ * http://localhost:8080/boo.jsp?somethingloi=1
+ *
+ * The last 2 outputs, where I've manually included the session id give
+ * the rewrite I want, but the other one won't - regardless of the
+ * encodefirst setting.
+ *
+ * My thinking is that encodefirst="true" attribue isn't behaving as
+ * expected.
+ */
+ public void testOutboundJsess() {
+ // check mockencoded is being added
+
+ UrlRewriteWrappedResponse urlRewriteWrappedResponse2 = new UrlRewriteWrappedResponse(response, request, null);
+
+ assertEquals("/boo.jsp;mockencoded=test?somethingloi=1",
+ urlRewriteWrappedResponse2.encodeURL("/boo.jsp?somethingloi=1"));
+ assertEquals("/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0;mockencoded=test?somethingloi=1",
+ urlRewriteWrappedResponse2.encodeURL("/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0?somethingloi=1"));
+ assertEquals("http://localhost:8080/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0?somethingloi=1",
+ urlRewriteWrappedResponse2.encodeURL("http://localhost:8080/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0?somethingloi=1"));
+
+ // check we can strip it
+ Conf conf = new Conf();
+ OutboundRule rule1 = new OutboundRule();
+ rule1.setFrom("^(?![a-z]+:)(.*);jsessionid=.*?([\\?|\\#].*)?$");
+ rule1.setTo("$1$2");
+ rule1.setEncodeFirst(true);
+ conf.addOutboundRule(rule1);
+ conf.initialise();
+
+ UrlRewriter urlRewriter = new UrlRewriter(conf);
+
+ UrlRewriteWrappedResponse urlRewriteWrappedResponse = new UrlRewriteWrappedResponse(response, request, urlRewriter);
+
+ assertEquals("/boo.jsp;mockencoded=test",
+ urlRewriteWrappedResponse.encodeURL("/boo.jsp"));
+ assertEquals("/boo.jsp;mockencoded=test?somethingloi=1",
+ urlRewriteWrappedResponse.encodeURL("/boo.jsp?somethingloi=1"));
+ assertEquals("/boo.jsp?somethingloi=1",
+ urlRewriteWrappedResponse.encodeURL("/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0?somethingloi=1"));
+ assertEquals("http://localhost:8080/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0?somethingloi=1",
+ urlRewriteWrappedResponse.encodeURL("http://localhost:8080/boo.jsp;jsessionid=91C4977F91B3CF69D2085B1B42BD5EB0?somethingloi=1"));
+
+ }
+
+ //todo: test multiple outbound rules with encodefirst on and off
+
+
+
+ public void testVarWithSpaces() {
+ Conf conf = new Conf();
+ OutboundRule rule1 = new OutboundRule();
+ rule1.setFrom("browse.ac\\?countryCode=([a-z]+)&stateCode=([a-z])&city=([a-z\\s]+)$");
+ rule1.setTo("%{context-path}/location/$1/$2/$3");
+ conf.addOutboundRule(rule1);
+ conf.initialise();
+
+ UrlRewriter urlRewriter = new UrlRewriter(conf);
+
+ MockRequest request = new MockRequest("/");
+ UrlRewriteWrappedResponse urlRewriteWrappedResponse = new UrlRewriteWrappedResponse(response, request, urlRewriter);
+
+ assertEquals("browse.ac;mockencoded=test?countryCode=US&stateCode=NY&city=New York", urlRewriteWrappedResponse.encodeURL("browse.ac?countryCode=US&stateCode=NY&city=New York"));
+
+ }
+
+
+}
+
+// "^/dir/([\\&a-zA-Z0-9\\s\\+\\/\\%&]+).([a-zA-Z\\s\\+&\\/]+).([a-zA-Z\\s]{2,})$"
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlTest.java
index 69d62316..2ad2455d 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlTest.java
@@ -1,128 +1,128 @@
-/**
- * Copyright (c) 2005-2007, Paul Tuckey
- * All rights reserved.
- * ====================================================================
- * Licensed under the BSD License. Text as follows.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * - Neither the name tuckey.org nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- */
-package org.tuckey.web.filters.urlrewrite;
-
-import junit.framework.TestCase;
-import org.tuckey.web.filters.urlrewrite.utils.Log;
-import org.tuckey.web.testhelper.MockFilterChain;
-import org.tuckey.web.testhelper.MockRequest;
-import org.tuckey.web.testhelper.MockRequestDispatcher;
-import org.tuckey.web.testhelper.MockResponse;
-
-import jakarta.servlet.ServletException;
-import jakarta.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-/**
- * @author Paul Tuckey
- * @version $Revision: 40 $ $Date: 2006-10-27 15:12:37 +1300 (Fri, 27 Oct 2006) $
- */
-public class RewrittenUrlTest extends TestCase {
-
- MockResponse response;
- MockRequest request;
- MockFilterChain chain;
-
- public void setUp() {
- Log.setLevel("SYSOUT:TRACE");
- response = new MockResponse();
- request = new MockRequest();
- chain = new MockFilterChain();
- }
-
- public void testPermanentRedir() throws IOException, ServletException {
- NormalRewrittenUrl rewrittenUrl = new NormalRewrittenUrl("/hi");
- rewrittenUrl.setPermanentRedirect(true);
- rewrittenUrl.doRewrite(request, response, chain);
- assertEquals("/hi", response.getHeader("Location"));
- assertEquals(HttpServletResponse.SC_MOVED_PERMANENTLY, response.getStatus());
- }
-
- public void testTempRedir() throws IOException, ServletException {
- NormalRewrittenUrl rewrittenUrl = new NormalRewrittenUrl("/hi");
- rewrittenUrl.setTemporaryRedirect(true);
- rewrittenUrl.doRewrite(request, response, chain);
- assertEquals("/hi", response.getHeader("Location"));
- assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus());
- }
-
- public void testForward() throws IOException, ServletException {
- NormalRewrittenUrl rewrittenUrl = new NormalRewrittenUrl("/hi");
- rewrittenUrl.setForward(true);
- rewrittenUrl.doRewrite(request, response, chain);
- assertEquals("/hi", MockRequestDispatcher.getCurrent().getUrl());
- assertTrue(MockRequestDispatcher.getCurrent().isForwarded());
- }
-
- public void testRedir() throws IOException, ServletException {
- NormalRewrittenUrl rewrittenUrl = new NormalRewrittenUrl("/hi");
- rewrittenUrl.setRedirect(true);
- rewrittenUrl.doRewrite(request, response, chain);
- assertEquals("/hi", response.getRedirectedUrl());
- }
-
- public void testRedirEncoded() throws IOException, ServletException {
- NormalRewrittenUrl rewrittenUrl = new NormalRewrittenUrl("/hi");
- rewrittenUrl.setRedirect(true);
- rewrittenUrl.setEncode(true);
- rewrittenUrl.doRewrite(request, response, chain);
- assertEquals("/hi;mockencoded=test", response.getRedirectedUrl());
- }
-
- public void testPreIncl() throws IOException, ServletException {
- NormalRewrittenUrl rewrittenUrl = new NormalRewrittenUrl("/hi");
- rewrittenUrl.setPreInclude(true);
- rewrittenUrl.setEncode(true);
- rewrittenUrl.doRewrite(request, response, chain);
- assertTrue(MockRequestDispatcher.getCurrent().isIncluded() && chain.isDoFilterRun());
- }
-
- public void testPostIncl() throws IOException, ServletException {
- NormalRewrittenUrl rewrittenUrl = new NormalRewrittenUrl("/hi");
- rewrittenUrl.setPostInclude(true);
- rewrittenUrl.setEncode(true);
- rewrittenUrl.doRewrite(request, response, chain);
- assertTrue(MockRequestDispatcher.getCurrent().isIncluded() && chain.isDoFilterRun());
- System.out.println("time diff: " + (MockRequestDispatcher.getCurrent().getIncludeLastCalled() - chain.getTimeInvoked()) + "ms" );
- assertTrue(chain.getTimeInvoked() < MockRequestDispatcher.getCurrent().getIncludeLastCalled());
- }
-
- public void testNoSubstitution() throws IOException, ServletException {
- NormalRewrittenUrl rewrittenUrl = new NormalRewrittenUrl("/hi");
- rewrittenUrl.setNoSubstitution(true);
- assertFalse(rewrittenUrl.doRewrite(request, response, chain));
- }
-
-}
+/**
+ * Copyright (c) 2005-2023, Paul Tuckey
+ * All rights reserved.
+ * ====================================================================
+ * Licensed under the BSD License. Text as follows.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * - Neither the name tuckey.org nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package org.tuckey.web.filters.urlrewrite;
+
+import junit.framework.TestCase;
+import org.tuckey.web.filters.urlrewrite.utils.Log;
+import org.tuckey.web.testhelper.MockFilterChain;
+import org.tuckey.web.testhelper.MockRequest;
+import org.tuckey.web.testhelper.MockRequestDispatcher;
+import org.tuckey.web.testhelper.MockResponse;
+
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * @author Paul Tuckey
+ * @version $Revision: 40 $ $Date: 2006-10-27 15:12:37 +1300 (Fri, 27 Oct 2006) $
+ */
+public class RewrittenUrlTest extends TestCase {
+
+ MockResponse response;
+ MockRequest request;
+ MockFilterChain chain;
+
+ public void setUp() {
+ Log.setLevel("SYSOUT:TRACE");
+ response = new MockResponse();
+ request = new MockRequest();
+ chain = new MockFilterChain();
+ }
+
+ public void testPermanentRedir() throws IOException, ServletException {
+ NormalRewrittenUrl rewrittenUrl = new NormalRewrittenUrl("/hi");
+ rewrittenUrl.setPermanentRedirect(true);
+ rewrittenUrl.doRewrite(request, response, chain);
+ assertEquals("/hi", response.getHeader("Location"));
+ assertEquals(HttpServletResponse.SC_MOVED_PERMANENTLY, response.getStatus());
+ }
+
+ public void testTempRedir() throws IOException, ServletException {
+ NormalRewrittenUrl rewrittenUrl = new NormalRewrittenUrl("/hi");
+ rewrittenUrl.setTemporaryRedirect(true);
+ rewrittenUrl.doRewrite(request, response, chain);
+ assertEquals("/hi", response.getHeader("Location"));
+ assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus());
+ }
+
+ public void testForward() throws IOException, ServletException {
+ NormalRewrittenUrl rewrittenUrl = new NormalRewrittenUrl("/hi");
+ rewrittenUrl.setForward(true);
+ rewrittenUrl.doRewrite(request, response, chain);
+ assertEquals("/hi", MockRequestDispatcher.getCurrent().getUrl());
+ assertTrue(MockRequestDispatcher.getCurrent().isForwarded());
+ }
+
+ public void testRedir() throws IOException, ServletException {
+ NormalRewrittenUrl rewrittenUrl = new NormalRewrittenUrl("/hi");
+ rewrittenUrl.setRedirect(true);
+ rewrittenUrl.doRewrite(request, response, chain);
+ assertEquals("/hi", response.getRedirectedUrl());
+ }
+
+ public void testRedirEncoded() throws IOException, ServletException {
+ NormalRewrittenUrl rewrittenUrl = new NormalRewrittenUrl("/hi");
+ rewrittenUrl.setRedirect(true);
+ rewrittenUrl.setEncode(true);
+ rewrittenUrl.doRewrite(request, response, chain);
+ assertEquals("/hi;mockencoded=test", response.getRedirectedUrl());
+ }
+
+ public void testPreIncl() throws IOException, ServletException {
+ NormalRewrittenUrl rewrittenUrl = new NormalRewrittenUrl("/hi");
+ rewrittenUrl.setPreInclude(true);
+ rewrittenUrl.setEncode(true);
+ rewrittenUrl.doRewrite(request, response, chain);
+ assertTrue(MockRequestDispatcher.getCurrent().isIncluded() && chain.isDoFilterRun());
+ }
+
+ public void testPostIncl() throws IOException, ServletException {
+ NormalRewrittenUrl rewrittenUrl = new NormalRewrittenUrl("/hi");
+ rewrittenUrl.setPostInclude(true);
+ rewrittenUrl.setEncode(true);
+ rewrittenUrl.doRewrite(request, response, chain);
+ assertTrue(MockRequestDispatcher.getCurrent().isIncluded() && chain.isDoFilterRun());
+ System.out.println("time diff: " + (MockRequestDispatcher.getCurrent().getIncludeLastCalled() - chain.getTimeInvoked()) + "ms" );
+ assertTrue(chain.getTimeInvoked() < MockRequestDispatcher.getCurrent().getIncludeLastCalled());
+ }
+
+ public void testNoSubstitution() throws IOException, ServletException {
+ NormalRewrittenUrl rewrittenUrl = new NormalRewrittenUrl("/hi");
+ rewrittenUrl.setNoSubstitution(true);
+ assertFalse(rewrittenUrl.doRewrite(request, response, chain));
+ }
+
+}
diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/RuleTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/RuleTest.java
index 7873b99b..4aa47580 100644
--- a/src/test/java/org/tuckey/web/filters/urlrewrite/RuleTest.java
+++ b/src/test/java/org/tuckey/web/filters/urlrewrite/RuleTest.java
@@ -1,922 +1,922 @@
-/**
- * Copyright (c) 2005-2007, Paul Tuckey
- * All rights reserved.
- * ====================================================================
- * Licensed under the BSD License. Text as follows.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * - Neither the name tuckey.org nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- */
-package org.tuckey.web.filters.urlrewrite;
-
-import junit.framework.TestCase;
-import org.tuckey.web.filters.urlrewrite.utils.Log;
-import org.tuckey.web.testhelper.MockRequest;
-import org.tuckey.web.testhelper.MockResponse;
-import org.tuckey.web.testhelper.MockServletContext;
-
-import jakarta.servlet.ServletException;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-
-/**
- * @author Paul Tuckey
- * @version $Revision: 49 $ $Date: 2006-12-08 10:09:07 +1300 (Fri, 08 Dec 2006) $
- */
-public class RuleTest extends TestCase {
-
- MockResponse response;
- MockRequest request;
-
- public void setUp() {
- Log.setLevel("TRACE");
- response = new MockResponse();
- request = new MockRequest();
- }
-
- public void testRule01() throws IOException, ServletException, InvocationTargetException {
- NormalRule rule = new NormalRule();
- rule.setFrom("simple(ass)");
- rule.setTo("$1simple");
- rule.initialise(null);
- MockRequest request = new MockRequest("simpleass");
- NormalRewrittenUrl rewrittenUrl = (NormalRewrittenUrl) rule.matches(request.getRequestURI(), request, response);
-
- assertEquals("forward should be default type", "forward", rule.getToType());
- assertEquals("asssimple", rewrittenUrl.getTarget());
- assertTrue("Should be a forward", rewrittenUrl.isForward());
- }
-
- public void testRule01a() throws IOException, ServletException, InvocationTargetException {
- NormalRule rule = new NormalRule();
- rule.setFrom("simple(ass)");
- rule.setTo("$1simple");
- rule.setQueryStringAppend("true");
- rule.initialise(null);
- MockRequest request = new MockRequest("simpleass");
- request.setQueryString("aaa=bbb");
- NormalRewrittenUrl rewrittenUrl = (NormalRewrittenUrl) rule.matches(request.getRequestURI(), request, response);
-
- assertEquals("forward should be default type", "forward", rule.getToType());
- assertEquals("asssimple?aaa=bbb", rewrittenUrl.getTarget());
- assertTrue("Should be a forward", rewrittenUrl.isForward());
- }
-
- public void testRule01b() throws IOException, ServletException, InvocationTargetException {
- NormalRule rule = new NormalRule();
- rule.setFrom("simple(ass)");
- rule.setTo("$1simple?d=f");
- rule.setQueryStringAppend("true");
- rule.initialise(null);
- MockRequest request = new MockRequest("simpleass");
- request.setQueryString("aaa=bbb");
- NormalRewrittenUrl rewrittenUrl = (NormalRewrittenUrl) rule.matches(request.getRequestURI(), request, response);
-
- assertEquals("forward should be default type", "forward", rule.getToType());
- assertEquals("asssimple?d=f&aaa=bbb", rewrittenUrl.getTarget());
- assertTrue("Should be a forward", rewrittenUrl.isForward());
- }
-
- public void testRule03() throws IOException, ServletException, InvocationTargetException {
- NormalRule rule = new NormalRule();
- rule.setFrom("^/visa.jsp/([0-9]+)$");
- rule.setTo("/visa.jsp?Idet=$1");
- rule.initialise(null);
- MockRequest request = new MockRequest("/visa.jsp/974210592");
- NormalRewrittenUrl rewrittenUrl = (NormalRewrittenUrl) rule.matches(request.getRequestURI(), request, response);
-
- assertEquals("forward should be default type", "forward", rule.getToType());
- assertEquals("/visa.jsp?Idet=974210592", rewrittenUrl.getTarget());
- assertTrue("Should be a forward", rewrittenUrl.isForward());
- }
-
- /**
- * Test gor Google app engine's use of dollar sign
- * http://code.google.com/p/urlrewritefilter/issues/detail?id=71
- */
- public void testRuleGaeWildcard() throws IOException, ServletException, InvocationTargetException {
- NormalRule rule = new NormalRule();
- rule.setFrom("/**");
- rule.setTo("/app/$1");
- rule.setMatchType("wildcard");
- rule.initialise(null);
- MockRequest request = new MockRequest("/$%7Bfavicon%7D");
- NormalRewrittenUrl rewrittenUrl = (NormalRewrittenUrl) rule.matches(request.getRequestURI(), request, response);
- assertEquals("forward should be default type", "forward", rule.getToType());
- assertEquals("/app/$%7Bfavicon%7D", rewrittenUrl.getTarget());
- assertTrue("Should be a forward", rewrittenUrl.isForward());
- }
-
- public void testRuleNullTo() throws IOException, ServletException, InvocationTargetException {
- NormalRule rule = new NormalRule();
- rule.setFrom("from");
- rule.setTo("null");
- rule.initialise(null);
- SetAttribute setAttribute1 = new SetAttribute();
- setAttribute1.setType("status");
- setAttribute1.setValue("302");
- rule.addSetAttribute(setAttribute1);
- rule.initialise(null);
-
- MockRequest request = new MockRequest("from");
- NormalRewrittenUrl rewrittenUrl = (NormalRewrittenUrl) rule.matches(request.getRequestURI(), request, response);
- assertEquals(302, response.getStatus());
- assertTrue(rewrittenUrl.isStopFilterChain());
-
- }
-
- public void testRuleInclude() throws IOException, ServletException, InvocationTargetException {
- NormalRule rule = new NormalRule();
- rule.setFrom("from");
- rule.setTo("to");
- rule.setToType("pre-include");
- rule.initialise(null);
- request.setRequestURI("from");
- NormalRewrittenUrl rewrittenUrl = (NormalRewrittenUrl) rule.matches(request.getRequestURI(), request, response);
-
- assertEquals("pre-include", rule.getToType());
- assertTrue("Should be an pre include", rewrittenUrl.isPreInclude());
- }
-
- public void testRuleBackRef() throws IOException, ServletException, InvocationTargetException {
- Condition c = new Condition();
- c.setName("hdr");
- c.setValue("aaa([a-z]+)cc(c)");
- NormalRule rule = new NormalRule();
- rule.setFrom("([a-z])rom");
- rule.setTo("from match: $1, backref1: %1, backref2: %2, bad backref: %a % %99 %%88, escaped backref: \\%2");
- rule.addCondition(c);
- rule.initialise(null);
- MockRequest request = new MockRequest("from");
- request.setHeader("hdr", "aaafffccc");
- RewrittenUrl rewrittenUrl = rule.matches(request.getRequestURI(), request, response);
-
- assertEquals("Should have replaced back reference",
- "from match: f, backref1: fff, backref2: c, bad backref: %a % 9 %8, escaped backref: %2", rewrittenUrl.getTarget());
-
- assertTrue(rule.isToContainsBackReference());
- assertFalse(rule.isToContainsVariable());
- }
-
- public void testRuleBackRefWildcard() throws IOException, ServletException, InvocationTargetException {
- Condition c = new Condition();
- c.setName("hdr");
- c.setValue("aaa-*-cc-*");
- NormalRule rule = new NormalRule();
- rule.setFrom("*rom");
- rule.setTo("from match: $1, backref1: %1, backref2: %2, bad backref: %a % %99 %%88, escaped backref: \\%2");
- rule.setMatchType("wildcard");
- rule.addCondition(c);
- rule.initialise(null);
- MockRequest request = new MockRequest("from");
- request.setHeader("hdr", "aaa-fff-cc-c");
- RewrittenUrl rewrittenUrl = rule.matches(request.getRequestURI(), request, response);
-
- assertEquals("Should have replaced back reference",
- "from match: f, backref1: fff, backref2: c, bad backref: %a % 9 %8, escaped backref: %2", rewrittenUrl.getTarget());
-
- assertTrue(rule.isToContainsBackReference());
- assertFalse(rule.isToContainsVariable());
- }
-
- /**
- * here's my urlrewriter.xml :
- * int []
.
- */
- protected static final int MATCH_FILE = -1;
-
- /**
- * The int representing '**' in the pattern int []
.
- */
- protected static final int MATCH_PATH = -2;
-
- /**
- * The int representing begin in the pattern int []
.
- */
- protected static final int MATCH_BEGIN = -4;
-
- /**
- * The int representing end in pattern int []
.
- */
- protected static final int MATCH_THEEND = -5;
-
- /**
- * The int value that terminates the pattern int []
.
- */
- protected static final int MATCH_END = -3;
-
-
- /**
- * Translate the given String
into a int []
- * representing the pattern matchable by this class.
- *
- * This function translates a String
into an int array
- * converting the special '*' and '\' characters.
- *
- * Here is how the conversion algorithm works:
- *
- *
- * When more than two '*' characters, not separated by another character,
- * are found their value is considered as '**' (MATCH_PATH).
- *
- * The array is always terminated by a special value (MATCH_END).
- *
- * All MATCH* values are less than zero, while normal characters are equal
- * or greater.
- *
- * @param data The string to translate.
- * @return The encoded string as an int array, terminated by the MATCH_END
- * value (don't consider the array length).
- * @throws NullPointerException If data is null.
- */
- public int[] compilePattern(String data) {
-
- // Prepare the arrays
- int expr[] = new int[data.length() + 2];
- char buff[] = data.toCharArray();
-
- // Prepare variables for the translation loop
- int y = 0;
- boolean slash = false;
-
- // Must start from beginning
- expr[y++] = MATCH_BEGIN;
-
- if (buff.length > 0) {
- if (buff[0] == '\\') {
- slash = true;
- } else if (buff[0] == '*') {
- expr[y++] = MATCH_FILE;
- } else {
- expr[y++] = buff[0];
- }
-
- // Main translation loop
- for (int x = 1; x < buff.length; x++) {
- // If the previous char was '\' simply copy this char.
- if (slash) {
- expr[y++] = buff[x];
- slash = false;
- // If the previous char was not '\' we have to do a bunch of
- // checks
- } else {
- // If this char is '\' declare that and continue
- if (buff[x] == '\\') {
- slash = true;
- // If this char is '*' check the previous one
- } else if (buff[x] == '*') {
- // If the previous character als was '*' match a path
- if (expr[y - 1] <= MATCH_FILE) {
- expr[y - 1] = MATCH_PATH;
- } else {
- expr[y++] = MATCH_FILE;
- }
- } else {
- expr[y++] = buff[x];
- }
- }
- }
- }
-
- // Must match end at the end
- expr[y] = MATCH_THEEND;
- return expr;
- }
-
- /**
- * Match a pattern agains a string and isolates wildcard replacement into a
- * Stack
.
- *
- * @param map The map to store matched values
- * @param data The string to match
- * @param expr The compiled wildcard expression
- * @return True if a match
- * @throws NullPointerException If any parameters are null
- */
- public boolean match(Map map, String data, int[] expr) {
- if (map == null) {
- throw new NullPointerException("No map provided");
- }
- if (data == null) {
- throw new NullPointerException("No data provided");
- }
- if (expr == null) {
- throw new NullPointerException("No pattern expression provided");
- }
-
-
- char buff[] = data.toCharArray();
- // Allocate the result buffer
- char rslt[] = new char[expr.length + buff.length];
-
- // The previous and current position of the expression character
- // (MATCH_*)
- int charpos = 0;
-
- // The position in the expression, input, translation and result arrays
- int exprpos = 0;
- int buffpos = 0;
- int rsltpos = 0;
- int offset;
-
- // The matching count
- int mcount = 0;
-
- // We want the complete data be in {0}
- map.put(Integer.toString(mcount), data);
-
- // First check for MATCH_BEGIN
- boolean matchBegin = false;
- if (expr[charpos] == MATCH_BEGIN) {
- matchBegin = true;
- exprpos = ++charpos;
- }
-
- // Search the fist expression character (except MATCH_BEGIN - already
- // skipped)
- while (expr[charpos] >= 0) {
- charpos++;
- }
-
- // The expression charater (MATCH_*)
- int exprchr = expr[charpos];
-
- while (true) {
- // Check if the data in the expression array before the current
- // expression character matches the data in the input buffer
- if (matchBegin) {
- if (!matchArray(expr, exprpos, charpos, buff, buffpos)) {
- return (false);
- }
- matchBegin = false;
- } else {
- offset = indexOfArray(expr, exprpos, charpos, buff,
- buffpos);
- if (offset < 0) {
- return (false);
- }
- }
-
- // Advance buffpos
- buffpos += (charpos - exprpos);
-
- // Check for END's
- if (exprchr == MATCH_END) {
- if (rsltpos > 0) {
- map.put(Integer.toString(++mcount),
- new String(rslt, 0, rsltpos));
- }
- // Don't care about rest of input buffer
- return (true);
- } else if (exprchr == MATCH_THEEND) {
- if (rsltpos > 0) {
- map.put(Integer.toString(++mcount),
- new String(rslt, 0, rsltpos));
- }
- // Check that we reach buffer's end
- return (buffpos == buff.length);
- }
-
- // Search the next expression character
- exprpos = ++charpos;
- while (expr[charpos] >= 0) {
- charpos++;
- }
- int prevchr = exprchr;
- exprchr = expr[charpos];
-
- // We have here prevchr == * or **.
- offset = (prevchr == MATCH_FILE)
- ? indexOfArray(expr, exprpos, charpos, buff, buffpos)
- : lastIndexOfArray(expr, exprpos, charpos, buff,
- buffpos);
-
- if (offset < 0) {
- return (false);
- }
-
- // Copy the data from the source buffer into the result buffer
- // to substitute the expression character
- if (prevchr == MATCH_PATH) {
- while (buffpos < offset) {
- rslt[rsltpos++] = buff[buffpos++];
- }
- } else {
- // Matching file, don't copy '/'
- while (buffpos < offset) {
- if (buff[buffpos] == '/') {
- return (false);
- }
- rslt[rsltpos++] = buff[buffpos++];
- }
- }
-
- map.put(Integer.toString(++mcount), new String(rslt, 0, rsltpos));
- rsltpos = 0;
- }
- }
-
- /**
- * Get the offset of a part of an int array within a char array.
- *
- * This method return the index in d of the first occurrence after dpos of
- * that part of array specified by r, starting at rpos and terminating at
- * rend.
- *
- * @param r The array containing the data that need to be matched in d.
- * @param rpos The index of the first character in r to look for.
- * @param rend The index of the last character in r to look for plus 1.
- * @param d The array of char that should contain a part of r.
- * @param dpos The starting offset in d for the matching.
- * @return The offset in d of the part of r matched in d or -1 if that was
- * not found.
- */
- protected int indexOfArray(int r[], int rpos, int rend,
- char d[], int dpos) {
-
- // Check if pos and len are legal
- if (rend < rpos) {
- throw new IllegalArgumentException("rend < rpos");
- }
- // If we need to match a zero length string return current dpos
- if (rend == rpos) {
- return (d.length); //?? dpos?
- }
- // If we need to match a 1 char length string do it simply
- if ((rend - rpos) == 1) {
- // Search for the specified character
- for (int x = dpos; x < d.length; x++) {
- if (r[rpos] == d[x]) {
- return (x);
- }
- }
- }
- // Main string matching loop. It gets executed if the characters to
- // match are less then the characters left in the d buffer
- while ((dpos + rend - rpos) <= d.length) {
- // Set current startpoint in d
- int y = dpos;
- // Check every character in d for equity. If the string is matched
- // return dpos
- for (int x = rpos; x <= rend; x++) {
- if (x == rend) {
- return (dpos);
- }
- if (r[x] != d[y++]) {
- break;
- }
- }
- // Increase dpos to search for the same string at next offset
- dpos++;
- }
- // The remaining chars in d buffer were not enough or the string
- // wasn't matched
- return (-1);
- }
-
- /**
- * Get the offset of a last occurance of an int array within a char array.
- *
- * This method return the index in d of the last occurrence after dpos of
- * that part of array specified by r, starting at rpos and terminating at
- * rend.
- *
- * @param r The array containing the data that need to be matched in d.
- * @param rpos The index of the first character in r to look for.
- * @param rend The index of the last character in r to look for plus 1.
- * @param d The array of char that should contain a part of r.
- * @param dpos The starting offset in d for the matching.
- * @return The offset in d of the last part of r matched in d or -1 if
- * that was not found.
- */
- protected int lastIndexOfArray(int r[], int rpos, int rend,
- char d[], int dpos) {
- // Check if pos and len are legal
- if (rend < rpos) {
- throw new IllegalArgumentException("rend < rpos");
- }
- // If we need to match a zero length string return current dpos
- if (rend == rpos) {
- return (d.length); //?? dpos?
- }
-
- // If we need to match a 1 char length string do it simply
- if ((rend - rpos) == 1) {
- // Search for the specified character
- for (int x = d.length - 1; x > dpos; x--) {
- if (r[rpos] == d[x]) {
- return (x);
- }
- }
- }
-
- // Main string matching loop. It gets executed if the characters to
- // match are less then the characters left in the d buffer
- int l = d.length - (rend - rpos);
- while (l >= dpos) {
- // Set current startpoint in d
- int y = l;
- // Check every character in d for equity. If the string is matched
- // return dpos
- for (int x = rpos; x <= rend; x++) {
- if (x == rend) {
- return (l);
- }
- if (r[x] != d[y++]) {
- break;
- }
- }
- // Decrease l to search for the same string at next offset
- l--;
- }
- // The remaining chars in d buffer were not enough or the string
- // wasn't matched
- return (-1);
- }
-
- /**
- * Matches elements of array r from rpos to rend with array d, starting
- * from dpos.
- *
- * This method return true if elements of array r from rpos to rend
- * equals elements of array d starting from dpos to dpos+(rend-rpos).
- *
- * @param r The array containing the data that need to be matched in d.
- * @param rpos The index of the first character in r to look for.
- * @param rend The index of the last character in r to look for.
- * @param d The array of char that should start from a part of r.
- * @param dpos The starting offset in d for the matching.
- * @return true if array d starts from portion of array r.
- */
- protected boolean matchArray(int r[], int rpos, int rend,
- char d[], int dpos) {
- if (d.length - dpos < rend - rpos) {
- return (false);
- }
- for (int i = rpos; i < rend; i++) {
- if (r[i] != d[dpos++]) {
- return (false);
- }
- }
- return (true);
- }
+/**
+ * This class is a modified version of one found in Apache Cocoon.
+ * int []
.
+ */
+ protected static final int MATCH_FILE = -1;
+
+ /**
+ * The int representing '**' in the pattern int []
.
+ */
+ protected static final int MATCH_PATH = -2;
+
+ /**
+ * The int representing begin in the pattern int []
.
+ */
+ protected static final int MATCH_BEGIN = -4;
+
+ /**
+ * The int representing end in pattern int []
.
+ */
+ protected static final int MATCH_THEEND = -5;
+
+ /**
+ * The int value that terminates the pattern int []
.
+ */
+ protected static final int MATCH_END = -3;
+
+
+ /**
+ * Translate the given String
into a int []
+ * representing the pattern matchable by this class.
+ *
+ * This function translates a String
into an int array
+ * converting the special '*' and '\' characters.
+ *
+ * Here is how the conversion algorithm works:
+ *
+ *
+ * When more than two '*' characters, not separated by another character,
+ * are found their value is considered as '**' (MATCH_PATH).
+ *
+ * The array is always terminated by a special value (MATCH_END).
+ *
+ * All MATCH* values are less than zero, while normal characters are equal
+ * or greater.
+ *
+ * @param data The string to translate.
+ * @return The encoded string as an int array, terminated by the MATCH_END
+ * value (don't consider the array length).
+ * @throws NullPointerException If data is null.
+ */
+ public int[] compilePattern(String data) {
+
+ // Prepare the arrays
+ int expr[] = new int[data.length() + 2];
+ char buff[] = data.toCharArray();
+
+ // Prepare variables for the translation loop
+ int y = 0;
+ boolean slash = false;
+
+ // Must start from beginning
+ expr[y++] = MATCH_BEGIN;
+
+ if (buff.length > 0) {
+ if (buff[0] == '\\') {
+ slash = true;
+ } else if (buff[0] == '*') {
+ expr[y++] = MATCH_FILE;
+ } else {
+ expr[y++] = buff[0];
+ }
+
+ // Main translation loop
+ for (int x = 1; x < buff.length; x++) {
+ // If the previous char was '\' simply copy this char.
+ if (slash) {
+ expr[y++] = buff[x];
+ slash = false;
+ // If the previous char was not '\' we have to do a bunch of
+ // checks
+ } else {
+ // If this char is '\' declare that and continue
+ if (buff[x] == '\\') {
+ slash = true;
+ // If this char is '*' check the previous one
+ } else if (buff[x] == '*') {
+ // If the previous character als was '*' match a path
+ if (expr[y - 1] <= MATCH_FILE) {
+ expr[y - 1] = MATCH_PATH;
+ } else {
+ expr[y++] = MATCH_FILE;
+ }
+ } else {
+ expr[y++] = buff[x];
+ }
+ }
+ }
+ }
+
+ // Must match end at the end
+ expr[y] = MATCH_THEEND;
+ return expr;
+ }
+
+ /**
+ * Match a pattern agains a string and isolates wildcard replacement into a
+ * Stack
.
+ *
+ * @param map The map to store matched values
+ * @param data The string to match
+ * @param expr The compiled wildcard expression
+ * @return True if a match
+ * @throws NullPointerException If any parameters are null
+ */
+ public boolean match(Map map, String data, int[] expr) {
+ if (map == null) {
+ throw new NullPointerException("No map provided");
+ }
+ if (data == null) {
+ throw new NullPointerException("No data provided");
+ }
+ if (expr == null) {
+ throw new NullPointerException("No pattern expression provided");
+ }
+
+
+ char buff[] = data.toCharArray();
+ // Allocate the result buffer
+ char rslt[] = new char[expr.length + buff.length];
+
+ // The previous and current position of the expression character
+ // (MATCH_*)
+ int charpos = 0;
+
+ // The position in the expression, input, translation and result arrays
+ int exprpos = 0;
+ int buffpos = 0;
+ int rsltpos = 0;
+ int offset;
+
+ // The matching count
+ int mcount = 0;
+
+ // We want the complete data be in {0}
+ map.put(Integer.toString(mcount), data);
+
+ // First check for MATCH_BEGIN
+ boolean matchBegin = false;
+ if (expr[charpos] == MATCH_BEGIN) {
+ matchBegin = true;
+ exprpos = ++charpos;
+ }
+
+ // Search the fist expression character (except MATCH_BEGIN - already
+ // skipped)
+ while (expr[charpos] >= 0) {
+ charpos++;
+ }
+
+ // The expression charater (MATCH_*)
+ int exprchr = expr[charpos];
+
+ while (true) {
+ // Check if the data in the expression array before the current
+ // expression character matches the data in the input buffer
+ if (matchBegin) {
+ if (!matchArray(expr, exprpos, charpos, buff, buffpos)) {
+ return (false);
+ }
+ matchBegin = false;
+ } else {
+ offset = indexOfArray(expr, exprpos, charpos, buff,
+ buffpos);
+ if (offset < 0) {
+ return (false);
+ }
+ }
+
+ // Advance buffpos
+ buffpos += (charpos - exprpos);
+
+ // Check for END's
+ if (exprchr == MATCH_END) {
+ if (rsltpos > 0) {
+ map.put(Integer.toString(++mcount),
+ new String(rslt, 0, rsltpos));
+ }
+ // Don't care about rest of input buffer
+ return (true);
+ } else if (exprchr == MATCH_THEEND) {
+ if (rsltpos > 0) {
+ map.put(Integer.toString(++mcount),
+ new String(rslt, 0, rsltpos));
+ }
+ // Check that we reach buffer's end
+ return (buffpos == buff.length);
+ }
+
+ // Search the next expression character
+ exprpos = ++charpos;
+ while (expr[charpos] >= 0) {
+ charpos++;
+ }
+ int prevchr = exprchr;
+ exprchr = expr[charpos];
+
+ // We have here prevchr == * or **.
+ offset = (prevchr == MATCH_FILE)
+ ? indexOfArray(expr, exprpos, charpos, buff, buffpos)
+ : lastIndexOfArray(expr, exprpos, charpos, buff,
+ buffpos);
+
+ if (offset < 0) {
+ return (false);
+ }
+
+ // Copy the data from the source buffer into the result buffer
+ // to substitute the expression character
+ if (prevchr == MATCH_PATH) {
+ while (buffpos < offset) {
+ rslt[rsltpos++] = buff[buffpos++];
+ }
+ } else {
+ // Matching file, don't copy '/'
+ while (buffpos < offset) {
+ if (buff[buffpos] == '/') {
+ return (false);
+ }
+ rslt[rsltpos++] = buff[buffpos++];
+ }
+ }
+
+ map.put(Integer.toString(++mcount), new String(rslt, 0, rsltpos));
+ rsltpos = 0;
+ }
+ }
+
+ /**
+ * Get the offset of a part of an int array within a char array.
+ *
+ * This method return the index in d of the first occurrence after dpos of
+ * that part of array specified by r, starting at rpos and terminating at
+ * rend.
+ *
+ * @param r The array containing the data that need to be matched in d.
+ * @param rpos The index of the first character in r to look for.
+ * @param rend The index of the last character in r to look for plus 1.
+ * @param d The array of char that should contain a part of r.
+ * @param dpos The starting offset in d for the matching.
+ * @return The offset in d of the part of r matched in d or -1 if that was
+ * not found.
+ */
+ protected int indexOfArray(int r[], int rpos, int rend,
+ char d[], int dpos) {
+
+ // Check if pos and len are legal
+ if (rend < rpos) {
+ throw new IllegalArgumentException("rend < rpos");
+ }
+ // If we need to match a zero length string return current dpos
+ if (rend == rpos) {
+ return (d.length); //?? dpos?
+ }
+ // If we need to match a 1 char length string do it simply
+ if ((rend - rpos) == 1) {
+ // Search for the specified character
+ for (int x = dpos; x < d.length; x++) {
+ if (r[rpos] == d[x]) {
+ return (x);
+ }
+ }
+ }
+ // Main string matching loop. It gets executed if the characters to
+ // match are less then the characters left in the d buffer
+ while ((dpos + rend - rpos) <= d.length) {
+ // Set current startpoint in d
+ int y = dpos;
+ // Check every character in d for equity. If the string is matched
+ // return dpos
+ for (int x = rpos; x <= rend; x++) {
+ if (x == rend) {
+ return (dpos);
+ }
+ if (r[x] != d[y++]) {
+ break;
+ }
+ }
+ // Increase dpos to search for the same string at next offset
+ dpos++;
+ }
+ // The remaining chars in d buffer were not enough or the string
+ // wasn't matched
+ return (-1);
+ }
+
+ /**
+ * Get the offset of a last occurance of an int array within a char array.
+ *
+ * This method return the index in d of the last occurrence after dpos of
+ * that part of array specified by r, starting at rpos and terminating at
+ * rend.
+ *
+ * @param r The array containing the data that need to be matched in d.
+ * @param rpos The index of the first character in r to look for.
+ * @param rend The index of the last character in r to look for plus 1.
+ * @param d The array of char that should contain a part of r.
+ * @param dpos The starting offset in d for the matching.
+ * @return The offset in d of the last part of r matched in d or -1 if
+ * that was not found.
+ */
+ protected int lastIndexOfArray(int r[], int rpos, int rend,
+ char d[], int dpos) {
+ // Check if pos and len are legal
+ if (rend < rpos) {
+ throw new IllegalArgumentException("rend < rpos");
+ }
+ // If we need to match a zero length string return current dpos
+ if (rend == rpos) {
+ return (d.length); //?? dpos?
+ }
+
+ // If we need to match a 1 char length string do it simply
+ if ((rend - rpos) == 1) {
+ // Search for the specified character
+ for (int x = d.length - 1; x > dpos; x--) {
+ if (r[rpos] == d[x]) {
+ return (x);
+ }
+ }
+ }
+
+ // Main string matching loop. It gets executed if the characters to
+ // match are less then the characters left in the d buffer
+ int l = d.length - (rend - rpos);
+ while (l >= dpos) {
+ // Set current startpoint in d
+ int y = l;
+ // Check every character in d for equity. If the string is matched
+ // return dpos
+ for (int x = rpos; x <= rend; x++) {
+ if (x == rend) {
+ return (l);
+ }
+ if (r[x] != d[y++]) {
+ break;
+ }
+ }
+ // Decrease l to search for the same string at next offset
+ l--;
+ }
+ // The remaining chars in d buffer were not enough or the string
+ // wasn't matched
+ return (-1);
+ }
+
+ /**
+ * Matches elements of array r from rpos to rend with array d, starting
+ * from dpos.
+ *
+ * This method return true if elements of array r from rpos to rend
+ * equals elements of array d starting from dpos to dpos+(rend-rpos).
+ *
+ * @param r The array containing the data that need to be matched in d.
+ * @param rpos The index of the first character in r to look for.
+ * @param rend The index of the last character in r to look for.
+ * @param d The array of char that should start from a part of r.
+ * @param dpos The starting offset in d for the matching.
+ * @return true if array d starts from portion of array r.
+ */
+ protected boolean matchArray(int r[], int rpos, int rend,
+ char d[], int dpos) {
+ if (d.length - dpos < rend - rpos) {
+ return (false);
+ }
+ for (int i = rpos; i < rend; i++) {
+ if (r[i] != d[dpos++]) {
+ return (false);
+ }
+ }
+ return (true);
+ }
}
\ No newline at end of file
diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardMatcher.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardMatcher.java
index 3b3d16e1..aad503c7 100644
--- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardMatcher.java
+++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/WildcardMatcher.java
@@ -3,11 +3,11 @@
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
- *
+ *