Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2015-08-18 14:17:06 +0000
committerThomas Watson2015-08-18 14:22:49 +0000
commit88b017a97beecb2d019c32661efb07d74afa9223 (patch)
tree35c6eb55510969efa6faf39b63700510845be301 /bundles/org.eclipse.equinox.http.servlet
parenta79cc578532511532eb8d96f1a739b0f358ef041 (diff)
downloadrt.equinox.bundles-88b017a97beecb2d019c32661efb07d74afa9223.tar.gz
rt.equinox.bundles-88b017a97beecb2d019c32661efb07d74afa9223.tar.xz
rt.equinox.bundles-88b017a97beecb2d019c32661efb07d74afa9223.zip
Bug 474250 - [http] org.eclipse.equinox.http.registry.filters alias
matching is broken Change-Id: I52424c6033d2920ab3dd0a503360335c4b736f71 Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
Diffstat (limited to 'bundles/org.eclipse.equinox.http.servlet')
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java21
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ContextController.java2
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/EndpointRegistration.java11
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/FilterRegistration.java51
4 files changed, 50 insertions, 35 deletions
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java
index 9c892375f..d9e7024d9 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java
@@ -515,8 +515,12 @@ public class HttpServiceRuntimeImpl
ContextController.checkPattern(alias);
// need to make sure exact matching aliases are converted to wildcard pattern matches
- if (!alias.endsWith(Const.SLASH_STAR) && !alias.startsWith("*.")) { //$NON-NLS-1$
- alias = alias + Const.SLASH_STAR;
+ if (!alias.endsWith(Const.SLASH_STAR) && !alias.startsWith(Const.STAR_DOT) && !alias.contains(Const.SLASH_STAR_DOT)) {
+ if (alias.endsWith(Const.SLASH)) {
+ alias = alias + '*';
+ } else {
+ alias = alias + Const.SLASH_STAR;
+ }
}
synchronized (legacyMappings) {
@@ -685,7 +689,18 @@ public class HttpServiceRuntimeImpl
throw new IllegalArgumentException("Servlet cannot be null");
}
+ // check the pattern against the original input
ContextController.checkPattern(alias);
+ String originalAlias = alias;
+
+ // need to make sure exact matching aliases are converted to wildcard pattern matches
+ if (!alias.endsWith(Const.SLASH_STAR) && !alias.startsWith(Const.STAR_DOT) && !alias.contains(Const.SLASH_STAR_DOT)) {
+ if (alias.endsWith(Const.SLASH)) {
+ alias = alias + '*';
+ } else {
+ alias = alias + Const.SLASH_STAR;
+ }
+ }
synchronized (legacyMappings) {
LegacyServlet legacyServlet = new LegacyServlet(servlet);
@@ -699,7 +714,7 @@ public class HttpServiceRuntimeImpl
String fullAlias = getFullAlias(alias, factory);
HttpServiceObjectRegistration existing = legacyMappings.get(fullAlias);
if (existing != null) {
- throw new PatternInUseException(alias);
+ throw new PatternInUseException(originalAlias);
}
String servletName = servlet.getClass().getName();
if ((initparams != null) && (initparams.get(Const.SERVLET_NAME) != null)) {
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ContextController.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ContextController.java
index cb78b8fbe..c717fa864 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ContextController.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ContextController.java
@@ -733,7 +733,7 @@ public class ContextController {
for (FilterRegistration filterRegistration : filterRegistrations) {
if ((filterRegistration.match(
- servletName, servletPath, pathInfo, extension, null) != null) &&
+ servletName, requestURI, extension, null) != null) &&
!matchingFilterRegistrations.contains(filterRegistration)) {
matchingFilterRegistrations.add(filterRegistration);
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/EndpointRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/EndpointRegistration.java
index d20933fd1..0d1e25fbb 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/EndpointRegistration.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/EndpointRegistration.java
@@ -18,7 +18,6 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.equinox.http.servlet.internal.context.ContextController;
import org.eclipse.equinox.http.servlet.internal.context.ContextController.ServiceHolder;
import org.eclipse.equinox.http.servlet.internal.servlet.Match;
-import org.eclipse.equinox.http.servlet.internal.util.Const;
import org.osgi.dto.DTO;
import org.osgi.framework.wiring.BundleWiring;
import org.osgi.service.http.context.ServletContextHelper;
@@ -33,7 +32,6 @@ public abstract class EndpointRegistration<D extends DTO>
private final ServletContextHelper servletContextHelper; //The context used during the registration of the servlet
private final ContextController contextController;
private final ClassLoader classLoader;
- private final boolean legacyRegistration;
public EndpointRegistration(
ServiceHolder<Servlet> servletHolder, D d, ServletContextHelper servletContextHelper,
@@ -43,8 +41,7 @@ public abstract class EndpointRegistration<D extends DTO>
this.servletHolder = servletHolder;
this.servletContextHelper = servletContextHelper;
this.contextController = contextController;
- this.legacyRegistration = legacyTCCL != null;
- if (this.legacyRegistration) {
+ if (legacyTCCL != null) {
// legacy registrations used the current TCCL at registration time
classLoader = legacyTCCL;
} else {
@@ -140,12 +137,6 @@ public abstract class EndpointRegistration<D extends DTO>
}
for (String pattern : patterns) {
- if (legacyRegistration && (match == Match.REGEX) &&
- !pattern.endsWith(Const.SLASH_STAR)) {
-
- pattern += Const.SLASH_STAR;
- }
-
if (doMatch(pattern, servletPath, pathInfo, extension, match)) {
return pattern;
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/FilterRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/FilterRegistration.java
index 382128b82..70f12ee78 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/FilterRegistration.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/FilterRegistration.java
@@ -160,10 +160,8 @@ public class FilterRegistration
}
}
- @Override
public String match(
- String name, String servletPath, String pathInfo, String extension, Match match) {
-
+ String name, String requestURI, String extension, Match match) {
if ((name != null) && (getD().servletNames != null)) {
for (String servletName : getD().servletNames) {
if (servletName.equals(name)) {
@@ -172,30 +170,18 @@ public class FilterRegistration
}
}
- StringBuilder sb = new StringBuilder();
-
- if (servletPath != null) {
- sb.append(servletPath);
- }
-
- if (pathInfo != null) {
- sb.append(pathInfo);
- }
-
- String path = sb.toString();
-
- if (path.length() <= 0) {
+ if (requestURI == null || requestURI.isEmpty()) {
return null;
}
for (String pattern : getD().patterns) {
- if (doPatternMatch(pattern, path, extension)) {
+ if (doPatternMatch(pattern, requestURI, extension)) {
return pattern;
}
}
for (Pattern regex : compiledRegexs) {
- if (regex.matcher(path).matches()) {
+ if (regex.matcher(requestURI).matches()) {
return regex.toString();
}
}
@@ -203,6 +189,13 @@ public class FilterRegistration
return null;
}
+ @Override
+ public String match(
+ String name, String servletPath, String pathInfo, String extension, Match match) {
+ // TODO need to rework match for filters to remove this method
+ throw new UnsupportedOperationException("Should not be calling this method on FilterRegistration"); //$NON-NLS-1$
+ }
+
private void createContextAttributes() {
contextController.getProxyContext().createContextAttributes(
contextController);
@@ -220,7 +213,10 @@ public class FilterRegistration
// first try wild card matching if the pattern requests it
if (pattern.endsWith("/*")) { //$NON-NLS-1$
int pathPatternLength = pattern.length() - 2;
- return path.regionMatches(0, pattern, 0, pathPatternLength);
+ if (path.regionMatches(0, pattern, 0, pathPatternLength)) {
+ return path.length() <= pathPatternLength || path.charAt(pathPatternLength) == '/';
+ }
+ return false;
}
// now do exact matching
return pattern.equals(path);
@@ -229,12 +225,25 @@ public class FilterRegistration
protected boolean doPatternMatch(String pattern, String path, String extension)
throws IllegalArgumentException {
- if (pattern.indexOf("/*.") == 0) { //$NON-NLS-1$
+ if (pattern.indexOf(Const.SLASH_STAR_DOT) == 0) {
pattern = pattern.substring(1);
}
+ int extensionMatchIndex = pattern.indexOf(Const.SLASH_STAR_DOT);
+ String extensionWithPrefixMatch = null;
+ if (extensionMatchIndex >= 0 && pattern.lastIndexOf('/') == extensionMatchIndex) {
+ extensionWithPrefixMatch = pattern.substring(extensionMatchIndex + 3);
+ pattern = pattern.substring(0, extensionMatchIndex + 2);
+ }
+
// first try prefix path matching; taking into account wild cards if necessary
if ((pattern.charAt(0) == '/')) {
- return isPathWildcardMatch(pattern, path);
+ if (isPathWildcardMatch(pattern, path)) {
+ if (extensionWithPrefixMatch != null) {
+ return extensionWithPrefixMatch.equals(extension);
+ }
+ return true;
+ }
+ return false;
}
// next try extension matching if requested

Back to the top