felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1814051 - in /felix/trunk/osgi-r7/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:29:11 GMT
Author: cziegeler
Date: Thu Nov  2 09:29:11 2017
New Revision: 1814051

URL: http://svn.apache.org/viewvc?rev=1814051&view=rev
Log:
FELIX-5736 : forward custom properties in a configuration to HttpRuntimeService. Apply patch
from J├╝rgen Albert

Modified:
    felix/trunk/osgi-r7/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
    felix/trunk/osgi-r7/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyConfigTest.java

Modified: felix/trunk/osgi-r7/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java?rev=1814051&r1=1814050&r2=1814051&view=diff
==============================================================================
--- felix/trunk/osgi-r7/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
(original)
+++ felix/trunk/osgi-r7/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
Thu Nov  2 09:29:11 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<String, Object> props)
+    {
+        final Enumeration<String> 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<String> list = new ArrayList<String>();
+            final List<String> 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<String> conv = new ArrayList<String>();
+            final ArrayList<String> conv = new ArrayList<>();
             for (Iterator<?> vi = ((Collection<?>) value).iterator(); vi.hasNext();)
             {
                 Object object = vi.next();

Modified: felix/trunk/osgi-r7/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyConfigTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyConfigTest.java?rev=1814051&r1=1814050&r2=1814051&view=diff
==============================================================================
--- felix/trunk/osgi-r7/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyConfigTest.java
(original)
+++ felix/trunk/osgi-r7/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyConfigTest.java
Thu Nov  2 09:29:11 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<String, Object> props = new Hashtable<String, Object>();
+        Hashtable<String, Object> 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<String, Object> props = new Hashtable<String, Object>();
+        Hashtable<String, Object> 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<String, Object> props = new Hashtable<String, Object>();
+        Hashtable<String, Object> 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<String, Object> props = new Hashtable<String, Object>();
+        Hashtable<String, Object> 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<String, Object> props = new Hashtable<String, Object>();
+        Hashtable<String, Object> 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<String, Object> props = new Hashtable<String, Object>();
+        Hashtable<String, Object> 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<String, Object> 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<String> 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<String, Object> 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<String>)toCheck.get("list")).size());
+        assertEquals("string2", ((List<String>)toCheck.get("list")).get(1));
+    }
+
     @Before
     public void setUp()
     {



Mime
View raw message