Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authora_mergey@yahoo.fr2017-05-17 16:10:54 +0000
committerThomas Watson2017-11-07 14:04:51 +0000
commitea94523fefb5b36def9cda1062495008e47b4795 (patch)
tree640c6ea7de81d2198ce2136cdbc8d0c598e0a0d8
parentf909baeb41bf7b21281e9621597feb0774dd0e51 (diff)
downloadrt.equinox.bundles-I20171109-2000.tar.gz
rt.equinox.bundles-I20171109-2000.tar.xz
rt.equinox.bundles-I20171109-2000.zip
Bug 497510 - [http] HttpServletRequestWrapperImpl::getRequestUri()I20171109-2000I20171108-2000I20171107-2000
returning decoded URI Change-Id: I58c54b98b6e3d08928f66b35e6faec8c1d84c250 Signed-off-by: Raymond Auge <raymond.auge@liferay.com> Signed-off-by: Thomas Watson <tjwatson@us.ibm.com> Signed-off-by: a_mergey@yahoo.fr <a_mergey@yahoo.fr>
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/DispatchingTest.java57
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/FilterRegistration.java7
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/MatchableRegistration.java36
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ResourceRegistration.java7
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ServletRegistration.java7
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpServletRequestWrapperImpl.java8
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ProxyServlet.java27
7 files changed, 142 insertions, 7 deletions
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/DispatchingTest.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/DispatchingTest.java
index bc9f0da8f..eaaee82af 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/DispatchingTest.java
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/DispatchingTest.java
@@ -1576,4 +1576,61 @@ public class DispatchingTest extends BaseTest {
Assert.assertEquals(10, counter.get());
}
+ @Test
+ public void test_Bug497510_1() throws Exception {
+ Servlet servlet = new HttpServlet() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(
+ final HttpServletRequest req, final HttpServletResponse resp)
+ throws ServletException, IOException {
+
+ String requestURI = req.getRequestURI();
+
+ Assert.assertNotNull(requestURI);
+
+ PrintWriter writer = resp.getWriter();
+ writer.write(requestURI);
+ }
+ };
+
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "Bug497510");
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/Bug497510/*");
+ registrations.add(getBundleContext().registerService(Servlet.class, servlet, props));
+
+ String result = requestAdvisor.request("Bug497510/a%20b%20c");
+
+ Assert.assertEquals("/Bug497510/a%20b%20c", result);
+ }
+
+ @Test
+ public void test_Bug497510_2() throws Exception {
+ Servlet servlet = new HttpServlet() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(
+ final HttpServletRequest req, final HttpServletResponse resp)
+ throws ServletException, IOException {
+
+ String requestURI = req.getRequestURI();
+
+ Assert.assertNotNull(requestURI);
+
+ PrintWriter writer = resp.getWriter();
+ writer.write(requestURI);
+ }
+ };
+
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "Bug 497510");
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/Bug 497510/*");
+ registrations.add(getBundleContext().registerService(Servlet.class, servlet, props));
+
+ String result = requestAdvisor.request("Bug%20497510/a%20b%20c");
+
+ Assert.assertEquals("/Bug%20497510/a%20b%20c", result);
+ }
} \ No newline at end of file
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 27975ca81..5e68ec68b 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
@@ -38,6 +38,7 @@ public class FilterRegistration
private final ContextController contextController;
private final boolean initDestoyWithContextController;
private final Pattern[] compiledRegexs;
+ private final boolean needDecode;
public FilterRegistration(
ServiceHolder<Filter> filterHolder, FilterDTO filterDTO, int priority,
@@ -70,6 +71,7 @@ public class FilterRegistration
} else {
initDestoyWithContextController = true;
}
+ needDecode = MatchableRegistration.patternsRequireDecode(filterDTO.patterns);
}
public int compareTo(FilterRegistration otherFilterRegistration) {
@@ -272,4 +274,9 @@ public class FilterRegistration
return patterns;
}
+ @Override
+ public boolean needDecode() {
+ return needDecode;
+ }
+
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/MatchableRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/MatchableRegistration.java
index 941437885..4da830e57 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/MatchableRegistration.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/MatchableRegistration.java
@@ -11,6 +11,9 @@
package org.eclipse.equinox.http.servlet.internal.registration;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
import org.eclipse.equinox.http.servlet.internal.servlet.Match;
import org.eclipse.equinox.http.servlet.internal.util.Const;
import org.osgi.dto.DTO;
@@ -25,12 +28,14 @@ public abstract class MatchableRegistration<T, D extends DTO>
super(t, d);
}
+ public abstract boolean needDecode();
+
public abstract String match(
String name, String servletPath, String pathInfo, String extension,
Match match);
- protected boolean isPathWildcardMatch(
- String pattern, String servletPath, String pathInfo) {
+ private boolean isPathWildcardMatch(
+ String pattern, String servletPath) {
int cpl = pattern.length() - 2;
@@ -47,11 +52,18 @@ public abstract class MatchableRegistration<T, D extends DTO>
return false;
}
- protected boolean doMatch(
+ final protected boolean doMatch(
String pattern, String servletPath, String pathInfo,
String extension, Match match)
throws IllegalArgumentException {
-
+ if (needDecode()) {
+ try {
+ servletPath = URLDecoder.decode(servletPath, "UTF-8"); //$NON-NLS-1$
+ }
+ catch (UnsupportedEncodingException e) {
+ // do nothing
+ }
+ }
if (match == Match.EXACT) {
return pattern.equals(servletPath);
}
@@ -66,7 +78,7 @@ public abstract class MatchableRegistration<T, D extends DTO>
}
if ((match == Match.REGEX) && isPathWildcardMatch(
- pattern, servletPath, pathInfo)) {
+ pattern, servletPath)) {
return true;
}
@@ -88,4 +100,18 @@ public abstract class MatchableRegistration<T, D extends DTO>
return false;
}
+ static boolean patternsRequireDecode(String[] patterns) {
+ for (String pattern : patterns) {
+ try {
+ String encode = URLEncoder.encode(pattern, "UTF-8"); //$NON-NLS-1$
+ if (!encode.equals(pattern)) {
+ return true;
+ }
+ }
+ catch (UnsupportedEncodingException e) {
+ // do nothing
+ }
+ }
+ return false;
+ }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ResourceRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ResourceRegistration.java
index fc6ac646d..ff10f1bc4 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ResourceRegistration.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ResourceRegistration.java
@@ -29,6 +29,7 @@ public class ResourceRegistration extends EndpointRegistration<ResourceDTO> {
super(servletHolder, resourceDTO, servletContextHelper, contextController, legacyTCCL);
name = servletHolder.get().getClass().getName().concat("#").concat(getD().prefix); //$NON-NLS-1$
+ needDecode = MatchableRegistration.patternsRequireDecode(resourceDTO.patterns);
}
@Override
@@ -46,6 +47,12 @@ public class ResourceRegistration extends EndpointRegistration<ResourceDTO> {
return getD().serviceId;
}
+ @Override
+ public boolean needDecode() {
+ return needDecode;
+ }
+
+ private final boolean needDecode;
private final String name;
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ServletRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ServletRegistration.java
index 63267f9e5..be982f459 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ServletRegistration.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ServletRegistration.java
@@ -66,6 +66,7 @@ public class ServletRegistration extends EndpointRegistration<ExtendedServletDTO
else {
multipartSupport = null;
}
+ needDecode = MatchableRegistration.patternsRequireDecode(servletDTO.patterns);
}
public ErrorPageDTO getErrorPageDTO() {
@@ -116,8 +117,12 @@ public class ServletRegistration extends EndpointRegistration<ExtendedServletDTO
return multipartSupport.parseRequest(request);
}
+ @Override
+ public boolean needDecode() {
+ return needDecode;
+ }
+ private final boolean needDecode;
private final ErrorPageDTO errorPageDTO;
private final MultipartSupport multipartSupport;
-
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpServletRequestWrapperImpl.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpServletRequestWrapperImpl.java
index 350ef26ea..e7c05f197 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpServletRequestWrapperImpl.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpServletRequestWrapperImpl.java
@@ -9,6 +9,7 @@
* Cognos Incorporated - initial API and implementation
* IBM Corporation - bug fixes and enhancements
* Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ * Arnaud Mergey <a_mergey@yahoo.fr> - Bug 497510
*******************************************************************************/
package org.eclipse.equinox.http.servlet.internal.servlet;
@@ -313,6 +314,13 @@ public class HttpServletRequestWrapperImpl extends HttpServletRequestWrapper {
return req.getPathInfo();
}
+
+ public static String getDispatchRequestURI(HttpServletRequest req) {
+ if (req.getDispatcherType() == DispatcherType.INCLUDE)
+ return (String) req.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI);
+
+ return req.getRequestURI();
+ }
public HttpSession getSession() {
return getSession(true);
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ProxyServlet.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ProxyServlet.java
index 08ec8f160..6dfafccfe 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ProxyServlet.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ProxyServlet.java
@@ -9,6 +9,7 @@
* Cognos Incorporated - initial API and implementation
* IBM Corporation - bug fixes and enhancements
* Raymond Augé - bug fixes and enhancements
+ * Arnaud Mergey <a_mergey@yahoo.fr> - Bug 497510
*******************************************************************************/
package org.eclipse.equinox.http.servlet.internal.servlet;
@@ -52,6 +53,30 @@ public class ProxyServlet extends HttpServlet {
public void sessionIdChanged(String oldSessionId) {
httpServiceRuntimeImpl.fireSessionIdChanged(oldSessionId);
}
+
+ /**
+ * get the value of path info, not decoded by the server
+ */
+ private String getNotDecodedAlias(HttpServletRequest request) {
+ String pathInfo = HttpServletRequestWrapperImpl.getDispatchPathInfo(request);
+ if(pathInfo == null) {
+ return null;
+ }
+ String requestUri = HttpServletRequestWrapperImpl.getDispatchRequestURI(request);
+
+ String[] pathInfoSegments = pathInfo.split(Const.SLASH);
+ String[] requestUriSegments = requestUri.split(Const.SLASH);
+
+ if(pathInfoSegments.length == requestUriSegments.length) {
+ return requestUri;
+ }
+
+ StringBuilder aliasBuilder = new StringBuilder();
+ for(int i=(requestUriSegments.length - pathInfoSegments.length + 1);i<requestUriSegments.length;i++) {
+ aliasBuilder.append(Const.SLASH).append(requestUriSegments[i]);
+ }
+ return aliasBuilder.toString();
+ }
/**
* @see HttpServlet#service(ServletRequest, ServletResponse)
@@ -62,7 +87,7 @@ public class ProxyServlet extends HttpServlet {
checkRuntime();
- String alias = HttpServletRequestWrapperImpl.getDispatchPathInfo(request);
+ String alias = getNotDecodedAlias(request);
if (alias == null) {
alias = Const.SLASH;

Back to the top