Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2018-08-28 17:52:49 +0000
committerThomas Watson2018-08-28 18:38:56 +0000
commita10afe24478d5fee6e5d696a4e877511b270f4d4 (patch)
treed644b9877dc6cac1e728bff8a54a43850e9dca73
parenta05e887ec911edc1bdde68182cf6a2dbad65915e (diff)
downloadrt.equinox.bundles-a10afe24478d5fee6e5d696a4e877511b270f4d4.tar.gz
rt.equinox.bundles-a10afe24478d5fee6e5d696a4e877511b270f4d4.tar.xz
rt.equinox.bundles-a10afe24478d5fee6e5d696a4e877511b270f4d4.zip
Change-Id: I1434aa0eb991ced8c20dab264e5735cfce7c8666 Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java92
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ProxyServlet.java5
2 files changed, 97 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java
index de740d41..fe0f8cc8 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java
@@ -3309,6 +3309,98 @@ public class ServletTest extends BaseTest {
}
@Test
+ public void test_getRequestURI_trailingSlash1() throws Exception {
+ try {
+ stopJetty();
+ System.setProperty("org.eclipse.equinox.http.jetty.context.path", "/foo");
+ }
+ finally {
+ startJetty();
+ }
+
+ Collection<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
+ try {
+ final AtomicReference<String> getRequestURI = new AtomicReference<String>();
+
+ Servlet servletA = new HttpServlet() {
+ private static final long serialVersionUID = 1L;
+ @Override
+ protected void service(HttpServletRequest req, HttpServletResponse resp)
+ throws IOException, ServletException {
+ getRequestURI.set(req.getRequestURI());
+ }
+ };
+
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "SA");
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/*");
+ registrations.add(getBundleContext().registerService(Servlet.class, servletA, props));
+ props = new Hashtable<String, Object>();
+
+ requestAdvisor.request("a/b/c/");
+ Assert.assertEquals("/foo/a/b/c/", getRequestURI.get());
+ requestAdvisor.request("a/b/");
+ Assert.assertEquals("/foo/a/b/", getRequestURI.get());
+ requestAdvisor.request("a/");
+ Assert.assertEquals("/foo/a/", getRequestURI.get());
+ requestAdvisor.request("/");
+ Assert.assertEquals("/foo/", getRequestURI.get());
+ }
+ finally {
+ for (ServiceRegistration<?> registration : registrations) {
+ registration.unregister();
+ }
+ try {
+ stopJetty();
+ System.setProperty("org.eclipse.equinox.http.jetty.context.path", "");
+ }
+ finally {
+ startJetty();
+ }
+ }
+ }
+
+ @Test
+ public void test_getRequestURI_trailingSlash2() throws Exception {
+ Collection<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
+ try {
+ final AtomicReference<String> getRequestURI = new AtomicReference<String>();
+
+ Servlet servletA = new HttpServlet() {
+ private static final long serialVersionUID = 1L;
+ @Override
+ protected void service(HttpServletRequest req, HttpServletResponse resp)
+ throws IOException, ServletException {
+ getRequestURI.set(req.getRequestURI());
+ }
+ };
+
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "SA");
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/*");
+ registrations.add(getBundleContext().registerService(Servlet.class, servletA, props));
+ props = new Hashtable<String, Object>();
+
+ requestAdvisor.request("a/b/c/");
+ Assert.assertEquals("/a/b/c/", getRequestURI.get());
+ requestAdvisor.request("a/b/");
+ Assert.assertEquals("/a/b/", getRequestURI.get());
+ requestAdvisor.request("a/");
+ Assert.assertEquals("/a/", getRequestURI.get());
+ // Note using empty string here because of the way requestAdvisor works
+ // by appending a slash first.
+ requestAdvisor.request("");
+ Assert.assertEquals("/", getRequestURI.get());
+ }
+ finally {
+ for (ServiceRegistration<?> registration : registrations) {
+ registration.unregister();
+ }
+ }
+ }
+
+
+ @Test
public void test_Listener1() throws Exception {
BaseServletContextListener scl1 =
new BaseServletContextListener();
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 805aaf48..db26e9dc 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
@@ -67,6 +67,7 @@ public class ProxyServlet extends HttpServlet {
}
String requestUri = HttpServletRequestWrapperImpl.getDispatchRequestURI(request);
+ // NOTE split does not include trailing empty strings for paths that end in SLASH
String[] pathInfoSegments = pathInfo.split(Const.SLASH);
String[] requestUriSegments = requestUri.split(Const.SLASH);
@@ -78,6 +79,10 @@ public class ProxyServlet extends HttpServlet {
for(int i=(requestUriSegments.length - pathInfoSegments.length + 1);i<requestUriSegments.length;i++) {
aliasBuilder.append(Const.SLASH).append(requestUriSegments[i]);
}
+ // if the original request ends in '/' then be sure to append a '/'
+ if (requestUri.endsWith(Const.SLASH)) {
+ aliasBuilder.append(Const.SLASH);
+ }
return aliasBuilder.toString();
}

Back to the top