Bug 545135 - [http whiteboard] optimize context select matching a little bit

Signed-off-by: Raymond Auge <raymond.auge@liferay.com>
Change-Id: I7e8cbe08912b80ef317a022c8ecf9b73901df538
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ContextController.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ContextController.java
index 5620a6a..7b131d7 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ContextController.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ContextController.java
@@ -862,13 +862,21 @@
 	}
 
 	public boolean matches(ServiceReference<?> whiteBoardService) {
-		String contextSelector = (String) whiteBoardService.getProperty(
-			HTTP_WHITEBOARD_CONTEXT_SELECT);
 		// make sure the context helper is either one of the built-in ones registered by this http whiteboard implementation;
 		// or is visible to the whiteboard registering bundle.
+
 		if (!visibleContextHelper(whiteBoardService)) {
 			return false;
 		}
+
+		String contextSelector = (String) whiteBoardService.getProperty(
+			HTTP_WHITEBOARD_CONTEXT_SELECT);
+
+		// custom equinox behaviour
+		if (contextName.equals(contextSelector)) {
+			return true;
+		}
+
 		if (contextSelector == null) {
 			contextSelector = httpServiceRuntime.getDefaultContextSelectFilter(whiteBoardService);
 			if (contextSelector == null) {
@@ -878,22 +886,22 @@
 			}
 		}
 
-		if (!contextSelector.startsWith(Const.OPEN_PAREN)) {
-			contextSelector = Const.OPEN_PAREN +
-				HTTP_WHITEBOARD_CONTEXT_NAME +
-					Const.EQUAL + contextSelector + Const.CLOSE_PAREN;
+		if (contextSelector.startsWith(Const.OPEN_PAREN)) {
+			org.osgi.framework.Filter targetFilter;
+
+			try {
+				targetFilter = FrameworkUtil.createFilter(contextSelector);
+			}
+			catch (InvalidSyntaxException ise) {
+				throw new IllegalArgumentException(ise);
+			}
+
+			if (matches(targetFilter)) {
+				return true;
+			}
 		}
 
-		org.osgi.framework.Filter targetFilter;
-
-		try {
-			targetFilter = FrameworkUtil.createFilter(contextSelector);
-		}
-		catch (InvalidSyntaxException ise) {
-			throw new HttpWhiteboardFailureException(ise.getMessage(), DTOConstants.FAILURE_REASON_VALIDATION_FAILED);
-		}
-
-		return matches(targetFilter);
+		return false;
 	}
 
 	private boolean visibleContextHelper(ServiceReference<?> whiteBoardService) {