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 14BBA200C23 for ; Wed, 22 Feb 2017 17:50:56 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 1373A160B49; Wed, 22 Feb 2017 16:50:56 +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 ADF3B160B62 for ; Wed, 22 Feb 2017 17:50:54 +0100 (CET) Received: (qmail 70385 invoked by uid 500); 22 Feb 2017 16:50:53 -0000 Mailing-List: contact commits-help@aries.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aries.apache.org Delivered-To: mailing list commits@aries.apache.org Received: (qmail 70300 invoked by uid 99); 22 Feb 2017 16:50:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Feb 2017 16:50:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B34BCDFF0F; Wed, 22 Feb 2017 16:50:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: csierra@apache.org To: commits@aries.apache.org Date: Wed, 22 Feb 2017 16:50:54 -0000 Message-Id: <775f308c169a4ba7848111223ca70e6a@git.apache.org> In-Reply-To: <58d37e06e9594b46b1139db5dde52810@git.apache.org> References: <58d37e06e9594b46b1139db5dde52810@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/8] aries-jax-rs-whiteboard git commit: Moved to component dsl archived-at: Wed, 22 Feb 2017 16:50:56 -0000 Moved to component dsl Project: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/repo Commit: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/commit/db14ae8e Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/db14ae8e Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/db14ae8e Branch: refs/heads/new-spec-with-component-dsl Commit: db14ae8e76956e15df8507a9c6d2255b11afa767 Parents: ecd20e3 Author: Carlos Sierra Authored: Wed Feb 15 11:30:45 2017 +0100 Committer: Carlos Sierra Committed: Wed Feb 15 11:30:45 2017 +0100 ---------------------------------------------------------------------- jax-rs.whiteboard/bnd.bnd | 1 + jax-rs.whiteboard/pom.xml | 5 + .../activator/CXFJaxRsBundleActivator.java | 167 +++++++++++++++---- .../AddonsServiceTrackerCustomizer.java | 84 ---------- .../ApplicationServiceTrackerCustomizer.java | 66 -------- ...AndInterceptorsServiceTrackerCustomizer.java | 121 -------------- .../SingletonServiceTrackerCustomizer.java | 78 --------- .../internal/TrackedJaxRsRegistrator.java | 45 ----- 8 files changed, 138 insertions(+), 429 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/db14ae8e/jax-rs.whiteboard/bnd.bnd ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/bnd.bnd b/jax-rs.whiteboard/bnd.bnd index 1f7dc5a..f37aab4 100644 --- a/jax-rs.whiteboard/bnd.bnd +++ b/jax-rs.whiteboard/bnd.bnd @@ -51,6 +51,7 @@ Import-Package:\ org.apache.cxf.jaxrs.ext.* -includeresource:\ + lib/component-dsl.jar=component-dsl-*.jar;lib:=true,\ lib/cxf-core.jar=cxf-core-*.jar;lib:=true,\ lib/cxf-rt-databinding-jaxb.jar=cxf-rt-databinding-jaxb-*.jar;lib:=true,\ lib/cxf-rt-frontend-jaxrs.jar=cxf-rt-frontend-jaxrs-*.jar;lib:=true,\ http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/db14ae8e/jax-rs.whiteboard/pom.xml ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/pom.xml b/jax-rs.whiteboard/pom.xml index 0456b69..23a0ce7 100644 --- a/jax-rs.whiteboard/pom.xml +++ b/jax-rs.whiteboard/pom.xml @@ -97,5 +97,10 @@ slf4j-api 1.7.2 + + org.apache.aries.component-dsl + component-dsl + 0.0.1-SNAPSHOT + http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/db14ae8e/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java index a871418..45fbf04 100644 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java +++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java @@ -21,9 +21,9 @@ import javax.servlet.Servlet; import javax.ws.rs.core.Application; import javax.ws.rs.ext.RuntimeDelegate; -import org.apache.aries.jax.rs.whiteboard.internal.ApplicationServiceTrackerCustomizer; -import org.apache.aries.jax.rs.whiteboard.internal.FiltersAndInterceptorsServiceTrackerCustomizer; -import org.apache.aries.jax.rs.whiteboard.internal.SingletonServiceTrackerCustomizer; +import org.apache.aries.jax.rs.whiteboard.internal.CXFJaxRsServiceRegistrator; +import org.apache.aries.osgi.functional.OSGi; +import org.apache.aries.osgi.functional.OSGiResult; import org.apache.cxf.Bus; import org.apache.cxf.BusFactory; import org.apache.cxf.bus.CXFBusFactory; @@ -31,15 +31,21 @@ import org.apache.cxf.transport.servlet.CXFNonSpringServlet; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; -import org.osgi.framework.Filter; -import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; import org.osgi.framework.wiring.BundleWiring; -import org.osgi.util.tracker.ServiceTracker; +import java.util.Collections; import java.util.Dictionary; import java.util.Hashtable; - +import java.util.Map; +import java.util.Set; + +import static org.apache.aries.osgi.functional.OSGi.bundleContext; +import static org.apache.aries.osgi.functional.OSGi.just; +import static org.apache.aries.osgi.functional.OSGi.onClose; +import static org.apache.aries.osgi.functional.OSGi.register; +import static org.apache.aries.osgi.functional.OSGi.serviceReferences; import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME; import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT; import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_DEFAULT_CONTEXT_NAME; @@ -48,9 +54,26 @@ import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHIT public class CXFJaxRsBundleActivator implements BundleActivator { private BundleContext _bundleContext; - private ServiceTracker _applicationTracker; - private ServiceTracker _singletonsServiceTracker; - private ServiceTracker _filtersAndInterceptorsServiceTracker; + private OSGiResult _applicationsResult; + private OSGiResult _singletonsResult; + private OSGiResult _filtersResult; + + private static OSGi service(ServiceReference serviceReference) { + return + bundleContext().flatMap(bundleContext -> + onClose(() -> bundleContext.ungetService(serviceReference)).then( + just(bundleContext.getService(serviceReference)) + )); + } + + private static OSGi cxfRegistrator( + Bus bus, Application application, Map props) { + + return + just(new CXFJaxRsServiceRegistrator(bus, application, props)).flatMap(registrator -> + onClose(registrator::close).then( + register(CXFJaxRsServiceRegistrator.class, registrator, props))); + } @Override public void start(BundleContext bundleContext) throws Exception { @@ -62,20 +85,58 @@ public class CXFJaxRsBundleActivator implements BundleActivator { CXFBusFactory.class.getName()).createBus(); registerCXFServletService(bus); - _applicationTracker = new ServiceTracker<>( - bundleContext, getApplicationFilter(), - new ApplicationServiceTrackerCustomizer(bundleContext, bus)); - _applicationTracker.open(); - - _singletonsServiceTracker = new ServiceTracker<>( - bundleContext, getSingletonsFilter(), - new SingletonServiceTrackerCustomizer(bundleContext, bus)); - _singletonsServiceTracker.open(); - - _filtersAndInterceptorsServiceTracker = new ServiceTracker<>( - bundleContext, getFiltersFilter(), - new FiltersAndInterceptorsServiceTrackerCustomizer(bundleContext)); - _filtersAndInterceptorsServiceTracker.open(); + OSGi applications = + serviceReferences(Application.class, getApplicationFilter()). + flatMap(ref -> + just( + CXFJaxRsServiceRegistrator.getProperties( + ref, "osgi.jaxrs.application.base")). + flatMap(properties -> + service(ref).flatMap(application -> + cxfRegistrator(bus, application, properties) + ))); + + _applicationsResult = applications.run(bundleContext); + + OSGi singletons = + serviceReferences(getSingletonsFilter()). + flatMap(serviceReference -> + just( + CXFJaxRsServiceRegistrator.getProperties( + serviceReference, "osgi.jaxrs.resource.base")). + flatMap(properties -> + service(serviceReference).flatMap(service -> + cxfRegistrator(bus, + new Application() { + @Override + public Set getSingletons() { + return Collections.singleton(service); + } + }, + properties) + ))); + + _singletonsResult = singletons.run(bundleContext); + + OSGi filters = + serviceReferences(getFiltersFilter()).flatMap(ref -> + just( + ref.getProperty("osgi.jaxrs.filter.base").toString()). + flatMap(filterBase -> + serviceReferences( + CXFJaxRsServiceRegistrator.class, "(CXF_ENDPOINT_ADDRESS=*)"). + filter(regref -> + regref. + getProperty("CXF_ENDPOINT_ADDRESS"). + toString(). + startsWith(filterBase)). + flatMap(regref -> + service(regref).flatMap(registrator -> + service(ref).flatMap(service -> + safeRegisterEndpoint(ref, registrator, service) + ))))); + + _filtersResult = filters.run(bundleContext); } /** @@ -96,6 +157,44 @@ public class CXFJaxRsBundleActivator implements BundleActivator { } } + private OSGi safeRegisterEndpoint( + ServiceReference ref, CXFJaxRsServiceRegistrator registrator, + Object service) { + + return + onClose(() -> unregisterEndpoint(registrator, service)).then( + registerEndpoint(ref, registrator, service)); + } + + private OSGi registerEndpoint( + ServiceReference ref, + CXFJaxRsServiceRegistrator registrator, Object service) { + + Thread thread = Thread.currentThread(); + + ClassLoader contextClassLoader = thread.getContextClassLoader(); + + ClassLoader classLoader = ref.getBundle().adapt(BundleWiring.class). + getClassLoader(); + + try { + thread.setContextClassLoader(classLoader); + + registrator.add(service); + } + finally { + thread.setContextClassLoader(contextClassLoader); + } + + return just(service); + } + + private void unregisterEndpoint( + CXFJaxRsServiceRegistrator registrator, Object service) { + + registrator.remove(service); + } + private ServiceRegistration registerCXFServletService(Bus bus) { Dictionary properties = new Hashtable<>(); properties.put(HTTP_WHITEBOARD_CONTEXT_SELECT, @@ -114,25 +213,23 @@ public class CXFJaxRsBundleActivator implements BundleActivator { return cxfNonSpringServlet; } - private Filter getFiltersFilter() throws InvalidSyntaxException { - return _bundleContext.createFilter("(osgi.jaxrs.filter.base=*)"); + private String getFiltersFilter() { + return "(osgi.jaxrs.filter.base=*)"; } - private Filter getApplicationFilter() throws InvalidSyntaxException { - return _bundleContext.createFilter( - "(&(objectClass=" + Application.class.getName() + ")" + - "(osgi.jaxrs.application.base=*))"); + private String getApplicationFilter() { + return "(osgi.jaxrs.application.base=*)"; } - private Filter getSingletonsFilter() throws InvalidSyntaxException { - return _bundleContext.createFilter("(osgi.jaxrs.resource.base=*)"); + private String getSingletonsFilter() { + return "(osgi.jaxrs.resource.base=*)"; } @Override public void stop(BundleContext context) throws Exception { - _applicationTracker.close(); - _filtersAndInterceptorsServiceTracker.close(); - _singletonsServiceTracker.close(); + _applicationsResult.close(); + _filtersResult.close(); + _singletonsResult.close(); } } http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/db14ae8e/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AddonsServiceTrackerCustomizer.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AddonsServiceTrackerCustomizer.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AddonsServiceTrackerCustomizer.java deleted file mode 100644 index 9db1aea..0000000 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AddonsServiceTrackerCustomizer.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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.aries.jax.rs.whiteboard.internal; - -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTrackerCustomizer; - -public class AddonsServiceTrackerCustomizer - implements - ServiceTrackerCustomizer { - - private final BundleContext _bundleContext; - private final ClassLoader _classLoader; - private final Object _service; - - public AddonsServiceTrackerCustomizer( - BundleContext bundleContext, ClassLoader classLoader, - Object service) { - - _bundleContext = bundleContext; - _classLoader = classLoader; - _service = service; - } - - @Override - public CXFJaxRsServiceRegistrator addingService(ServiceReference reference) { - CXFJaxRsServiceRegistrator registrator = _bundleContext.getService(reference); - try { - runInClassLoader(_classLoader, () -> registrator.add(_service)); - return registrator; - } - catch (Exception e) { - _bundleContext.ungetService(reference); - throw e; - } - } - - @Override - public void modifiedService( - ServiceReference reference, - CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator) { - - removedService(reference, cxfJaxRsServiceRegistrator); - addingService(reference); - } - - @Override - public void removedService( - ServiceReference reference, - CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator) { - - cxfJaxRsServiceRegistrator.remove(_service); - _bundleContext.ungetService(reference); - } - - private void runInClassLoader(ClassLoader cl, Runnable runable) { - Thread thread = Thread.currentThread(); - ClassLoader contextClassLoader = thread.getContextClassLoader(); - try { - thread.setContextClassLoader(_classLoader); - runable.run(); - } - finally { - thread.setContextClassLoader(contextClassLoader); - } - } - -} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/db14ae8e/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ApplicationServiceTrackerCustomizer.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ApplicationServiceTrackerCustomizer.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ApplicationServiceTrackerCustomizer.java deleted file mode 100644 index ccf2165..0000000 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ApplicationServiceTrackerCustomizer.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.aries.jax.rs.whiteboard.internal; - -import java.util.Map; - -import javax.ws.rs.core.Application; - -import org.apache.cxf.Bus; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTrackerCustomizer; - -public class ApplicationServiceTrackerCustomizer - implements ServiceTrackerCustomizer { - - private BundleContext _bundleContext; - private Bus _bus; - - public ApplicationServiceTrackerCustomizer(BundleContext bundleContext, Bus bus) { - _bundleContext = bundleContext; - _bus = bus; - } - - @Override - public TrackedJaxRsRegistrator addingService(ServiceReference serviceReference) { - Application application = _bundleContext.getService(serviceReference); - try { - Map props = CXFJaxRsServiceRegistrator - .getProperties(serviceReference, "osgi.jaxrs.application.base"); - CXFJaxRsServiceRegistrator registrator = new CXFJaxRsServiceRegistrator(_bus, application, props); - return new TrackedJaxRsRegistrator(registrator, _bundleContext, props); - } - catch (Throwable e) { - _bundleContext.ungetService(serviceReference); - throw e; - } - } - - @Override - public void modifiedService(ServiceReference serviceReference, TrackedJaxRsRegistrator tracked) { - removedService(serviceReference, tracked); - addingService(serviceReference); - } - - @Override - public void removedService(ServiceReference reference, TrackedJaxRsRegistrator tracked) { - _bundleContext.ungetService(reference); - tracked.close(); - } -} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/db14ae8e/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/FiltersAndInterceptorsServiceTrackerCustomizer.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/FiltersAndInterceptorsServiceTrackerCustomizer.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/FiltersAndInterceptorsServiceTrackerCustomizer.java deleted file mode 100644 index 9e516b8..0000000 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/FiltersAndInterceptorsServiceTrackerCustomizer.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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.aries.jax.rs.whiteboard.internal; - -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTracker; -import org.osgi.util.tracker.ServiceTrackerCustomizer; - -public class FiltersAndInterceptorsServiceTrackerCustomizer - implements ServiceTrackerCustomizer> { - - private BundleContext _bundleContext; - - public FiltersAndInterceptorsServiceTrackerCustomizer( - BundleContext bundleContext) { - - _bundleContext = bundleContext; - } - - @Override - public ServiceTracker addingService(final ServiceReference reference) { - final String filterBase = - reference.getProperty("osgi.jaxrs.filter.base").toString(); - - final Object service = _bundleContext.getService(reference); - - ServiceTracker serviceTracker = new ServiceTracker<>( - _bundleContext, CXFJaxRsServiceRegistrator.class, - new ServiceTrackerCustomizer - () { - - @Override - public CXFJaxRsServiceRegistrator addingService( - ServiceReference cxfReference) { - - Object resourceBaseObject = - cxfReference.getProperty("CXF_ENDPOINT_ADDRESS"); - - if (resourceBaseObject == null) { - return null; - } - - String resourceBase = resourceBaseObject.toString(); - - if (resourceBase.startsWith(filterBase)) { - CXFJaxRsServiceRegistrator serviceRegistrator = - _bundleContext.getService(cxfReference); - try { - serviceRegistrator.add(service); - - return serviceRegistrator; - } - finally { - _bundleContext.ungetService(reference); - } - } - - return null; - } - - @Override - public void modifiedService( - ServiceReference reference, - CXFJaxRsServiceRegistrator serviceRegistrator) { - - removedService(reference, serviceRegistrator); - addingService(reference); - } - - @Override - public void removedService( - ServiceReference reference, - CXFJaxRsServiceRegistrator serviceRegistrator) { - - try { - serviceRegistrator.remove(service); - } - finally { - _bundleContext.ungetService(reference); - } - } - }); - - serviceTracker.open(); - - return serviceTracker; - } - - @Override - public void modifiedService( - ServiceReference reference, ServiceTracker serviceTracker) { - - removedService(reference, serviceTracker); - addingService(reference); - } - - @Override - public void removedService( - ServiceReference reference, ServiceTracker serviceTracker) { - - _bundleContext.ungetService(reference); - - serviceTracker.close(); - } -} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/db14ae8e/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/SingletonServiceTrackerCustomizer.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/SingletonServiceTrackerCustomizer.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/SingletonServiceTrackerCustomizer.java deleted file mode 100644 index 2d1264d..0000000 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/SingletonServiceTrackerCustomizer.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.aries.jax.rs.whiteboard.internal; - -import java.util.Collections; -import java.util.Map; -import java.util.Set; - -import javax.ws.rs.core.Application; - -import org.apache.cxf.Bus; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTrackerCustomizer; - -public class SingletonServiceTrackerCustomizer - implements ServiceTrackerCustomizer { - - private BundleContext _bundleContext; - private Bus _bus; - - public SingletonServiceTrackerCustomizer(BundleContext bundleContext, Bus bus) { - _bundleContext = bundleContext; - _bus = bus; - } - - @Override - public TrackedJaxRsRegistrator addingService( - ServiceReference serviceReference) { - - final Object service = _bundleContext.getService(serviceReference); - Application application = new Application() { - @Override - public Set getSingletons() { - return Collections.singleton(service); - } - }; - try { - Map properties = CXFJaxRsServiceRegistrator - .getProperties(serviceReference, "osgi.jaxrs.resource.base"); - CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator = - new CXFJaxRsServiceRegistrator(_bus, application, properties); - return new TrackedJaxRsRegistrator(cxfJaxRsServiceRegistrator, _bundleContext, properties); - } - catch (Exception e) { - _bundleContext.ungetService(serviceReference); - throw e; - } - } - - @Override - public void modifiedService(ServiceReference serviceReference, TrackedJaxRsRegistrator tracked) { - removedService(serviceReference, tracked); - addingService(serviceReference); - } - - @Override - public void removedService(ServiceReference reference, TrackedJaxRsRegistrator tracked) { - _bundleContext.ungetService(reference); - tracked.close(); - } - -} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/db14ae8e/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/TrackedJaxRsRegistrator.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/TrackedJaxRsRegistrator.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/TrackedJaxRsRegistrator.java deleted file mode 100644 index 90ed68e..0000000 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/TrackedJaxRsRegistrator.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.aries.jax.rs.whiteboard.internal; - -import java.util.Hashtable; -import java.util.Map; - -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -public class TrackedJaxRsRegistrator { - private final CXFJaxRsServiceRegistrator _registrator; - private final ServiceRegistration _sreg; - - public TrackedJaxRsRegistrator(CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator, - BundleContext bundleContext, - Map properties) { - _registrator = cxfJaxRsServiceRegistrator; - _sreg = bundleContext. - registerService(CXFJaxRsServiceRegistrator.class, - cxfJaxRsServiceRegistrator, - new Hashtable<>(properties)); - } - - - - public void close() { - _registrator.close(); - _sreg.unregister(); - } -} \ No newline at end of file