Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/pom.xml2
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/AllTests.java2
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/BaseTest.java32
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/Test_140_7_validation.java70
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextListenerTrackerCustomizer.java14
6 files changed, 118 insertions, 4 deletions
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.http.servlet.tests/META-INF/MANIFEST.MF
index cf06baa9..0db378b8 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: org.eclipse.equinox.http.servlet.tests
Bundle-SymbolicName: org.eclipse.equinox.http.servlet.tests
-Bundle-Version: 1.6.0.qualifier
+Bundle-Version: 1.6.100.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Eclipse-BundleShape: dir
Require-Bundle: org.junit;bundle-version="4.0"
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/pom.xml b/bundles/org.eclipse.equinox.http.servlet.tests/pom.xml
index 8fef0fb0..efc58ce4 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/pom.xml
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/pom.xml
@@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.equinox</groupId>
<artifactId>org.eclipse.equinox.http.servlet.tests</artifactId>
- <version>1.6.0-SNAPSHOT</version>
+ <version>1.6.100-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<build>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/AllTests.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/AllTests.java
index 129fca46..44aa6354 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/AllTests.java
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/AllTests.java
@@ -35,6 +35,7 @@ import org.eclipse.equinox.http.servlet.tests.Test_140_4_42to44;
import org.eclipse.equinox.http.servlet.tests.Test_140_4_9;
import org.eclipse.equinox.http.servlet.tests.Test_140_6_1;
import org.eclipse.equinox.http.servlet.tests.Test_140_6_20to21_commonProperties;
+import org.eclipse.equinox.http.servlet.tests.Test_140_7_validation;
import org.eclipse.equinox.http.servlet.tests.Test_140_9_ServletContextDTO_custom_listener;
import org.eclipse.equinox.http.servlet.tests.Test_140_9_ServletContextDTO_default_listener;
import org.eclipse.equinox.http.servlet.tests.Test_table_140_1_HTTP_WHITEBOARD_CONTEXT_NAME_bindUsingContextSelect;
@@ -74,6 +75,7 @@ import org.junit.runners.Suite.SuiteClasses;
Test_140_4_9.class,
Test_140_6_1.class,
Test_140_6_20to21_commonProperties.class,
+ Test_140_7_validation.class,
Test_140_9_ServletContextDTO_custom_listener.class,
Test_140_9_ServletContextDTO_default_listener.class,
Test_table_140_1_HTTP_WHITEBOARD_CONTEXT_NAME_bindUsingContextSelect.class,
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/BaseTest.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/BaseTest.java
index e4f2617f..bb9800db 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/BaseTest.java
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/BaseTest.java
@@ -66,10 +66,12 @@ import org.osgi.service.http.runtime.HttpServiceRuntimeConstants;
import org.osgi.service.http.runtime.dto.ErrorPageDTO;
import org.osgi.service.http.runtime.dto.FailedErrorPageDTO;
import org.osgi.service.http.runtime.dto.FailedFilterDTO;
+import org.osgi.service.http.runtime.dto.FailedListenerDTO;
import org.osgi.service.http.runtime.dto.FailedResourceDTO;
import org.osgi.service.http.runtime.dto.FailedServletContextDTO;
import org.osgi.service.http.runtime.dto.FailedServletDTO;
import org.osgi.service.http.runtime.dto.FilterDTO;
+import org.osgi.service.http.runtime.dto.ListenerDTO;
import org.osgi.service.http.runtime.dto.RequestInfoDTO;
import org.osgi.service.http.runtime.dto.ResourceDTO;
import org.osgi.service.http.runtime.dto.ServletContextDTO;
@@ -339,6 +341,22 @@ public class BaseTest {
return getBundleContext().getService(serviceReference);
}
+ protected ListenerDTO getListenerDTOByServiceId(String contextName, long serviceId) {
+ ServletContextDTO servletContextDTO = getServletContextDTOByName(contextName);
+
+ if (servletContextDTO == null) {
+ return null;
+ }
+
+ for (ListenerDTO listenerDTO : servletContextDTO.listenerDTOs) {
+ if (serviceId == listenerDTO.serviceId) {
+ return listenerDTO;
+ }
+ }
+
+ return null;
+ }
+
protected long getServiceId(ServiceRegistration<?> sr) {
return (Long) sr.getReference().getProperty(Constants.SERVICE_ID);
}
@@ -441,6 +459,20 @@ public class BaseTest {
return getHttpServiceRuntime().getRuntimeDTO().failedFilterDTOs;
}
+ protected FailedListenerDTO getFailedListenerDTOByServiceId(long serviceId) {
+ for (FailedListenerDTO failedListenerDTO : getFailedListenerDTOs()) {
+ if (serviceId == failedListenerDTO.serviceId) {
+ return failedListenerDTO;
+ }
+ }
+
+ return null;
+ }
+
+ protected FailedListenerDTO[] getFailedListenerDTOs() {
+ return getHttpServiceRuntime().getRuntimeDTO().failedListenerDTOs;
+ }
+
protected FailedServletContextDTO getFailedServletContextDTOByName(String name) {
for (FailedServletContextDTO failedServletContextDTO : getFailedServletContextDTOs()) {
if (name.equals(failedServletContextDTO.name)) {
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/Test_140_7_validation.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/Test_140_7_validation.java
new file mode 100644
index 00000000..ea71d846
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/Test_140_7_validation.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) Mar. 28, 2019 Liferay, Inc.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Liferay, Inc. - tests
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextListener;
+
+import org.eclipse.equinox.http.servlet.testbase.BaseTest;
+import org.eclipse.equinox.http.servlet.tests.util.MockSCL;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.http.runtime.dto.DTOConstants;
+import org.osgi.service.http.runtime.dto.FailedListenerDTO;
+import org.osgi.service.http.runtime.dto.ListenerDTO;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+
+public class Test_140_7_validation extends BaseTest {
+
+ @Test
+ public void test_140_7_validation() throws Exception {
+ BundleContext context = getBundleContext();
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, "true");
+ ServiceRegistration<?> sr = context.registerService(
+ ServletContextListener.class, new MockSCL(new AtomicReference<ServletContext>()), properties);
+ registrations.add(sr);
+
+ ListenerDTO listenerDTO = getListenerDTOByServiceId(DEFAULT, getServiceId(sr));
+ assertNotNull(listenerDTO);
+
+ properties.remove(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER);
+ sr.setProperties(properties);
+
+ listenerDTO = getListenerDTOByServiceId(DEFAULT, getServiceId(sr));
+ assertNull(listenerDTO);
+
+ properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, "blah");
+ sr.setProperties(properties);
+
+ FailedListenerDTO failedListenerDTO = getFailedListenerDTOByServiceId(getServiceId(sr));
+ assertNotNull(failedListenerDTO);
+ assertEquals(DTOConstants.FAILURE_REASON_VALIDATION_FAILED, failedListenerDTO.failureReason);
+
+ listenerDTO = getListenerDTOByServiceId(DEFAULT, getServiceId(sr));
+ assertNull(listenerDTO);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextListenerTrackerCustomizer.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextListenerTrackerCustomizer.java
index ecc40fd5..9dfc7b04 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextListenerTrackerCustomizer.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextListenerTrackerCustomizer.java
@@ -67,13 +67,23 @@ public class ContextListenerTrackerCustomizer
Object listenerObj = serviceReference.getProperty(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER);
- if (!(listenerObj instanceof Boolean) && !(listenerObj instanceof String)) {
+ if (!(listenerObj instanceof Boolean) &&
+ !"true".equalsIgnoreCase(String.valueOf(listenerObj)) && //$NON-NLS-1$
+ !"false".equalsIgnoreCase(String.valueOf(listenerObj)) && //$NON-NLS-1$
+ !"1".equalsIgnoreCase(String.valueOf(listenerObj)) && //$NON-NLS-1$
+ !"0".equalsIgnoreCase(String.valueOf(listenerObj)) && //$NON-NLS-1$
+ !"yes".equalsIgnoreCase(String.valueOf(listenerObj)) && //$NON-NLS-1$
+ !"no".equalsIgnoreCase(String.valueOf(listenerObj)) //$NON-NLS-1$
+ ) {
throw new HttpWhiteboardFailureException(
HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER + "=" + listenerObj + " is not a valid option. Ignoring!", //$NON-NLS-1$ //$NON-NLS-2$
DTOConstants.FAILURE_REASON_VALIDATION_FAILED);
}
- if (Boolean.FALSE.equals(listenerObj) || !Boolean.valueOf(String.valueOf(listenerObj)).booleanValue()) {
+ if (Boolean.FALSE.equals(listenerObj) ||
+ "false".equalsIgnoreCase(String.valueOf(listenerObj)) || //$NON-NLS-1$
+ "0".equalsIgnoreCase(String.valueOf(listenerObj)) || //$NON-NLS-1$
+ "no".equalsIgnoreCase(String.valueOf(listenerObj))) { //$NON-NLS-1$
// Asks to be ignored.
return result;
}

Back to the top