Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Auge2016-04-13 03:27:27 +0000
committerRaymond Auge2016-04-13 03:27:27 +0000
commit3718d2e92787fa4286056a88fc313e2d8f110631 (patch)
tree30960430847913ad69a590498802dba4da0a1419
parent0d5a1a04a5679853ed95fa8e097c578791add100 (diff)
downloadrt.equinox.bundles-3718d2e92787fa4286056a88fc313e2d8f110631.tar.gz
rt.equinox.bundles-3718d2e92787fa4286056a88fc313e2d8f110631.tar.xz
rt.equinox.bundles-3718d2e92787fa4286056a88fc313e2d8f110631.zip
Bug 491557 - [http whiteboard] prefix the value of the osgi.http.endpoint init param with the context
path of the current app Signed-off-by: Raymond Auge <raymond.auge@liferay.com>
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/DispatchingTest.java38
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/Activator.java32
2 files changed, 62 insertions, 8 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 d9b8194d6..42828f2b9 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
@@ -13,6 +13,7 @@ package org.eclipse.equinox.http.servlet.tests;
import java.io.IOException;
import java.io.PrintWriter;
+import java.io.StringWriter;
import java.util.Arrays;
import java.util.Dictionary;
import java.util.Hashtable;
@@ -45,6 +46,43 @@ import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
public class DispatchingTest extends BaseTest {
@Test
+ public void test_crossContextDispatch1() throws Exception {
+ Servlet servlet1 = new BaseServlet() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ StringWriter writer = new StringWriter();
+
+ writer.write(request.getContextPath());
+ writer.write("|");
+
+ ServletContext servletContext = getServletContext().getContext("/");
+
+ writer.write(servletContext.getContextPath());
+
+ response.getWriter().write(writer.toString());
+ }
+ };
+
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, "a");
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, "/a");
+ registrations.add(getBundleContext().registerService(ServletContextHelper.class, new ServletContextHelper() {}, props));
+
+ props = new Hashtable<String, Object>();
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/s1/*");
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT, "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=a)");
+ registrations.add(getBundleContext().registerService(Servlet.class, servlet1, props));
+
+ String response = requestAdvisor.request("a/s1/d");
+
+ Assert.assertEquals("/a|", response);
+ }
+
+ @Test
public void test_forwardDepth1() throws Exception {
Servlet servlet1 = new BaseServlet() {
private static final long serialVersionUID = 1L;
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/Activator.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/Activator.java
index e4ecd0586..d6dc49e59 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/Activator.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/Activator.java
@@ -21,8 +21,7 @@ import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import org.eclipse.equinox.http.servlet.ExtendedHttpService;
import org.eclipse.equinox.http.servlet.internal.servlet.ProxyServlet;
-import org.eclipse.equinox.http.servlet.internal.util.HttpTuple;
-import org.eclipse.equinox.http.servlet.internal.util.UMDictionaryMap;
+import org.eclipse.equinox.http.servlet.internal.util.*;
import org.osgi.framework.*;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.runtime.HttpServiceRuntime;
@@ -106,9 +105,6 @@ public class Activator
ServletConfig servletConfig = proxyServlet.getServletConfig();
ServletContext servletContext = servletConfig.getServletContext();
- String[] httpServiceEndpoints = getHttpServiceEndpoints(
- servletContext, servletConfig.getServletName());
-
Dictionary<String, Object> serviceProperties =
new Hashtable<String, Object>(3);
@@ -132,8 +128,28 @@ public class Activator
Constants.SERVICE_DESCRIPTION, DEFAULT_SERVICE_DESCRIPTION);
}
- if (serviceProperties.get(
- HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT) == null) {
+ Object httpServiceEndpointObj = serviceProperties.get(HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT);
+
+ if (httpServiceEndpointObj == null) {
+ String[] httpServiceEndpoints = getHttpServiceEndpoints(
+ servletContext, servletConfig.getServletName());
+
+ serviceProperties.put(
+ HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT,
+ httpServiceEndpoints);
+ }
+ else {
+ List<String> httpServiceEndpoints = new ArrayList<String>();
+
+ String contextPath = servletContext.getContextPath();
+
+ for (String httpServiceEndpoint : StringPlus.from(httpServiceEndpointObj)) {
+ if (!httpServiceEndpoint.startsWith(Const.HTTP.concat(":")) && !httpServiceEndpoint.startsWith(contextPath)) { //$NON-NLS-1$
+ httpServiceEndpoint = contextPath + httpServiceEndpoint;
+ }
+
+ httpServiceEndpoints.add(httpServiceEndpoint);
+ }
serviceProperties.put(
HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT,
@@ -219,7 +235,7 @@ public class Activator
for (String mapping : mappings) {
if (mapping.indexOf('/') == 0) {
if (mapping.charAt(mapping.length() - 1) == '*') {
- mapping = mapping.substring(0, mapping.length() - 2);
+ mapping = mapping.substring(0, mapping.length() - 1);
if ((mapping.length() > 1) &&
(mapping.charAt(mapping.length() - 1) != '/')) {

Back to the top