felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1734777 - in /felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty: internal/JettyActivator.java internal/JettyService.java package-info.java
Date Sun, 13 Mar 2016 10:34:34 GMT
Author: cziegeler
Date: Sun Mar 13 10:34:33 2016
New Revision: 1734777

URL: http://svn.apache.org/viewvc?rev=1734777&view=rev
Log:
FELIX-5207 : Flexible Customizer for 'Enable Proxy/Load Balancer Connection'. Apply slightly
modified patch from Antonio Sanso

Modified:
    felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java
    felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
    felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/package-info.java

Modified: felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java?rev=1734777&r1=1734776&r2=1734777&view=diff
==============================================================================
--- felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java
(original)
+++ felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java
Sun Mar 13 10:34:33 2016
@@ -20,6 +20,7 @@ import java.util.Dictionary;
 import java.util.Hashtable;
 
 import org.apache.felix.http.base.internal.AbstractHttpActivator;
+import org.apache.felix.http.jetty.LoadBalancerCustomizerFactory;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceFactory;
@@ -30,6 +31,7 @@ public final class JettyActivator extend
     private JettyService jetty;
 
     private ServiceRegistration<?> metatypeReg;
+    private ServiceRegistration<LoadBalancerCustomizerFactory> loadBalancerCustomizerFactoryReg;
 
     @Override
     protected void doStart() throws Exception
@@ -58,6 +60,29 @@ public final class JettyActivator extend
                 }, properties);
         this.jetty = new JettyService(getBundleContext(), getDispatcherServlet(), getEventDispatcher(),
getHttpServiceController());
         this.jetty.start();
+
+        final Dictionary<String, Object> propertiesCustomizer = new Hashtable<String,
Object>();
+        propertiesCustomizer.put(Constants.SERVICE_DESCRIPTION, "Load Balancer Customizer
Factory for Jetty Http Service");
+        propertiesCustomizer.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+        loadBalancerCustomizerFactoryReg = this.getBundleContext().registerService(LoadBalancerCustomizerFactory.class,
+                new ServiceFactory<LoadBalancerCustomizerFactory>()
+                {
+
+                    @Override
+                    public LoadBalancerCustomizerFactory getService(final Bundle bundle,
+                            final ServiceRegistration<LoadBalancerCustomizerFactory>
registration)
+                    {
+                        return new ForwardedRequestCustomizerFactory();
+                    }
+
+                    @Override
+                    public void ungetService(final Bundle bundle,
+                            final ServiceRegistration<LoadBalancerCustomizerFactory>
registration,
+                            final LoadBalancerCustomizerFactory service)
+                    {
+                        // nothing to do
+                    }
+                }, propertiesCustomizer);
     }
 
     @Override
@@ -69,6 +94,12 @@ public final class JettyActivator extend
             metatypeReg.unregister();
             metatypeReg = null;
         }
+        if ( loadBalancerCustomizerFactoryReg != null )
+        {
+            loadBalancerCustomizerFactoryReg.unregister();
+            loadBalancerCustomizerFactoryReg = null;
+        }
+
         super.doStop();
     }
 }

Modified: felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java?rev=1734777&r1=1734776&r2=1734777&view=diff
==============================================================================
--- felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
(original)
+++ felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
Sun Mar 13 10:34:33 2016
@@ -47,7 +47,6 @@ import org.eclipse.jetty.http.HttpVersio
 import org.eclipse.jetty.security.HashLoginService;
 import org.eclipse.jetty.server.Connector;
 import org.eclipse.jetty.server.ConnectorStatistics;
-import org.eclipse.jetty.server.ForwardedRequestCustomizer;
 import org.eclipse.jetty.server.HttpConfiguration;
 import org.eclipse.jetty.server.HttpConnectionFactory;
 import org.eclipse.jetty.server.SecureRequestCustomizer;
@@ -105,6 +104,8 @@ public final class JettyService extends
     private BundleTracker bundleTracker;
     private ServiceTracker eventAdmintTracker;
     private ServiceTracker connectorTracker;
+    private ServiceTracker loadBalancerCustomizerTracker;
+    private CustomizerWrapper customizerWrapper;
     private EventAdmin eventAdmin;
 
     public JettyService(final BundleContext context,
@@ -218,6 +219,13 @@ public final class JettyService extends
                 this.connectorTracker.close();
                 this.connectorTracker = null;
             }
+            
+            if (this.loadBalancerCustomizerTracker != null)
+            {
+                this.loadBalancerCustomizerTracker.close();
+                this.loadBalancerCustomizerTracker = null;
+            } 
+            
             try
             {
                 this.server.stop();
@@ -276,8 +284,14 @@ public final class JettyService extends
             this.server.setHandler(this.parent);
             this.server.start();
 
+            if (this.config.isProxyLoadBalancerConnection()) 
+            {
+                customizerWrapper = new CustomizerWrapper();
+                this.loadBalancerCustomizerTracker = new LoadBalancerCustomizerFactoryTracker(this.context,
customizerWrapper);
+                this.loadBalancerCustomizerTracker.open();
+            }
+            
             final StringBuilder message = new StringBuilder("Started Jetty ").append(version).append("
at port(s)");
-
             if (this.config.isUseHttp() && initializeHttp())
             {
                 message.append(" HTTP:").append(this.config.getHttpPort());
@@ -290,7 +304,7 @@ public final class JettyService extends
 
             this.connectorTracker = new ConnectorFactoryTracker(this.context, this.server);
             this.connectorTracker.open();
-
+            
             if (this.server.getConnectors() != null && this.server.getConnectors().length
> 0)
             {
                 message.append(" on context path ").append(this.config.getContextPath());
@@ -355,11 +369,10 @@ public final class JettyService extends
 
         configureConnector(connector, this.config.getHttpPort());
 
-        if (this.config.isProxyLoadBalancerConnection())
+        if (this.config.isProxyLoadBalancerConnection()) 
         {
-            connFactory.getHttpConfiguration().addCustomizer(new ForwardedRequestCustomizer());
+            connFactory.getHttpConfiguration().addCustomizer(customizerWrapper);
         }
-
         return startConnector(connector);
     }
 
@@ -382,11 +395,11 @@ public final class JettyService extends
         HttpConfiguration httpConfiguration = connFactory.getHttpConfiguration();
         httpConfiguration.addCustomizer(new SecureRequestCustomizer());
 
-        if (this.config.isProxyLoadBalancerConnection())
+        if (this.config.isProxyLoadBalancerConnection()) 
         {
-            httpConfiguration.addCustomizer(new ForwardedRequestCustomizer());
+            httpConfiguration.addCustomizer(customizerWrapper);
         }
-
+        
         configureConnector(connector, this.config.getHttpsPort());
         return startConnector(connector);
     }

Modified: felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/package-info.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/package-info.java?rev=1734777&r1=1734776&r2=1734777&view=diff
==============================================================================
--- felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/package-info.java (original)
+++ felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/package-info.java Sun
Mar 13 10:34:33 2016
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-@Version("2.0")
+@Version("2.1")
 package org.apache.felix.http.jetty;
 
 import org.osgi.annotation.versioning.Version;
\ No newline at end of file



Mime
View raw message