diff options
author | Thomas Watson | 2015-03-19 15:38:27 +0000 |
---|---|---|
committer | Thomas Watson | 2015-03-23 13:21:04 +0000 |
commit | 2bfd73b11a100afdba892e228ae84741e15d4d89 (patch) | |
tree | 43533204604de27329bf3be281a44b7ed9a62652 | |
parent | 38cd951e9d2ecbce016c73bf1eb689f1c3b719d4 (diff) | |
download | rt.equinox.bundles-2bfd73b11a100afdba892e228ae84741e15d4d89.tar.gz rt.equinox.bundles-2bfd73b11a100afdba892e228ae84741e15d4d89.tar.xz rt.equinox.bundles-2bfd73b11a100afdba892e228ae84741e15d4d89.zip |
Bug 462581 - [http whiteboard] Issues with context root of SLASH andI20150324-0800
ContextPathCustomizer which may result in a context path ending in '/'
Change-Id: Id35e90877d2fd592eb5c1d12a0997e600482be74
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
2 files changed, 43 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 3f30d3e30..60a7bd3c6 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 @@ -1913,7 +1913,46 @@ public class ServletTest extends TestCase { } } + public void testWBServletDefaultContextAdaptor3() throws Exception{ + // test the ContextPathCustomizer with a ServletContextHelper that has a '/' context path + Dictionary<String, String> helperProps = new Hashtable<String, String>(); + helperProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, "testContext" + getName()); + helperProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, "/"); + helperProps.put(TEST_PATH_CUSTOMIZER_NAME, getName()); + ServiceRegistration<ServletContextHelper> helperReg = getBundleContext().registerService(ServletContextHelper.class, new TestServletContextHelperFactory(), helperProps); + + ServiceRegistration<ContextPathCustomizer> pathAdaptorReg = null; + try { + Map<String, String> params = new HashMap<String, String>(); + params.put(TEST_PROTOTYPE_NAME, getName()); + params.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, '/' + getName()); + params.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT, "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=" + "testContext" + getName() + ")"); + params.put(STATUS_PARAM, getName()); + params.put("servlet.init." + TEST_PATH_CUSTOMIZER_NAME, getName()); + String actual = doRequest(CONFIGURE, params); + Assert.assertEquals(getName(), actual); + + actual = requestAdvisor.request(getName()); + Assert.assertEquals(getName(), actual); + ContextPathCustomizer pathAdaptor = new TestContextPathAdaptor(null, "testPrefix", getName()); + pathAdaptorReg = getBundleContext().registerService(ContextPathCustomizer.class, pathAdaptor, null); + + actual = requestAdvisor.request("testPrefix/" + getName()); + Assert.assertEquals(getName(), actual); + + pathAdaptorReg.unregister(); + pathAdaptorReg = null; + + actual = requestAdvisor.request(getName()); + Assert.assertEquals(getName(), actual); + } finally { + helperReg.unregister(); + if (pathAdaptorReg != null) { + pathAdaptorReg.unregister(); + } + } + } private String doRequest(String action, Map<String, String> params) throws IOException { StringBuilder requestInfo = new StringBuilder(PROTOTYPE); 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 05bbc0cf3..48580a037 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 @@ -136,6 +136,10 @@ public class HttpServiceRuntimeImpl if (!contextPrefix.startsWith(Const.SLASH)) { contextPrefix = Const.SLASH + contextPrefix; } + // make sure we do not append SLASH context path here + if (contextPath == null || contextPath.equals(Const.SLASH)) { + contextPath = Const.BLANK; + } return contextPrefix + contextPath; } } |