Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Auge2018-01-20 02:56:33 +0000
committerRaymond Auge2018-01-22 15:55:42 +0000
commit8640d436cb326bf2a59c322d59d4d0a1ff0763e3 (patch)
tree6ce8b09f322e79c4e120baf11d0dd0e53442c06f
parent5951364be6642087127fd0ea77b39a70017223b9 (diff)
downloadrt.equinox.bundles-8640d436cb326bf2a59c322d59d4d0a1ff0763e3.tar.gz
rt.equinox.bundles-8640d436cb326bf2a59c322d59d4d0a1ff0763e3.tar.xz
rt.equinox.bundles-8640d436cb326bf2a59c322d59d4d0a1ff0763e3.zip
Bug 530064 - [http servlet] Temp directory created by ProxyContext should be different for different servlet context
or else the temp folder created will be removed when a new ProxyContext is generated. Signed-off-by: Raymond Auge <raymond.auge@liferay.com> Signed-off-by: Tina Tian <tina.tian@liferay.com> Change-Id: I145859cb6a831c1efd229a2498d5f438cc180fa6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java51
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java2
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ProxyContext.java5
3 files changed, 55 insertions, 3 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 e1d3cef73..bc3de7dbd 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
@@ -2902,6 +2902,57 @@ public class ServletTest extends BaseTest {
}
@Test
+ public void test_ServletContextHelper14_uniqueTempDirs() throws Exception {
+ BundleContext bundleContext = getBundleContext();
+ Bundle bundle = bundleContext.getBundle();
+
+ ServletContextHelper servletContextHelperA = new ServletContextHelper(bundle){};
+ ServletContextHelper servletContextHelperB = new ServletContextHelper(bundle){};
+
+ Collection<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
+ try {
+ final AtomicReference<File> fileA = new AtomicReference<File>();
+
+ Servlet servletA = new HttpServlet() {
+ private static final long serialVersionUID = 1L;
+ @Override
+ protected void service(HttpServletRequest req, HttpServletResponse resp)
+ throws IOException, ServletException {
+ fileA.set((File)getServletContext().getAttribute(ServletContext.TEMPDIR));
+ new File(fileA.get(), "test").createNewFile();
+ }
+ };
+
+ Dictionary<String, String> contextProps = new Hashtable<String, String>();
+ contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, "a");
+ contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, "/a");
+ registrations.add(bundleContext.registerService(ServletContextHelper.class, servletContextHelperA, contextProps));
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT, "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=a)");
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "SA");
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/SA");
+ registrations.add(getBundleContext().registerService(Servlet.class, servletA, props));
+
+ requestAdvisor.request("a/SA");
+ Assert.assertNotNull(fileA.get());
+ Assert.assertTrue(new File(fileA.get(), "test").exists());
+
+ contextProps = new Hashtable<String, String>();
+ contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, "b");
+ contextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, "/b");
+ registrations.add(bundleContext.registerService(ServletContextHelper.class, servletContextHelperB, contextProps));
+
+ Assert.assertNotNull(fileA.get());
+ Assert.assertTrue(new File(fileA.get(), "test").exists());
+ }
+ 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/HttpServiceRuntimeImpl.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java
index c25aa85eb..7bd6d5649 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
@@ -114,7 +114,7 @@ public class HttpServiceRuntimeImpl
contextPath = adaptContextPath(contextPath, serviceReference);
ContextController contextController = new ContextController(
- trackingContext, consumingContext, serviceReference, new ProxyContext(parentServletContext),
+ trackingContext, consumingContext, serviceReference, new ProxyContext(contextName, parentServletContext),
this, contextName, contextPath, httpSessionTracker);
controllerMap.put(serviceReference, contextController);
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ProxyContext.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ProxyContext.java
index 14a14d477..d722af577 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ProxyContext.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ProxyContext.java
@@ -37,11 +37,12 @@ public class ProxyContext {
File proxyContextTempDir;
private ServletContext servletContext;
- public ProxyContext(ServletContext servletContext) {
+ public ProxyContext(String contextName, ServletContext servletContext) {
this.servletContext = servletContext;
File tempDir = (File) servletContext.getAttribute(JAVAX_SERVLET_CONTEXT_TEMPDIR);
if (tempDir != null) {
- proxyContextTempDir = new File(tempDir, "proxytemp"); //$NON-NLS-1$
+ tempDir = new File(tempDir, "proxytemp"); //$NON-NLS-1$
+ proxyContextTempDir = new File(tempDir, contextName);
deleteDirectory(proxyContextTempDir);
proxyContextTempDir.mkdirs();
}

Back to the top