Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 070C6200D2B for ; Thu, 2 Nov 2017 10:27:19 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 05762160BE5; Thu, 2 Nov 2017 09:27:19 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 23B8D1609EE for ; Thu, 2 Nov 2017 10:27:17 +0100 (CET) Received: (qmail 835 invoked by uid 500); 2 Nov 2017 09:27:17 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 822 invoked by uid 99); 2 Nov 2017 09:27:17 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Nov 2017 09:27:17 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id CAF513A01E5 for ; Thu, 2 Nov 2017 09:27:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1814050 - in /felix/trunk/http/jetty/src: main/java/org/apache/felix/http/jetty/internal/JettyConfig.java test/java/org/apache/felix/http/jetty/internal/JettyConfigTest.java Date: Thu, 02 Nov 2017 09:27:12 -0000 To: commits@felix.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20171102092715.CAF513A01E5@svn01-us-west.apache.org> archived-at: Thu, 02 Nov 2017 09:27:19 -0000 Author: cziegeler Date: Thu Nov 2 09:27:12 2017 New Revision: 1814050 URL: http://svn.apache.org/viewvc?rev=1814050&view=rev Log: FELIX-5736 : forward custom properties in a configuration to HttpRuntimeService. Apply patch from Jürgen Albert Modified: felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java felix/trunk/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyConfigTest.java Modified: felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java URL: http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java?rev=1814050&r1=1814049&r2=1814050&view=diff ============================================================================== --- felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java (original) +++ felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java Thu Nov 2 09:27:12 2017 @@ -22,6 +22,7 @@ import java.security.KeyStore; import java.util.ArrayList; import java.util.Collection; import java.util.Dictionary; +import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; import java.util.List; @@ -164,6 +165,8 @@ public final class JettyConfig /** Felix specific property to set HTTP instance name. */ public static final String FELIX_HTTP_SERVICE_NAME = "org.apache.felix.http.name"; + /** Felix specific property to define custom properties for the http runtime service. */ + public static final String FELIX_CUSTOM_HTTP_RUNTIME_PROPERTY_PREFIX = "org.apache.felix.http.runtime.init."; private static String validateContextPath(String ctxPath) { @@ -437,6 +440,20 @@ public final class JettyConfig { props.put(FELIX_HTTP_SERVICE_NAME, getHttpServiceName()); } + addCustomServiceProperties(props); + } + + private void addCustomServiceProperties(final Hashtable props) + { + final Enumeration keys = this.config.keys(); + while(keys.hasMoreElements()) + { + final String key = keys.nextElement(); + if (key.startsWith(FELIX_CUSTOM_HTTP_RUNTIME_PROPERTY_PREFIX)) + { + props.put(key.substring(FELIX_CUSTOM_HTTP_RUNTIME_PROPERTY_PREFIX.length()), this.config.get(key)); + } + } } /** @@ -608,7 +625,7 @@ public final class JettyConfig else if (value instanceof String[]) { final String[] stringArr = (String[]) value; - final List list = new ArrayList(); + final List list = new ArrayList<>(); for (final String stringVal : stringArr) { if (stringVal.trim().length() > 0) @@ -623,7 +640,7 @@ public final class JettyConfig } else if (value instanceof Collection) { - final ArrayList conv = new ArrayList(); + final ArrayList conv = new ArrayList<>(); for (Iterator vi = ((Collection) value).iterator(); vi.hasNext();) { Object object = vi.next(); Modified: felix/trunk/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyConfigTest.java URL: http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyConfigTest.java?rev=1814050&r1=1814049&r2=1814050&view=diff ============================================================================== --- felix/trunk/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyConfigTest.java (original) +++ felix/trunk/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyConfigTest.java Thu Nov 2 09:27:12 2017 @@ -22,7 +22,9 @@ import static org.junit.Assert.assertArr import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.util.ArrayList; import java.util.Hashtable; +import java.util.List; import org.junit.Before; import org.junit.Test; @@ -44,7 +46,7 @@ public class JettyConfigTest @Test public void testGetPortInRange() { - Hashtable props = new Hashtable(); + Hashtable props = new Hashtable<>(); props.put("org.osgi.service.http.port", "[8000,9000]"); props.put("org.osgi.service.http.port.secure", "[10000,11000)"); this.config.update(props); @@ -69,7 +71,7 @@ public class JettyConfigTest @Test public void testGetPortInvalidRange() { - Hashtable props = new Hashtable(); + Hashtable props = new Hashtable<>(); props.put("org.osgi.service.http.port", "+12000,13000*"); props.put("org.osgi.service.http.port.secure", "%14000,15000"); this.config.update(props); @@ -80,7 +82,7 @@ public class JettyConfigTest @Test public void testGetSpecificPortOne() throws Exception { - Hashtable props = new Hashtable(); + Hashtable props = new Hashtable<>(); props.put("org.osgi.service.http.port", "1"); this.config.update(props); assertTrue(this.config.getHttpPort() == 1); @@ -88,7 +90,7 @@ public class JettyConfigTest @Test public void testGetRandomPort() { - Hashtable props = new Hashtable(); + Hashtable props = new Hashtable<>(); props.put("org.osgi.service.http.port", "*"); props.put("org.osgi.service.http.port.secure", "*"); this.config.update(props); @@ -98,7 +100,7 @@ public class JettyConfigTest @Test public void testGetRandomPortZero() throws Exception { - Hashtable props = new Hashtable(); + Hashtable props = new Hashtable<>(); props.put("org.osgi.service.http.port", "0"); this.config.update(props); assertTrue(this.config.getHttpPort() != 0); @@ -108,7 +110,7 @@ public class JettyConfigTest { int port = 80; - Hashtable props = new Hashtable(); + Hashtable props = new Hashtable<>(); props.put("org.osgi.service.http.port", port); props.put("org.osgi.service.http.port.secure", port); this.config.update(props); @@ -125,6 +127,29 @@ public class JettyConfigTest assertArrayEquals(expecteds, this.config.getExcludedCipherSuites()); } + @SuppressWarnings("unchecked") + @Test public void testAdditionalCustomProperties() { + Hashtable props = new Hashtable<>(); + props.put(JettyConfig.FELIX_CUSTOM_HTTP_RUNTIME_PROPERTY_PREFIX + "number", 5); + props.put(JettyConfig.FELIX_CUSTOM_HTTP_RUNTIME_PROPERTY_PREFIX + "string", "testString"); + List list = new ArrayList<>(3); + list.add("string1"); + list.add("string2"); + list.add("string3"); + props.put(JettyConfig.FELIX_CUSTOM_HTTP_RUNTIME_PROPERTY_PREFIX + "list", list); + this.config.update(props); + + Hashtable toCheck = new Hashtable<>(); + + this.config.setServiceProperties(toCheck); + + assertEquals(5, toCheck.get("number")); + assertEquals("testString", toCheck.get("string")); + assertTrue(toCheck.get("list") instanceof List); + assertEquals(3, ((List)toCheck.get("list")).size()); + assertEquals("string2", ((List)toCheck.get("list")).get(1)); + } + @Before public void setUp() {