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 3288B200B82 for ; Fri, 16 Sep 2016 09:03:55 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 31197160AC4; Fri, 16 Sep 2016 07:03:55 +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 26466160A8C for ; Fri, 16 Sep 2016 09:03:53 +0200 (CEST) Received: (qmail 20859 invoked by uid 500); 16 Sep 2016 07:03:53 -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 20850 invoked by uid 99); 16 Sep 2016 07:03:53 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Sep 2016 07:03:53 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id E8F92C7043 for ; Fri, 16 Sep 2016 07:03:52 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.676 X-Spam-Level: X-Spam-Status: No, score=0.676 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-1.124] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id 1vBFg1imLVJl for ; Fri, 16 Sep 2016 07:03:49 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 72F435F242 for ; Fri, 16 Sep 2016 07:03:48 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 7815EE05DC for ; Fri, 16 Sep 2016 07:03:47 +0000 (UTC) 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 E525D3A0248 for ; Fri, 16 Sep 2016 07:03:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1761005 - in /felix/trunk/http: base/src/main/java/org/apache/felix/http/base/internal/ jetty/src/main/java/org/apache/felix/http/jetty/internal/ Date: Fri, 16 Sep 2016 07:03:46 -0000 To: commits@felix.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160916070346.E525D3A0248@svn01-us-west.apache.org> archived-at: Fri, 16 Sep 2016 07:03:55 -0000 Author: cziegeler Date: Fri Sep 16 07:03:46 2016 New Revision: 1761005 URL: http://svn.apache.org/viewvc?rev=1761005&view=rev Log: FELIX-5349 : add ManagedServiceFactory to HTTP service Added: felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedServiceFactory.java (with props) felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyServiceStarter.java (with props) Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java 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/JettyConfig.java felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java?rev=1761005&r1=1761004&r2=1761005&view=diff ============================================================================== --- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java (original) +++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java Fri Sep 16 07:03:46 2016 @@ -32,6 +32,11 @@ public abstract class AbstractActivator return this.context; } + protected final void setBundleContext(BundleContext context) + { + this.context = context; + } + public final void start(BundleContext context) throws Exception { Modified: felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java URL: http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java?rev=1761005&r1=1761004&r2=1761005&view=diff ============================================================================== --- felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java (original) +++ felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java Fri Sep 16 07:03:46 2016 @@ -315,6 +315,12 @@ class ConfigMetaTypeProvider implements -1, bundle.getBundleContext().getProperty(JettyConfig.FELIX_JETTY_SERVLET_SESSION_MAX_AGE))); + adList.add(new AttributeDefinitionImpl(JettyConfig.FELIX_HTTP_SERVICE_NAME, + "HTTP Service Name", + "HTTP Service Name used in service filter to target specific HTTP instance. Default is null.", + null, + bundle.getBundleContext().getProperty(JettyConfig.FELIX_HTTP_SERVICE_NAME))); + return new ObjectClassDefinition() { 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=1761005&r1=1761004&r2=1761005&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 Fri Sep 16 07:03:46 2016 @@ -25,6 +25,7 @@ import org.osgi.framework.Bundle; import org.osgi.framework.Constants; import org.osgi.framework.ServiceFactory; import org.osgi.framework.ServiceRegistration; +import org.osgi.service.cm.ManagedServiceFactory; public final class JettyActivator extends AbstractHttpActivator { @@ -32,6 +33,7 @@ public final class JettyActivator extend private ServiceRegistration metatypeReg; private ServiceRegistration loadBalancerCustomizerFactoryReg; + private ServiceRegistration configServiceFactoryReg; @Override protected void doStart() throws Exception @@ -83,6 +85,11 @@ public final class JettyActivator extend // nothing to do } }, propertiesCustomizer); + + Dictionary factoryProps = new Hashtable(); + factoryProps.put(Constants.SERVICE_PID, JettyService.PID); + this.configServiceFactoryReg = this.getBundleContext().registerService( + ManagedServiceFactory.class.getName(), new JettyManagedServiceFactory(this.getBundleContext()), factoryProps); } @Override @@ -99,6 +106,11 @@ public final class JettyActivator extend loadBalancerCustomizerFactoryReg.unregister(); loadBalancerCustomizerFactoryReg = null; } + if ( configServiceFactoryReg != null ) + { + configServiceFactoryReg.unregister(); + configServiceFactoryReg = null; + } super.doStop(); } 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=1761005&r1=1761004&r2=1761005&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 Fri Sep 16 07:03:46 2016 @@ -162,6 +162,10 @@ public final class JettyConfig /** Felix specific property to configure session max age */ public static final String FELIX_JETTY_SERVLET_SESSION_MAX_AGE = "org.eclipse.jetty.servlet.MaxAge"; + /** Felix specific property to set HTTP instance name. */ + public static final String FELIX_HTTP_SERVICE_NAME = "org.apache.felix.http.name"; + + private static String validateContextPath(String ctxPath) { // undefined, empty, or root context path @@ -404,7 +408,7 @@ public final class JettyConfig boolean useHttps = getBooleanProperty(FELIX_HTTPS_ENABLE, getBooleanProperty(OSCAR_HTTPS_ENABLE, false)); return useHttps && getHttpsPort() > 0; } - + public boolean isProxyLoadBalancerConnection() { return getBooleanProperty(FELIX_PROXY_LOAD_BALANCER_CONNECTION_ENABLE, false); @@ -414,6 +418,11 @@ public final class JettyConfig return getBooleanProperty(FELIX_JETTY_RENEGOTIATION_ALLOWED, false); } + public String getHttpServiceName() + { + return (String) getProperty(FELIX_HTTP_SERVICE_NAME); + } + public void reset() { update(null); @@ -425,6 +434,10 @@ public final class JettyConfig props.put(HTTPS_PORT, Integer.toString(getHttpsPort())); props.put(FELIX_HTTP_ENABLE, Boolean.toString(isUseHttp())); props.put(FELIX_HTTPS_ENABLE, Boolean.toString(isUseHttps())); + if (getHttpServiceName() != null) + { + props.put(FELIX_HTTP_SERVICE_NAME, getHttpServiceName()); + } } /** Added: felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedServiceFactory.java URL: http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedServiceFactory.java?rev=1761005&view=auto ============================================================================== --- felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedServiceFactory.java (added) +++ felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedServiceFactory.java Fri Sep 16 07:03:46 2016 @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.http.jetty.internal; + +import java.util.Dictionary; +import java.util.HashMap; +import java.util.Map; + +import org.osgi.framework.BundleContext; +import org.osgi.service.cm.ConfigurationException; +import org.osgi.service.cm.ManagedServiceFactory; + +public class JettyManagedServiceFactory implements ManagedServiceFactory +{ + private final Map services = new HashMap<>(); + private final BundleContext context; + + JettyManagedServiceFactory(BundleContext context) + { + this.context = context; + } + + @Override + public String getName() + { + return "Apache Felix Http Jetty"; + } + + @Override + public void updated(String pid, Dictionary properties) throws ConfigurationException + { + JettyServiceStarter jetty = services.get(pid); + + try + { + if (jetty == null) + { + jetty = new JettyServiceStarter(context, properties); + services.put(pid, jetty); + jetty.start(); + } + else + { + jetty.updated(properties); + } + } + catch (Exception e) + { + throw new ConfigurationException(null, "Failed to start Http Jetty pid=" + pid, e); + } + } + + @Override + public void deleted(String pid) + { + JettyServiceStarter jetty = services.remove(pid); + + if (jetty != null) + { + try + { + jetty.stop(); + } + catch (Exception e) + { + throw new RuntimeException("Faiiled to stop Http Jetty pid=" + pid, e); + } + } + + } + +} Propchange: felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedServiceFactory.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedServiceFactory.java ------------------------------------------------------------------------------ svn:keywords = author date id revision rev url 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=1761005&r1=1761004&r2=1761005&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 Fri Sep 16 07:03:46 2016 @@ -107,6 +107,7 @@ public final class JettyService extends private ServiceTracker loadBalancerCustomizerTracker; private CustomizerWrapper customizerWrapper; private EventAdmin eventAdmin; + private boolean registerManagedService = true; public JettyService(final BundleContext context, final DispatcherServlet dispatcher, @@ -131,14 +132,27 @@ public final class JettyService extends }); } + public JettyService(final BundleContext context, + final DispatcherServlet dispatcher, + final EventDispatcher eventDispatcher, + final HttpServiceController controller, + final Dictionary props) + { + this(context, dispatcher, eventDispatcher, controller); + this.config.update(props); + this.registerManagedService = false; + } + public void start() throws Exception { // FELIX-4422: start Jetty synchronously... startJetty(); - Dictionary props = new Hashtable(); - props.put(Constants.SERVICE_PID, PID); - this.configServiceReg = this.context.registerService("org.osgi.service.cm.ManagedService", new JettyManagedService(this), props); + if (this.registerManagedService) { + Dictionary props = new Hashtable(); + props.put(Constants.SERVICE_PID, PID); + this.configServiceReg = this.context.registerService("org.osgi.service.cm.ManagedService", new JettyManagedService(this), props); + } this.eventAdmintTracker = new ServiceTracker(this.context, EventAdmin.class.getName(), this); this.eventAdmintTracker.open(); Added: felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyServiceStarter.java URL: http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyServiceStarter.java?rev=1761005&view=auto ============================================================================== --- felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyServiceStarter.java (added) +++ felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyServiceStarter.java Fri Sep 16 07:03:46 2016 @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.http.jetty.internal; + +import java.util.Dictionary; + +import org.apache.felix.http.base.internal.AbstractHttpActivator; +import org.osgi.framework.BundleContext; + +public class JettyServiceStarter extends AbstractHttpActivator +{ + + private final BundleContext context; + private final Dictionary props; + private JettyService jetty; + + JettyServiceStarter(BundleContext context, Dictionary properties) + { + this.context = context; + this.props = properties; + } + + public void start() throws Exception + { + super.setBundleContext(context); + super.doStart(); + jetty = new JettyService(context, getDispatcherServlet(), getEventDispatcher(), + getHttpServiceController(), props); + jetty.start(); + } + + public void stop() throws Exception + { + jetty.stop(); + super.doStop(); + } + + public void updated(Dictionary properties) throws Exception + { + jetty.updated(properties); + } + +} Propchange: felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyServiceStarter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyServiceStarter.java ------------------------------------------------------------------------------ svn:keywords = author date id revision rev url