You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2017/02/22 16:50:53 UTC
[1/8] aries-jax-rs-whiteboard git commit: We no longer extend
applications with registered services
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 <cs...@apache.org>
Authored: Tue Feb 14 15:47:33 2017 +0100
Committer: Carlos Sierra <cs...@apache.org>
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);
- }
-
-}
[6/8] aries-jax-rs-whiteboard git commit: Deploy raw services in the
same application
Posted by cs...@apache.org.
Deploy raw services in the same application
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/d425d5d9
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/d425d5d9
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/d425d5d9
Branch: refs/heads/new-spec-with-component-dsl
Commit: d425d5d97cd0fd57f864515202a8d0e865044380
Parents: 729e58c
Author: Carlos Sierra <cs...@apache.org>
Authored: Wed Feb 22 17:41:57 2017 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Wed Feb 22 17:49:47 2017 +0100
----------------------------------------------------------------------
.../activator/CXFJaxRsBundleActivator.java | 57 ++++++-----
.../internal/CXFJaxRsServiceRegistrator.java | 100 +++++++++++++++++--
2 files changed, 125 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/d425d5d9/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 1275c0d..e40b991 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
@@ -22,6 +22,7 @@ import javax.ws.rs.core.Application;
import javax.ws.rs.ext.RuntimeDelegate;
import org.apache.aries.jax.rs.whiteboard.internal.CXFJaxRsServiceRegistrator;
+import org.apache.aries.jax.rs.whiteboard.internal.CXFJaxRsServiceRegistrator.ServiceInformation;
import org.apache.aries.osgi.functional.OSGi;
import org.apache.aries.osgi.functional.OSGiResult;
import org.apache.cxf.Bus;
@@ -37,6 +38,7 @@ import org.osgi.framework.wiring.BundleWiring;
import java.util.Collections;
import java.util.Dictionary;
+import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
@@ -67,13 +69,17 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
));
}
- private static OSGi<?> cxfRegistrator(
+ private static OSGi<CXFJaxRsServiceRegistrator> cxfRegistrator(
Bus bus, Application application, Map<String, Object> props) {
+ CXFJaxRsServiceRegistrator registrator =
+ new CXFJaxRsServiceRegistrator(bus, application, props);
+
return
- just(new CXFJaxRsServiceRegistrator(bus, application, props)).flatMap(registrator ->
onClose(registrator::close).then(
- register(CXFJaxRsServiceRegistrator.class, registrator, props)));
+ register(CXFJaxRsServiceRegistrator.class, registrator, props).then(
+ just(registrator)
+ ));
}
@Override
@@ -99,6 +105,12 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
_applicationsResult = applications.run(bundleContext);
+ Application defaultApplication = new Application() {};
+
+ CXFJaxRsServiceRegistrator defaultServiceRegistrator =
+ new CXFJaxRsServiceRegistrator(
+ bus, defaultApplication, new HashMap<>());
+
OSGi<?> singletons =
serviceReferences(getSingletonsFilter()).
flatMap(serviceReference ->
@@ -108,16 +120,10 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
serviceReference, "osgi.jaxrs.resource.base")).
flatMap(properties ->
service(serviceReference).flatMap(service ->
- cxfRegistrator(bus,
- new Application() {
- @Override
- public Set<Object> getSingletons() {
- return Collections.singleton(service);
- }
- },
- properties)
- )))
- );
+ safeRegisterEndpoint(
+ serviceReference, defaultServiceRegistrator)
+ )))
+ );
_singletonsResult = singletons.run(bundleContext);
@@ -166,11 +172,9 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
if (propertyValue == null) {
return new String[0];
}
-
if (propertyValue instanceof String[]) {
return (String[]) propertyValue;
}
-
return new String[]{propertyValue.toString()};
}
@@ -194,12 +198,14 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
}
private OSGi<?> safeRegisterEndpoint(
- ServiceReference<?> ref, CXFJaxRsServiceRegistrator registrator,
- Object service) {
+ ServiceReference<?> ref, CXFJaxRsServiceRegistrator registrator) {
return
+ bundleContext().flatMap(bundleContext ->
+ service(ref).flatMap(service ->
onClose(() -> unregisterEndpoint(registrator, service)).then(
- registerEndpoint(ref, registrator, service));
+ registerEndpoint(ref, registrator, service)
+ )));
}
private OSGi<?> registerEndpoint(
@@ -207,21 +213,26 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
CXFJaxRsServiceRegistrator registrator, Object service) {
Thread thread = Thread.currentThread();
-
ClassLoader contextClassLoader = thread.getContextClassLoader();
-
ClassLoader classLoader = ref.getBundle().adapt(BundleWiring.class).
getClassLoader();
+ Object resourceBaseObject = ref.getProperty("osgi.jaxrs.resource.base");
+
+ String resourceBase;
+ if (resourceBaseObject == null) {
+ resourceBase = "";
+ }
+ else {
+ resourceBase = resourceBaseObject.toString();
+ }
try {
thread.setContextClassLoader(classLoader);
-
- registrator.add(service);
+ registrator.add(new ServiceInformation(resourceBase, "", service));
}
finally {
thread.setContextClassLoader(contextClassLoader);
}
-
return just(service);
}
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/d425d5d9/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
index 43f6ddb..683cb0f 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
@@ -20,6 +20,8 @@ package org.apache.aries.jax.rs.whiteboard.internal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import javax.ws.rs.core.Application;
@@ -29,7 +31,10 @@ import javax.ws.rs.ext.RuntimeDelegate;
import org.apache.cxf.Bus;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean;
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.URITemplate;
import org.apache.cxf.jaxrs.provider.json.JSONProvider;
import org.osgi.framework.ServiceReference;
@@ -40,7 +45,7 @@ public class CXFJaxRsServiceRegistrator {
private final Map<String, Object> _properties;
private final Collection<Object> _providers = new ArrayList<>();
private Server _server;
- private final Collection<Object> _services = new ArrayList<>();
+ private final Collection<ServiceInformation> _services = new ArrayList<>();
public CXFJaxRsServiceRegistrator(
Bus bus, Application application, Map<String, Object> properties) {
@@ -79,14 +84,17 @@ public class CXFJaxRsServiceRegistrator {
_closed = true;
}
- public void add(Object object) {
+ public void add(ServiceInformation serviceInformation) {
if (_closed) {
return;
}
+
+ Object object = serviceInformation.getService();
+
if (object.getClass().isAnnotationPresent(Provider.class)) {
_providers.add(object);
} else {
- _services.add(object);
+ _services.add(serviceInformation);
}
rewire();
}
@@ -95,11 +103,21 @@ public class CXFJaxRsServiceRegistrator {
if (_closed) {
return;
}
+
if (object.getClass().isAnnotationPresent(Provider.class)) {
_providers.remove(object);
- } else {
- _services.remove(object);
}
+ else {
+ Iterator<ServiceInformation> iterator = _services.iterator();
+ while (iterator.hasNext()) {
+ ServiceInformation next = iterator.next();
+
+ if (next.getService() == object) {
+ iterator.remove();
+ }
+ }
+ }
+
rewire();
}
@@ -108,6 +126,13 @@ public class CXFJaxRsServiceRegistrator {
_server.destroy();
}
+ if (_services.isEmpty() &&
+ _application.getSingletons().isEmpty() &&
+ _application.getClasses().isEmpty()) {
+
+ return;
+ }
+
RuntimeDelegate runtimeDelegate = RuntimeDelegate.getInstance();
JAXRSServerFactoryBean jaxRsServerFactoryBean =
@@ -130,12 +155,42 @@ public class CXFJaxRsServiceRegistrator {
jaxRsServerFactoryBean.setProvider(provider);
}
- for (Object service : _services) {
- jaxRsServerFactoryBean.setResourceProvider(
- new SingletonResourceProvider(service, true));
+ JAXRSServiceFactoryBean serviceFactory =
+ jaxRsServerFactoryBean.getServiceFactory();
+
+ for (ServiceInformation serviceInformation : _services) {
+ Object service = serviceInformation.getService();
+
+ SingletonResourceProvider rp = new SingletonResourceProvider(
+ service, true);
+
+ jaxRsServerFactoryBean.setResourceProvider(rp);
+
+ List<ClassResourceInfo> classResourceInfo =
+ serviceFactory.getClassResourceInfo();
+
+ for (ClassResourceInfo resourceInfo : classResourceInfo) {
+ if (resourceInfo.getServiceClass() == service.getClass()) {
+ URITemplate uriTemplate = resourceInfo.getURITemplate();
+ resourceInfo.setURITemplate(
+ new URITemplate(
+ serviceInformation.getPrefixPath() +
+ uriTemplate.getValue()));
+ }
+ }
}
- String address = _properties.get("CXF_ENDPOINT_ADDRESS").toString();
+ Object cxfEndpointAddressObject = _properties.get(
+ "CXF_ENDPOINT_ADDRESS");
+
+ String address;
+
+ if (cxfEndpointAddressObject == null) {
+ address = "";
+ }
+ else {
+ address = cxfEndpointAddressObject.toString();
+ }
if (address != null) {
jaxRsServerFactoryBean.setAddress(address);
@@ -146,4 +201,31 @@ public class CXFJaxRsServiceRegistrator {
_server.start();
}
+ public static class ServiceInformation {
+ private final String prefixPath;
+ private final String scope;
+ private final Object service;
+
+ public ServiceInformation(
+ String prefixPath, String scope, Object service) {
+
+ this.prefixPath = prefixPath;
+ this.scope = scope;
+ this.service = service;
+ }
+
+ public String getPrefixPath() {
+ return prefixPath;
+ }
+
+ public String getScope() {
+ return scope;
+ }
+
+ public Object getService() {
+ return service;
+ }
+
+ }
+
}
[3/8] aries-jax-rs-whiteboard git commit: Implemented wait for
extensions
Posted by cs...@apache.org.
Implemented wait for extensions
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/6243975d
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/6243975d
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/6243975d
Branch: refs/heads/new-spec-with-component-dsl
Commit: 6243975d66e2314435328a7308baf41476299fcd
Parents: db14ae8
Author: Carlos Sierra <cs...@apache.org>
Authored: Wed Feb 15 15:12:31 2017 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Wed Feb 15 15:12:31 2017 +0100
----------------------------------------------------------------------
jax-rs.itests/src/main/java/test/JaxrsTest.java | 92 ++++++++++++++++++-
.../activator/CXFJaxRsBundleActivator.java | 94 ++++++++++++++------
2 files changed, 153 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6243975d/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 f7c983d..00282ee 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -260,6 +260,67 @@ public class JaxrsTest {
}
}
+ @Test
+ public void testStandaloneEndpointWithExtensionsDependencies() {
+ Client client = createClient();
+
+ WebTarget webTarget = client.
+ target("http://localhost:8080").
+ path("/test-addon").
+ path("test");
+
+ ServiceRegistration<?> serviceRegistration = null;
+ ServiceRegistration<?> extensionRegistration1;
+ ServiceRegistration<?> extensionRegistration2;
+
+ try {
+ serviceRegistration = registerAddon(
+ "osgi.jaxrs.resource.base", "/test-addon",
+ "osgi.jaxrs.extension.select", new String[]{
+ "(property one=one)",
+ "(property two=two)",
+ });
+
+ assertEquals(404, webTarget.request().get().getStatus());
+
+ extensionRegistration1 = registerExtension(
+ "aExtension", "property one", "one");
+
+ assertEquals(404, webTarget.request().get().getStatus());
+
+ extensionRegistration2 = registerExtension(
+ "anotherExtension", "property two", "two");
+
+ Response response = webTarget.request().get();
+
+ assertEquals(
+ "This should say hello", "Hello test",
+ response.readEntity(String.class));
+
+ extensionRegistration1.unregister();
+
+ assertEquals(404, webTarget.request().get().getStatus());
+
+ extensionRegistration1 = registerExtension(
+ "aExtension", "property one", "one");
+
+ assertEquals(
+ "This should say hello", "Hello test",
+ response.readEntity(String.class));
+
+ extensionRegistration2.unregister();
+
+ assertEquals(404, webTarget.request().get().getStatus());
+
+ extensionRegistration1.unregister();
+ }
+ finally {
+ if (serviceRegistration != null) {
+ serviceRegistration.unregister();
+ }
+ }
+ }
+
private Client createClient() {
Thread thread = Thread.currentThread();
@@ -276,12 +337,15 @@ public class JaxrsTest {
}
}
- private ServiceRegistration<?> registerAddon(String key, String value) {
+ private ServiceRegistration<?> registerAddon(Object ... keyValues) {
+
TestAddon testAddon = new TestAddon();
Dictionary<String, Object> properties = new Hashtable<>();
- properties.put(key, value);
+ for (int i = 0; i < keyValues.length; i = i + 2) {
+ properties.put(keyValues[i].toString(), keyValues[i + 1]);
+ }
return bundleContext.registerService(
Object.class, testAddon, properties);
@@ -300,12 +364,32 @@ public class JaxrsTest {
Application.class, testApplication, properties);
}
- private ServiceRegistration<?> registerFilter(String key, String value) {
+ private ServiceRegistration<?> registerFilter(Object ... keyValues) {
+
+ TestFilter testFilter = new TestFilter();
+
+ Dictionary<String, Object> properties = new Hashtable<>();
+
+ for (int i = 0; i < keyValues.length; i = i + 2) {
+ properties.put(keyValues[i].toString(), keyValues[i + 1]);
+ }
+
+ return bundleContext.registerService(
+ Object.class, testFilter, properties);
+ }
+
+ private ServiceRegistration<?> registerExtension(
+ String name, Object ... keyValues) {
+
TestFilter testFilter = new TestFilter();
Dictionary<String, Object> properties = new Hashtable<>();
- properties.put(key, value);
+ properties.put("osgi.jaxrs.extension.name", name);
+
+ for (int i = 0; i < keyValues.length; i = i + 2) {
+ properties.put(keyValues[i].toString(), keyValues[i + 1]);
+ }
return bundleContext.registerService(
Object.class, testFilter, properties);
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6243975d/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 45fbf04..1275c0d 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
@@ -43,6 +43,7 @@ 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.nothing;
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;
@@ -101,40 +102,44 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
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<Object> getSingletons() {
- return Collections.singleton(service);
- }
- },
- properties)
- )));
+ waitForExtensionDependencies(serviceReference,
+ just(
+ CXFJaxRsServiceRegistrator.getProperties(
+ serviceReference, "osgi.jaxrs.resource.base")).
+ flatMap(properties ->
+ service(serviceReference).flatMap(service ->
+ cxfRegistrator(bus,
+ new Application() {
+ @Override
+ public Set<Object> 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)
- )))));
+ waitForExtensionDependencies(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);
}
@@ -157,6 +162,37 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
}
}
+ private String[] canonicalize(Object propertyValue) {
+ if (propertyValue == null) {
+ return new String[0];
+ }
+
+ if (propertyValue instanceof String[]) {
+ return (String[]) propertyValue;
+ }
+
+ return new String[]{propertyValue.toString()};
+ }
+
+ private String buildExtensionFilter(String filter) {
+ return "(&(osgi.jaxrs.extension.name=*)" + filter + ")";
+ }
+
+ private OSGi<?> waitForExtensionDependencies(
+ ServiceReference<?> serviceReference, OSGi<?> program) {
+
+ String[] extensionDependencies = canonicalize(
+ serviceReference.getProperty("osgi.jaxrs.extension.select"));
+
+ for (String extensionDependency : extensionDependencies) {
+ program =
+ serviceReferences(buildExtensionFilter(extensionDependency)).
+ then(program);
+ }
+
+ return program;
+ }
+
private OSGi<?> safeRegisterEndpoint(
ServiceReference<?> ref, CXFJaxRsServiceRegistrator registrator,
Object service) {
[4/8] aries-jax-rs-whiteboard git commit: Use assert properly
Posted by cs...@apache.org.
Use assert properly
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/729e58ce
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/729e58ce
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/729e58ce
Branch: refs/heads/new-spec-with-component-dsl
Commit: 729e58cee6e6b56ea72287e1426d96c6dee8d5e6
Parents: 6243975
Author: Carlos Sierra <cs...@apache.org>
Authored: Wed Feb 15 15:12:55 2017 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Wed Feb 15 15:12:55 2017 +0100
----------------------------------------------------------------------
jax-rs.itests/src/main/java/test/JaxrsTest.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/729e58ce/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 00282ee..5292cfd 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -78,7 +78,7 @@ public class JaxrsTest {
path("/test-application");
Runnable testCase = () -> {
- assertEquals(webTarget.request().get().getStatus(), 404);
+ assertEquals(404, webTarget.request().get().getStatus());
ServiceRegistration<?> serviceRegistration = null;
@@ -142,7 +142,7 @@ public class JaxrsTest {
path("test");
Runnable testCase = () -> {
- assertEquals(webTarget.request().get().getStatus(), 404);
+ assertEquals(404, webTarget.request().get().getStatus());
ServiceRegistration<?> serviceRegistration = null;
@@ -192,7 +192,7 @@ public class JaxrsTest {
"This should say hello", "Hello test",
response.readEntity(String.class));
- assertEquals(response.getHeaders().getFirst("Filtered"), "true");
+ assertEquals("true", response.getHeaders().getFirst("Filtered"));
}
finally {
if (serviceRegistration != null) {
@@ -239,7 +239,7 @@ public class JaxrsTest {
"Hello test", response.readEntity(String.class));
assertEquals(
- response.getHeaders().getFirst("Filtered"), "true");
+ "true", response.getHeaders().getFirst("Filtered"));
}
finally {
if (filterRegistration != null) {
[8/8] aries-jax-rs-whiteboard git commit: Clean imports
Posted by cs...@apache.org.
Clean imports
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/17341dd4
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/17341dd4
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/17341dd4
Branch: refs/heads/new-spec-with-component-dsl
Commit: 17341dd48f890c04d6fafd33340167ccb8def3e6
Parents: 7e1405d
Author: Carlos Sierra <cs...@apache.org>
Authored: Wed Feb 22 17:47:03 2017 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Wed Feb 22 17:49:47 2017 +0100
----------------------------------------------------------------------
.../jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java | 3 ---
1 file changed, 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/17341dd4/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 7ca04f5..8618122 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
@@ -36,16 +36,13 @@ import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.wiring.BundleWiring;
-import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
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.nothing;
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;
[7/8] aries-jax-rs-whiteboard git commit: Readd support for
application extension
Posted by cs...@apache.org.
Readd support for application extension
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/7e1405d7
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/7e1405d7
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/7e1405d7
Branch: refs/heads/new-spec-with-component-dsl
Commit: 7e1405d7e2805f22f56ca510d82f186d04487418
Parents: 14c49ec
Author: Carlos Sierra <cs...@apache.org>
Authored: Wed Feb 22 17:45:47 2017 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Wed Feb 22 17:49:47 2017 +0100
----------------------------------------------------------------------
jax-rs.itests/src/main/java/test/JaxrsTest.java | 174 +++++++++++++++++++
.../activator/CXFJaxRsBundleActivator.java | 15 ++
2 files changed, 189 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/7e1405d7/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 3fc9c52..f5b434b 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -105,6 +105,180 @@ 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(
+ "osgi.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(
+ "osgi.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(
+ "osgi.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(
+ "osgi.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();
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/7e1405d7/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 4260db0..7ca04f5 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
@@ -49,6 +49,7 @@ import static org.apache.aries.osgi.functional.OSGi.nothing;
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.apache.aries.osgi.functional.OSGi.services;
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;
@@ -60,6 +61,7 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
private OSGiResult<?> _applicationsResult;
private OSGiResult<?> _singletonsResult;
private OSGiResult<?> _extensionsResult;
+ private OSGiResult<?> _applicationSingletonsResult;
private static <T> OSGi<T> service(ServiceReference<T> serviceReference) {
return
@@ -135,6 +137,18 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
);
_extensionsResult = extensions.run(bundleContext);
+
+ OSGi<?> applicationSingletons =
+ serviceReferences("(osgi.jaxrs.application.select=*)").
+ flatMap(ref ->
+ just(ref.getProperty("osgi.jaxrs.application.select").toString()).
+ flatMap(applicationFilter ->
+ services(CXFJaxRsServiceRegistrator.class, applicationFilter).
+ flatMap(registrator ->
+ safeRegisterEndpoint(ref, registrator)
+ )));
+
+ _applicationSingletonsResult = applicationSingletons.run(bundleContext);
}
/**
@@ -261,6 +275,7 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
@Override
public void stop(BundleContext context) throws Exception {
+ _applicationSingletonsResult.close();
_applicationsResult.close();
_extensionsResult.close();
_singletonsResult.close();
[5/8] aries-jax-rs-whiteboard git commit: Deploy extensions in
default application
Posted by cs...@apache.org.
Deploy extensions in default application
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/14c49ecd
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/14c49ecd
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/14c49ecd
Branch: refs/heads/new-spec-with-component-dsl
Commit: 14c49ecd551d4a407a722c7644a5493c04858031
Parents: d425d5d
Author: Carlos Sierra <cs...@apache.org>
Authored: Wed Feb 22 17:44:39 2017 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Wed Feb 22 17:49:47 2017 +0100
----------------------------------------------------------------------
jax-rs.itests/src/main/java/test/JaxrsTest.java | 4 +--
.../activator/CXFJaxRsBundleActivator.java | 31 ++++++--------------
2 files changed, 11 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/14c49ecd/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 5292cfd..3fc9c52 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -184,7 +184,7 @@ public class JaxrsTest {
"osgi.jaxrs.resource.base", "/test-addon");
filterRegistration = registerFilter(
- "osgi.jaxrs.filter.base", "/test-addon");
+ "osgi.jaxrs.extension.name", "test-filter");
Response response = webTarget.request().get();
@@ -231,7 +231,7 @@ public class JaxrsTest {
assertNull(response.getHeaders().getFirst("Filtered"));
filterRegistration = registerFilter(
- "osgi.jaxrs.filter.base", "/test-addon");
+ "osgi.jaxrs.extension.name", "test-filter");
response = webTarget.request().get();
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/14c49ecd/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 e40b991..4260db0 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
@@ -59,7 +59,7 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
private BundleContext _bundleContext;
private OSGiResult<?> _applicationsResult;
private OSGiResult<?> _singletonsResult;
- private OSGiResult<?> _filtersResult;
+ private OSGiResult<?> _extensionsResult;
private static <T> OSGi<T> service(ServiceReference<T> serviceReference) {
return
@@ -127,27 +127,14 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
_singletonsResult = singletons.run(bundleContext);
- OSGi<?> filters =
- serviceReferences(getFiltersFilter()).flatMap(ref ->
+ OSGi<?> extensions =
+ serviceReferences(getExtensionFilter()).flatMap(ref ->
waitForExtensionDependencies(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)
- )))))
+ safeRegisterEndpoint(ref, defaultServiceRegistrator)
+ )
);
- _filtersResult = filters.run(bundleContext);
+ _extensionsResult = extensions.run(bundleContext);
}
/**
@@ -260,8 +247,8 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
return cxfNonSpringServlet;
}
- private String getFiltersFilter() {
- return "(osgi.jaxrs.filter.base=*)";
+ private String getExtensionFilter() {
+ return "(osgi.jaxrs.extension.name=*)";
}
private String getApplicationFilter() {
@@ -275,7 +262,7 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
@Override
public void stop(BundleContext context) throws Exception {
_applicationsResult.close();
- _filtersResult.close();
+ _extensionsResult.close();
_singletonsResult.close();
}
[2/8] aries-jax-rs-whiteboard git commit: Moved to component dsl
Posted by cs...@apache.org.
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 <cs...@apache.org>
Authored: Wed Feb 15 11:30:45 2017 +0100
Committer: Carlos Sierra <cs...@apache.org>
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 @@
<artifactId>slf4j-api</artifactId>
<version>1.7.2</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.aries.component-dsl</groupId>
+ <artifactId>component-dsl</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </dependency>
</dependencies>
</project>
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<Application, ?> _applicationTracker;
- private ServiceTracker<Object, ?> _singletonsServiceTracker;
- private ServiceTracker<Object, ?> _filtersAndInterceptorsServiceTracker;
+ private OSGiResult<?> _applicationsResult;
+ private OSGiResult<?> _singletonsResult;
+ private OSGiResult<?> _filtersResult;
+
+ private static <T> OSGi<T> service(ServiceReference<T> serviceReference) {
+ return
+ bundleContext().flatMap(bundleContext ->
+ onClose(() -> bundleContext.ungetService(serviceReference)).then(
+ just(bundleContext.getService(serviceReference))
+ ));
+ }
+
+ private static OSGi<?> cxfRegistrator(
+ Bus bus, Application application, Map<String, Object> 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<Object> 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<Servlet> registerCXFServletService(Bus bus) {
Dictionary<String, Object> 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<CXFJaxRsServiceRegistrator, CXFJaxRsServiceRegistrator> {
-
- 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<CXFJaxRsServiceRegistrator> 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<CXFJaxRsServiceRegistrator> reference,
- CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator) {
-
- removedService(reference, cxfJaxRsServiceRegistrator);
- addingService(reference);
- }
-
- @Override
- public void removedService(
- ServiceReference<CXFJaxRsServiceRegistrator> 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<Application, TrackedJaxRsRegistrator> {
-
- private BundleContext _bundleContext;
- private Bus _bus;
-
- public ApplicationServiceTrackerCustomizer(BundleContext bundleContext, Bus bus) {
- _bundleContext = bundleContext;
- _bus = bus;
- }
-
- @Override
- public TrackedJaxRsRegistrator addingService(ServiceReference<Application> serviceReference) {
- Application application = _bundleContext.getService(serviceReference);
- try {
- Map<String, Object> 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<Application> serviceReference, TrackedJaxRsRegistrator tracked) {
- removedService(serviceReference, tracked);
- addingService(serviceReference);
- }
-
- @Override
- public void removedService(ServiceReference<Application> 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<Object, ServiceTracker<?, ?>> {
-
- private BundleContext _bundleContext;
-
- public FiltersAndInterceptorsServiceTrackerCustomizer(
- BundleContext bundleContext) {
-
- _bundleContext = bundleContext;
- }
-
- @Override
- public ServiceTracker<?, ?> addingService(final ServiceReference<Object> reference) {
- final String filterBase =
- reference.getProperty("osgi.jaxrs.filter.base").toString();
-
- final Object service = _bundleContext.getService(reference);
-
- ServiceTracker<CXFJaxRsServiceRegistrator, CXFJaxRsServiceRegistrator> serviceTracker = new ServiceTracker<>(
- _bundleContext, CXFJaxRsServiceRegistrator.class,
- new ServiceTrackerCustomizer
- <CXFJaxRsServiceRegistrator, CXFJaxRsServiceRegistrator>() {
-
- @Override
- public CXFJaxRsServiceRegistrator addingService(
- ServiceReference<CXFJaxRsServiceRegistrator> 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<CXFJaxRsServiceRegistrator> reference,
- CXFJaxRsServiceRegistrator serviceRegistrator) {
-
- removedService(reference, serviceRegistrator);
- addingService(reference);
- }
-
- @Override
- public void removedService(
- ServiceReference<CXFJaxRsServiceRegistrator> reference,
- CXFJaxRsServiceRegistrator serviceRegistrator) {
-
- try {
- serviceRegistrator.remove(service);
- }
- finally {
- _bundleContext.ungetService(reference);
- }
- }
- });
-
- serviceTracker.open();
-
- return serviceTracker;
- }
-
- @Override
- public void modifiedService(
- ServiceReference<Object> reference, ServiceTracker<?, ?> serviceTracker) {
-
- removedService(reference, serviceTracker);
- addingService(reference);
- }
-
- @Override
- public void removedService(
- ServiceReference<Object> 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<Object, TrackedJaxRsRegistrator> {
-
- private BundleContext _bundleContext;
- private Bus _bus;
-
- public SingletonServiceTrackerCustomizer(BundleContext bundleContext, Bus bus) {
- _bundleContext = bundleContext;
- _bus = bus;
- }
-
- @Override
- public TrackedJaxRsRegistrator addingService(
- ServiceReference<Object> serviceReference) {
-
- final Object service = _bundleContext.getService(serviceReference);
- Application application = new Application() {
- @Override
- public Set<Object> getSingletons() {
- return Collections.singleton(service);
- }
- };
- try {
- Map<String, Object> 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<Object> serviceReference, TrackedJaxRsRegistrator tracked) {
- removedService(serviceReference, tracked);
- addingService(serviceReference);
- }
-
- @Override
- public void removedService(ServiceReference<Object> 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<String, Object> 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