Repository: aries-jax-rs-whiteboard Updated Branches: refs/heads/new-spec-with-component-dsl [created] 17341dd48
We no longer extend applications with registered services 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/ecd20e34 Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/ecd20e34 Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/ecd20e34 Branch: refs/heads/new-spec-with-component-dsl Commit: ecd20e3458e5bac0fc494bdf79371caba0917fa4 Parents: 62000db Author: Carlos Sierra <[email protected]> Authored: Tue Feb 14 15:47:33 2017 +0100 Committer: Carlos Sierra <[email protected]> Committed: Tue Feb 14 15:48:08 2017 +0100 ---------------------------------------------------------------------- jax-rs.itests/src/main/java/test/JaxrsTest.java | 175 ------------------- .../activator/CXFJaxRsBundleActivator.java | 12 -- .../ServicesServiceTrackerCustomizer.java | 74 -------- 3 files changed, 261 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/ecd20e34/jax-rs.itests/src/main/java/test/JaxrsTest.java ---------------------------------------------------------------------- diff --git a/jax-rs.itests/src/main/java/test/JaxrsTest.java b/jax-rs.itests/src/main/java/test/JaxrsTest.java index d5f3ec5..f7c983d 100644 --- a/jax-rs.itests/src/main/java/test/JaxrsTest.java +++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java @@ -105,180 +105,6 @@ public class JaxrsTest { } @Test - public void testApplicationEndpointExtension() { - Client client = createClient(); - - WebTarget webTarget = client. - target("http://localhost:8080"). - path("/test-application"). - path("extended"); - - ServiceRegistration<?> applicationRegistration = null; - - ServiceRegistration<?> serviceRegistration = null; - - try { - applicationRegistration = registerApplication(); - - serviceRegistration = registerAddon( - "jaxrs.application.select", - "(osgi.jaxrs.application.base=/test-application)"); - - assertEquals( - "Hello extended", - webTarget.request().get().readEntity(String.class)); - } - finally { - if (applicationRegistration != null) { - applicationRegistration.unregister(); - } - if (serviceRegistration != null) { - serviceRegistration.unregister(); - } - } - } - - @Test - public void testApplicationEndpointExtensionReadd() { - Client client = createClient(); - - WebTarget webTarget = client. - target("http://localhost:8080"). - path("/test-application"). - path("extended"); - - ServiceRegistration<?> applicationRegistration = null; - - try { - applicationRegistration = registerApplication(); - - Runnable testCase = () -> { - assertEquals(webTarget.request().get().getStatus(), 404); - - ServiceRegistration<?> serviceRegistration = null; - - try { - serviceRegistration = registerAddon( - "jaxrs.application.select", - "(osgi.jaxrs.application.base=/test-application)"); - - assertEquals( - "Hello extended", - webTarget.request().get().readEntity(String.class)); - } - finally { - if (serviceRegistration != null) { - serviceRegistration.unregister(); - } - } - }; - - testCase.run(); - - testCase.run(); - } - finally { - if (applicationRegistration != null) { - applicationRegistration.unregister(); - } - - } - } - - @Test - public void testApplicationProviderExtension() { - Client client = createClient(); - - WebTarget webTarget = client. - target("http://localhost:8080"). - path("/test-application"); - - ServiceRegistration<?> applicationRegistration = null; - - ServiceRegistration<?> filterRegistration = null; - - try { - applicationRegistration = registerApplication(); - - filterRegistration = registerFilter( - "jaxrs.application.select", - "(osgi.jaxrs.application.base=/test-application)"); - - Response response = webTarget.request().get(); - - assertEquals( - "Hello application", - response.readEntity(String.class)); - - assertEquals( - response.getHeaders().getFirst("Filtered"), - "true"); - } - finally { - if (applicationRegistration != null) { - applicationRegistration.unregister(); - } - if (filterRegistration != null) { - filterRegistration.unregister(); - } - } - } - - @Test - public void testApplicationProviderExtensionReadd() { - Client client = createClient(); - - WebTarget webTarget = client. - target("http://localhost:8080"). - path("/test-application"); - - ServiceRegistration<?> applicationRegistration = null; - - try { - applicationRegistration = registerApplication(); - - assertEquals( - "Hello application", - webTarget.request().get().readEntity(String.class)); - - Runnable testCase = () -> { - Response response = webTarget.request().get(); - - assertNull(response.getHeaders().getFirst("Filtered")); - - ServiceRegistration<?> filterRegistration = null; - - try { - filterRegistration = registerFilter( - "jaxrs.application.select", - "(osgi.jaxrs.application.base=/test-application)"); - - response = webTarget.request().get(); - - assertEquals( - response.getHeaders().getFirst("Filtered"), - "true"); - } - finally { - if (filterRegistration != null) { - filterRegistration.unregister(); - } - } - }; - - testCase.run(); - - testCase.run(); - - } - finally { - if (applicationRegistration != null) { - applicationRegistration.unregister(); - } - } - } - - @Test public void testStandaloneEndPoint() { Client client = createClient(); @@ -306,7 +132,6 @@ public class JaxrsTest { } } - @Test public void testStandaloneEndPointReadd() { Client client = createClient(); http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/ecd20e34/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 97555bd..a871418 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 @@ -37,8 +37,6 @@ import org.osgi.framework.ServiceRegistration; import org.osgi.framework.wiring.BundleWiring; import org.osgi.util.tracker.ServiceTracker; -import org.apache.aries.jax.rs.whiteboard.internal.ServicesServiceTrackerCustomizer; - import java.util.Dictionary; import java.util.Hashtable; @@ -49,7 +47,6 @@ import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHIT public class CXFJaxRsBundleActivator implements BundleActivator { - private ServiceTracker<?, ?> _singletonsTracker; private BundleContext _bundleContext; private ServiceTracker<Application, ?> _applicationTracker; private ServiceTracker<Object, ?> _singletonsServiceTracker; @@ -79,14 +76,6 @@ public class CXFJaxRsBundleActivator implements BundleActivator { bundleContext, getFiltersFilter(), new FiltersAndInterceptorsServiceTrackerCustomizer(bundleContext)); _filtersAndInterceptorsServiceTracker.open(); - - Filter filter = bundleContext.createFilter( - "(jaxrs.application.select=*)"); - - _singletonsTracker = new ServiceTracker<>( - bundleContext, filter, - new ServicesServiceTrackerCustomizer(bundleContext)); - _singletonsTracker.open(); } /** @@ -144,7 +133,6 @@ public class CXFJaxRsBundleActivator implements BundleActivator { _applicationTracker.close(); _filtersAndInterceptorsServiceTracker.close(); _singletonsServiceTracker.close(); - _singletonsTracker.close(); } } http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/ecd20e34/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ServicesServiceTrackerCustomizer.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ServicesServiceTrackerCustomizer.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ServicesServiceTrackerCustomizer.java deleted file mode 100644 index 758199a..0000000 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ServicesServiceTrackerCustomizer.java +++ /dev/null @@ -1,74 +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.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Filter; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.wiring.BundleWiring; -import org.osgi.util.tracker.ServiceTracker; -import org.osgi.util.tracker.ServiceTrackerCustomizer; - -public class ServicesServiceTrackerCustomizer implements ServiceTrackerCustomizer<Object, ServiceTracker<?, ?>> { - - private final BundleContext _bundleContext; - - public ServicesServiceTrackerCustomizer(BundleContext bundleContext) { - _bundleContext = bundleContext; - } - - @Override - public ServiceTracker<?, ?> addingService(ServiceReference<Object> reference) { - String applicationSelector = reference.getProperty("jaxrs.application.select").toString(); - Bundle bundle = reference.getBundle(); - BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); - ClassLoader classLoader = bundleWiring.getClassLoader(); - Object service = _bundleContext.getService(reference); - try { - Filter filter = _bundleContext.createFilter( - "(&(objectClass=" + CXFJaxRsServiceRegistrator.class.getName() + - ")" + applicationSelector + ")"); - ServiceTracker<?, ?> serviceTracker = new ServiceTracker<>( - _bundleContext, - filter, - new AddonsServiceTrackerCustomizer( - _bundleContext, classLoader, service)); - serviceTracker.open(); - return serviceTracker; - } - catch (InvalidSyntaxException ise) { - _bundleContext.ungetService(reference); - throw new RuntimeException(ise); - } - } - - @Override - public void modifiedService(ServiceReference<Object> reference, ServiceTracker<?, ?> serviceTracker) { - removedService(reference, serviceTracker); - addingService(reference); - } - - @Override - public void removedService(ServiceReference<Object> reference, ServiceTracker<?, ?> serviceTracker) { - serviceTracker.close(); - _bundleContext.ungetService(reference); - } - -}
