jaxrs
diff --git a/cdi-bom/pom.xml b/cdi-bom/pom.xml
index 64e0752..35f8c82 100644
--- a/cdi-bom/pom.xml
+++ b/cdi-bom/pom.xml
@@ -59,6 +59,12 @@
</dependency>
<dependency>
<groupId>org.apache.aries.cdi</groupId>
+ <artifactId>org.apache.aries.cdi.extension.jaxrs</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.cdi</groupId>
<artifactId>org.apache.aries.cdi.extension.jndi</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
@@ -101,6 +107,12 @@
</dependency>
<dependency>
<groupId>org.apache.aries.cdi</groupId>
+ <artifactId>org.apache.aries.cdi.extension.spi</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.cdi</groupId>
<artifactId>org.apache.aries.cdi.extra</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
diff --git a/cdi-executable/base.bndrun b/cdi-executable/base.bndrun
index 396921a..6216eda 100644
--- a/cdi-executable/base.bndrun
+++ b/cdi-executable/base.bndrun
@@ -38,3 +38,6 @@
org.slf4j.spi;version=1.7.28,\
sun.invoke,\
sun.misc
+
+-runblacklist.base: \
+ osgi.identity;filter:='(osgi.identity=biz.aQute.bndlib)'
diff --git a/cdi-executable/owb-executable.bndrun b/cdi-executable/owb-executable.bndrun
index e0a29f0..957f2ce 100644
--- a/cdi-executable/owb-executable.bndrun
+++ b/cdi-executable/owb-executable.bndrun
@@ -24,6 +24,7 @@
openwebbeans-impl;version='[2.0.14,2.0.15)',\
openwebbeans-spi;version='[2.0.14,2.0.15)',\
org.apache.aries.cdi.extender;version='[1.1.0,1.1.1)',\
+ org.apache.aries.cdi.extension.spi;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.owb;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.spi;version='[1.1.0,1.1.1)',\
org.apache.aries.spifly.dynamic.framework.extension;version='[1.2.3,1.2.4)',\
diff --git a/cdi-executable/weld-executable.bndrun b/cdi-executable/weld-executable.bndrun
index 4103d24..dd58d9f 100644
--- a/cdi-executable/weld-executable.bndrun
+++ b/cdi-executable/weld-executable.bndrun
@@ -27,6 +27,7 @@
javax.transaction-api;version='[1.2.0,1.2.1)',\
jboss-classfilewriter;version='[1.2.3,1.2.4)',\
org.apache.aries.cdi.extender;version='[1.1.0,1.1.1)',\
+ org.apache.aries.cdi.extension.spi;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.spi;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.weld;version='[1.1.0,1.1.1)',\
org.apache.aries.spifly.dynamic.framework.extension;version='[1.2.3,1.2.4)',\
diff --git a/cdi-extender/pom.xml b/cdi-extender/pom.xml
index 0821749..4e74ef9 100644
--- a/cdi-extender/pom.xml
+++ b/cdi-extender/pom.xml
@@ -64,6 +64,11 @@
<dependencies>
<dependency>
<groupId>org.apache.aries.cdi</groupId>
+ <artifactId>org.apache.aries.cdi.extension.spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.cdi</groupId>
<artifactId>org.apache.aries.cdi.spi</artifactId>
<version>${project.version}</version>
</dependency>
diff --git a/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/util/Annotates.java b/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/util/Annotates.java
index 9239d4a..584076b 100644
--- a/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/util/Annotates.java
+++ b/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/util/Annotates.java
@@ -14,6 +14,8 @@
package org.apache.aries.cdi.container.internal.util;
+import static java.util.Arrays.asList;
+import static java.util.Optional.ofNullable;
import static org.apache.aries.cdi.container.internal.util.Reflection.getRawType;
import java.lang.annotation.Annotation;
@@ -26,10 +28,10 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import javax.decorator.Decorator;
import javax.enterprise.context.ApplicationScoped;
@@ -56,6 +58,7 @@
import javax.inject.Scope;
import javax.interceptor.Interceptor;
+import org.apache.aries.cdi.extension.spi.annotation.AdaptedService;
import org.osgi.service.cdi.ServiceScope;
import org.osgi.service.cdi.annotations.Service;
import org.osgi.service.cdi.annotations.ServiceInstance;
@@ -185,11 +188,11 @@
if (annotated instanceof AnnotatedType) {
Class<?> annotatedClass = ((AnnotatedType<?>)annotated).getJavaClass();
- Optional.ofNullable(annotatedClass.getAnnotatedSuperclass()).ifPresent(at -> ats.add(at));
- ats.addAll(Arrays.asList(annotatedClass.getAnnotatedInterfaces()));
+ ofNullable(annotatedClass.getAnnotatedSuperclass()).ifPresent(at -> ats.add(at));
+ ats.addAll(asList(annotatedClass.getAnnotatedInterfaces()));
for (java.lang.reflect.AnnotatedType at : ats) {
- Optional.ofNullable(at.getAnnotation(Service.class)).ifPresent(
+ ofNullable(at.getAnnotation(Service.class)).ifPresent(
service -> {
if (service.value().length > 0) {
throw new IllegalArgumentException(
@@ -212,6 +215,10 @@
);
}
+ ofNullable(
+ annotated.getAnnotation(AdaptedService.class)
+ ).map(AdaptedService::value).map(Stream::of).orElseGet(Stream::empty).forEach(serviceTypes::add);
+
Service service = annotated.getAnnotation(Service.class);
if (service == null) {
diff --git a/cdi-extension-jaxrs/LICENSE b/cdi-extension-jaxrs/LICENSE
new file mode 100644
index 0000000..6b0b127
--- /dev/null
+++ b/cdi-extension-jaxrs/LICENSE
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
diff --git a/cdi-extension-jaxrs/NOTICE b/cdi-extension-jaxrs/NOTICE
new file mode 100644
index 0000000..424644d
--- /dev/null
+++ b/cdi-extension-jaxrs/NOTICE
@@ -0,0 +1,8 @@
+
+Apache Aries
+Copyright 2009-2011 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+
diff --git a/cdi-extension-jaxrs/pom.xml b/cdi-extension-jaxrs/pom.xml
new file mode 100644
index 0000000..772d78a
--- /dev/null
+++ b/cdi-extension-jaxrs/pom.xml
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/**
+ * Licensed 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.
+ */
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.aries.cdi</groupId>
+ <artifactId>org.apache.aries.cdi</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>org.apache.aries.cdi.extension.jaxrs</artifactId>
+ <name>Apache Aries CDI - JAX-RS Extension</name>
+ <description>
+ Provides support to CDI bundles for JAX-RS components.
+ </description>
+
+ <licenses>
+ <license>
+ <name>ASL 2.0</name>
+ <url>https://www.apache.org/licenses/LICENSE-2.0</url>
+ </license>
+ </licenses>
+
+ <scm>
+ <connection>scm:git:git@github.com:apache/aries-cdi.git</connection>
+ <developerConnection>scm:git:git@github.com:apache/aries-cdi.git</developerConnection>
+ <tag>HEAD</tag>
+ <url>https://github.com/apache/aries-cdi</url>
+ </scm>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>bnd-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.aries.cdi</groupId>
+ <artifactId>org.apache.aries.cdi.extension.spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.cdi</groupId>
+ <artifactId>org.apache.aries.cdi.extra</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.cdi</groupId>
+ <artifactId>org.apache.aries.cdi.spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-annotation_1.3_spec</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-atinject_1.0_spec</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-interceptor_1.2_spec</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jaxrs_2.1_spec</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jcdi_2.0_spec</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.namespace.extender</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.namespace.implementation</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.namespace.service</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.cdi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.jaxrs</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.annotation</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.core</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/cdi-extension-jaxrs/src/main/java/org/apache/aries/cdi/extension/jaxrs/JaxrsActivator.java b/cdi-extension-jaxrs/src/main/java/org/apache/aries/cdi/extension/jaxrs/JaxrsActivator.java
new file mode 100644
index 0000000..cf80ad2
--- /dev/null
+++ b/cdi-extension-jaxrs/src/main/java/org/apache/aries/cdi/extension/jaxrs/JaxrsActivator.java
@@ -0,0 +1,53 @@
+/**
+ * Licensed 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.cdi.extension.jaxrs;
+
+import static org.osgi.framework.Constants.BUNDLE_ACTIVATOR;
+import static org.osgi.framework.Constants.SERVICE_DESCRIPTION;
+import static org.osgi.framework.Constants.SERVICE_VENDOR;
+import static org.osgi.service.cdi.CDIConstants.CDI_EXTENSION_PROPERTY;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.enterprise.inject.spi.Extension;
+
+import org.osgi.annotation.bundle.Header;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+@Header(name = BUNDLE_ACTIVATOR, value = "${@class}")
+public class JaxrsActivator implements BundleActivator {
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ Dictionary<String, Object> properties = new Hashtable<>();
+ properties.put(CDI_EXTENSION_PROPERTY, "aries.cdi.jaxrs");
+ properties.put(SERVICE_DESCRIPTION, "Apache Aries CDI - JAX-RS Extension");
+ properties.put(SERVICE_VENDOR, "Apache Software Foundation");
+
+ _serviceRegistration = context.registerService(
+ Extension.class, new JaxrsExtensionFactory(), properties);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ _serviceRegistration.unregister();
+ }
+
+ private ServiceRegistration<Extension> _serviceRegistration;
+
+}
diff --git a/cdi-extension-jaxrs/src/main/java/org/apache/aries/cdi/extension/jaxrs/JaxrsCDIExtension.java b/cdi-extension-jaxrs/src/main/java/org/apache/aries/cdi/extension/jaxrs/JaxrsCDIExtension.java
new file mode 100644
index 0000000..aad1e54
--- /dev/null
+++ b/cdi-extension-jaxrs/src/main/java/org/apache/aries/cdi/extension/jaxrs/JaxrsCDIExtension.java
@@ -0,0 +1,352 @@
+/**
+ * Licensed 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.cdi.extension.jaxrs;
+
+import static java.util.Optional.ofNullable;
+
+import java.lang.annotation.Annotation;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+import javax.enterprise.inject.spi.WithAnnotations;
+import javax.enterprise.inject.spi.configurator.AnnotatedTypeConfigurator;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HEAD;
+import javax.ws.rs.OPTIONS;
+import javax.ws.rs.PATCH;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.container.DynamicFeature;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Feature;
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.ParamConverterProvider;
+import javax.ws.rs.ext.ReaderInterceptor;
+import javax.ws.rs.ext.WriterInterceptor;
+
+import org.apache.aries.cdi.extension.spi.annotation.AdaptedService;
+import org.apache.aries.cdi.extra.propertytypes.JaxrsApplicationBase;
+import org.apache.aries.cdi.extra.propertytypes.JaxrsApplicationSelect;
+import org.apache.aries.cdi.extra.propertytypes.JaxrsExtension;
+import org.apache.aries.cdi.extra.propertytypes.JaxrsExtensionSelect;
+import org.apache.aries.cdi.extra.propertytypes.JaxrsName;
+import org.apache.aries.cdi.extra.propertytypes.JaxrsResource;
+import org.apache.aries.cdi.extra.propertytypes.JaxrsWhiteboardTarget;
+import org.apache.aries.cdi.spi.configuration.Configuration;
+import org.osgi.service.cdi.ServiceScope;
+import org.osgi.service.cdi.annotations.Service;
+import org.osgi.service.cdi.annotations.ServiceInstance;
+import org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants;
+
+public class JaxrsCDIExtension implements Extension {
+
+ private volatile Configuration configuration;
+
+ void getConfiguration(@Observes Configuration configuration) {
+ this.configuration = configuration;
+ }
+
+ void application(
+ @Observes @WithAnnotations(ApplicationPath.class)
+ ProcessAnnotatedType<? extends Application> pat) {
+
+ AnnotatedType<? extends Application> annotatedType = pat.getAnnotatedType();
+
+ AnnotatedTypeConfigurator<? extends Application> configurator = pat.configureAnnotatedType();
+
+ if (!commonProperties(annotatedType, configurator, Application.class, true)) {
+ return;
+ }
+
+ if (!annotatedType.isAnnotationPresent(JaxrsApplicationBase.class)) {
+ configurator.add(
+ JaxrsApplicationBase.Literal.of(
+ annotatedType.getAnnotation(ApplicationPath.class).value()));
+ }
+ }
+
+ <X> void resource(
+ @Observes @WithAnnotations({Path.class, DELETE.class, GET.class, HEAD.class, OPTIONS.class, PATCH.class, POST.class, PUT.class})
+ ProcessAnnotatedType<X> pat) {
+
+ AnnotatedType<X> annotatedType = pat.getAnnotatedType();
+
+ AnnotatedTypeConfigurator<X> configurator = pat.configureAnnotatedType();
+
+ if (!commonProperties(annotatedType, configurator, Object.class, false)) {
+ return;
+ }
+
+ if (!annotatedType.isAnnotationPresent(JaxrsResource.class)) {
+ configurator.add(JaxrsResource.Literal.INSTANCE);
+ }
+ }
+
+ void containerRequestFilter(
+ @Observes ProcessAnnotatedType<? extends ContainerRequestFilter> pat) {
+
+ AnnotatedType<? extends ContainerRequestFilter> annotatedType = pat.getAnnotatedType();
+
+ AnnotatedTypeConfigurator<? extends ContainerRequestFilter> configurator = pat.configureAnnotatedType();
+
+ if (!commonProperties(annotatedType, configurator, ContainerRequestFilter.class, false)) {
+ return;
+ }
+
+ if (!annotatedType.isAnnotationPresent(JaxrsExtension.class)) {
+ configurator.add(JaxrsExtension.Literal.INSTANCE);
+ }
+ }
+
+ void containerResponseFilter(
+ @Observes ProcessAnnotatedType<? extends ContainerResponseFilter> pat) {
+
+ AnnotatedType<? extends ContainerResponseFilter> annotatedType = pat.getAnnotatedType();
+
+ AnnotatedTypeConfigurator<? extends ContainerResponseFilter> configurator = pat.configureAnnotatedType();
+
+ if (!commonProperties(annotatedType, configurator, ContainerResponseFilter.class, false)) {
+ return;
+ }
+
+ if (!annotatedType.isAnnotationPresent(JaxrsExtension.class)) {
+ configurator.add(JaxrsExtension.Literal.INSTANCE);
+ }
+ }
+
+ void readerInterceptor(
+ @Observes ProcessAnnotatedType<? extends ReaderInterceptor> pat) {
+
+ AnnotatedType<? extends ReaderInterceptor> annotatedType = pat.getAnnotatedType();
+
+ AnnotatedTypeConfigurator<? extends ReaderInterceptor> configurator = pat.configureAnnotatedType();
+
+ if (!commonProperties(annotatedType, configurator, ReaderInterceptor.class, false)) {
+ return;
+ }
+
+ if (!annotatedType.isAnnotationPresent(JaxrsExtension.class)) {
+ configurator.add(JaxrsExtension.Literal.INSTANCE);
+ }
+ }
+
+ void writerInterceptor(
+ @Observes ProcessAnnotatedType<? extends WriterInterceptor> pat) {
+
+ AnnotatedType<? extends WriterInterceptor> annotatedType = pat.getAnnotatedType();
+
+ AnnotatedTypeConfigurator<? extends WriterInterceptor> configurator = pat.configureAnnotatedType();
+
+ if (!commonProperties(annotatedType, configurator, WriterInterceptor.class, false)) {
+ return;
+ }
+
+ if (!annotatedType.isAnnotationPresent(JaxrsExtension.class)) {
+ configurator.add(JaxrsExtension.Literal.INSTANCE);
+ }
+ }
+
+ @SuppressWarnings("rawtypes")
+ void messageBodyReader(
+ @Observes ProcessAnnotatedType<? extends MessageBodyReader> pat) {
+
+ AnnotatedType<? extends MessageBodyReader> annotatedType = pat.getAnnotatedType();
+
+ AnnotatedTypeConfigurator<? extends MessageBodyReader> configurator = pat.configureAnnotatedType();
+
+ if (!commonProperties(annotatedType, configurator, MessageBodyReader.class, false)) {
+ return;
+ }
+
+ if (!annotatedType.isAnnotationPresent(JaxrsExtension.class)) {
+ configurator.add(JaxrsExtension.Literal.INSTANCE);
+ }
+ }
+
+ @SuppressWarnings("rawtypes")
+ void messageBodyWriter(
+ @Observes ProcessAnnotatedType<? extends MessageBodyWriter> pat) {
+
+ AnnotatedType<? extends MessageBodyWriter> annotatedType = pat.getAnnotatedType();
+
+ AnnotatedTypeConfigurator<? extends MessageBodyWriter> configurator = pat.configureAnnotatedType();
+
+ if (!commonProperties(annotatedType, configurator, MessageBodyWriter.class, false)) {
+ return;
+ }
+
+ if (!annotatedType.isAnnotationPresent(JaxrsExtension.class)) {
+ configurator.add(JaxrsExtension.Literal.INSTANCE);
+ }
+ }
+
+ @SuppressWarnings("rawtypes")
+ void contextResolver(
+ @Observes ProcessAnnotatedType<? extends ContextResolver> pat) {
+
+ AnnotatedType<? extends ContextResolver> annotatedType = pat.getAnnotatedType();
+
+ AnnotatedTypeConfigurator<? extends ContextResolver> configurator = pat.configureAnnotatedType();
+
+ if (!commonProperties(annotatedType, configurator, ContextResolver.class, false)) {
+ return;
+ }
+
+ if (!annotatedType.isAnnotationPresent(JaxrsExtension.class)) {
+ configurator.add(JaxrsExtension.Literal.INSTANCE);
+ }
+ }
+
+ @SuppressWarnings("rawtypes")
+ void exceptionMapper(
+ @Observes ProcessAnnotatedType<? extends ExceptionMapper> pat) {
+
+ AnnotatedType<? extends ExceptionMapper> annotatedType = pat.getAnnotatedType();
+
+ AnnotatedTypeConfigurator<? extends ExceptionMapper> configurator = pat.configureAnnotatedType();
+
+ if (!commonProperties(annotatedType, configurator, ExceptionMapper.class, false)) {
+ return;
+ }
+
+ if (!annotatedType.isAnnotationPresent(JaxrsExtension.class)) {
+ configurator.add(JaxrsExtension.Literal.INSTANCE);
+ }
+ }
+
+ void paramConverterProvider(
+ @Observes ProcessAnnotatedType<? extends ParamConverterProvider> pat) {
+
+ AnnotatedType<? extends ParamConverterProvider> annotatedType = pat.getAnnotatedType();
+
+ AnnotatedTypeConfigurator<? extends ParamConverterProvider> configurator = pat.configureAnnotatedType();
+
+ if (!commonProperties(annotatedType, configurator, ParamConverterProvider.class, false)) {
+ return;
+ }
+
+ if (!annotatedType.isAnnotationPresent(JaxrsExtension.class)) {
+ configurator.add(JaxrsExtension.Literal.INSTANCE);
+ }
+ }
+
+ void feature(
+ @Observes ProcessAnnotatedType<? extends Feature> pat) {
+
+ AnnotatedType<? extends Feature> annotatedType = pat.getAnnotatedType();
+
+ AnnotatedTypeConfigurator<? extends Feature> configurator = pat.configureAnnotatedType();
+
+ if (!commonProperties(annotatedType, configurator, Feature.class, false)) {
+ return;
+ }
+
+ if (!annotatedType.isAnnotationPresent(JaxrsExtension.class)) {
+ configurator.add(JaxrsExtension.Literal.INSTANCE);
+ }
+ }
+
+ void dynamicFeature(
+ @Observes ProcessAnnotatedType<? extends DynamicFeature> pat) {
+
+ AnnotatedType<? extends DynamicFeature> annotatedType = pat.getAnnotatedType();
+
+ AnnotatedTypeConfigurator<? extends DynamicFeature> configurator = pat.configureAnnotatedType();
+
+ if (!commonProperties(annotatedType, configurator, DynamicFeature.class, false)) {
+ return;
+ }
+
+ if (!annotatedType.isAnnotationPresent(JaxrsExtension.class)) {
+ configurator.add(JaxrsExtension.Literal.INSTANCE);
+ }
+ }
+
+ /*
+ * @return true if common properties were added (i.e. if no @Service was found)
+ */
+ boolean commonProperties(
+ AnnotatedType<?> annotatedType, AnnotatedTypeConfigurator<?> configurator,
+ Class<?> serviceType, boolean application) {
+
+ if (annotatedType.isAnnotationPresent(Service.class)) {
+ return false;
+ }
+
+ Set<Class<?>> serviceTypes = new HashSet<>();
+ serviceTypes.add(serviceType);
+
+ AdaptedService adaptedService = annotatedType.getAnnotation(AdaptedService.class);
+
+ if (adaptedService != null) {
+ configurator.remove(adaptedService::equals);
+ serviceTypes.addAll(Arrays.asList(adaptedService.value()));
+ }
+
+ configurator.add(
+ AdaptedService.Literal.of(serviceTypes.toArray(new Class<?>[0])));
+
+ if (!annotatedType.isAnnotationPresent(JaxrsName.class)) {
+ configurator.add(
+ JaxrsName.Literal.of(
+ annotatedType.getJavaClass().getSimpleName()));
+ }
+
+ if (!application && !annotatedType.isAnnotationPresent(JaxrsApplicationSelect.class)) {
+ ofNullable((String)configuration.get(JaxrsWhiteboardConstants.JAX_RS_APPLICATION_SELECT)).ifPresent(
+ select -> configurator.add(JaxrsApplicationSelect.Literal.of(select))
+ );
+ }
+
+ if (!annotatedType.isAnnotationPresent(JaxrsExtensionSelect.class)) {
+ ofNullable((String[])configuration.get(JaxrsWhiteboardConstants.JAX_RS_EXTENSION_SELECT)).ifPresent(selects -> {
+ if (selects.length > 0) {
+ configurator.add(JaxrsExtensionSelect.Literal.of(selects));
+ }
+ });
+ }
+
+ if (!annotatedType.isAnnotationPresent(JaxrsWhiteboardTarget.class)) {
+ ofNullable((String)configuration.get(JaxrsWhiteboardConstants.JAX_RS_WHITEBOARD_TARGET)).ifPresent(
+ target -> configurator.add(JaxrsWhiteboardTarget.Literal.of(target))
+ );
+ }
+
+ if (!annotatedType.isAnnotationPresent(ServiceInstance.class)) {
+ Class<? extends Annotation> beanScope = Util.beanScope(annotatedType, Dependent.class);
+
+ if (Dependent.class.equals(beanScope)) {
+ configurator.add(ServiceInstance.Literal.of(ServiceScope.PROTOTYPE));
+ }
+ }
+
+ return true;
+ }
+
+}
diff --git a/cdi-extension-jaxrs/src/main/java/org/apache/aries/cdi/extension/jaxrs/JaxrsExtensionFactory.java b/cdi-extension-jaxrs/src/main/java/org/apache/aries/cdi/extension/jaxrs/JaxrsExtensionFactory.java
new file mode 100644
index 0000000..d71fa5b
--- /dev/null
+++ b/cdi-extension-jaxrs/src/main/java/org/apache/aries/cdi/extension/jaxrs/JaxrsExtensionFactory.java
@@ -0,0 +1,37 @@
+/**
+ * Licensed 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.cdi.extension.jaxrs;
+
+import javax.enterprise.inject.spi.Extension;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.PrototypeServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+public class JaxrsExtensionFactory implements PrototypeServiceFactory<Extension> {
+
+ @Override
+ public Extension getService(
+ Bundle bundle, ServiceRegistration<Extension> registration) {
+
+ return new JaxrsCDIExtension();
+ }
+
+ @Override
+ public void ungetService(
+ Bundle bundle, ServiceRegistration<Extension> registration, Extension service) {
+ }
+
+}
diff --git a/cdi-extension-jaxrs/src/main/java/org/apache/aries/cdi/extension/jaxrs/Util.java b/cdi-extension-jaxrs/src/main/java/org/apache/aries/cdi/extension/jaxrs/Util.java
new file mode 100644
index 0000000..c03e358
--- /dev/null
+++ b/cdi-extension-jaxrs/src/main/java/org/apache/aries/cdi/extension/jaxrs/Util.java
@@ -0,0 +1,61 @@
+/**
+ * Licensed 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.cdi.extension.jaxrs;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.function.Predicate;
+
+import javax.enterprise.context.NormalScope;
+import javax.enterprise.inject.spi.Annotated;
+import javax.inject.Scope;
+
+public class Util {
+
+ private static final Predicate<Annotation> isScope = annotation ->
+ annotation.annotationType().isAnnotationPresent(Scope.class) ||
+ annotation.annotationType().isAnnotationPresent(NormalScope.class);
+
+ public static Class<? extends Annotation> beanScope(Annotated annotated, Class<? extends Annotation> defaultValue) {
+ Class<? extends Annotation> scope = collect(annotated.getAnnotations()).stream().filter(isScope).map(Annotation::annotationType).findFirst().orElse(null);
+
+ return (scope == null) ? defaultValue : scope;
+ }
+
+ private static List<Annotation> collect(Collection<Annotation> annotations) {
+ List<Annotation> list = new ArrayList<>();
+ for (Annotation a1 : annotations) {
+ if (a1.annotationType().getName().startsWith("java.lang.annotation.")) continue;
+ list.add(a1);
+ }
+ list.addAll(inherit(list));
+ return list;
+ }
+
+ private static List<Annotation> inherit(Collection<Annotation> annotations) {
+ List<Annotation> list = new ArrayList<>();
+ for (Annotation a1 : annotations) {
+ for (Annotation a2 : collect(Arrays.asList(a1.annotationType().getAnnotations()))) {
+ if (list.contains(a2)) continue;
+ list.add(a2);
+ }
+ }
+ return list;
+ }
+
+}
diff --git a/cdi-extension-jaxrs/src/main/java/org/apache/aries/cdi/extension/jaxrs/package-info.java b/cdi-extension-jaxrs/src/main/java/org/apache/aries/cdi/extension/jaxrs/package-info.java
new file mode 100644
index 0000000..3dec230
--- /dev/null
+++ b/cdi-extension-jaxrs/src/main/java/org/apache/aries/cdi/extension/jaxrs/package-info.java
@@ -0,0 +1,39 @@
+/**
+ * Licensed 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.
+ */
+
+@Capability(
+ attribute = "objectClass:List<String>=javax.enterprise.inject.spi.Extension",
+ namespace = SERVICE_NAMESPACE
+)
+@Capability(
+ namespace = CDI_EXTENSION_PROPERTY,
+ name = "aries.cdi.jaxrs",
+ uses= {
+ javax.enterprise.inject.spi.Extension.class,
+ javax.ws.rs.Path.class,
+ javax.ws.rs.core.Application.class,
+ javax.ws.rs.ext.Provider.class
+ },
+ version = "1.0.0"
+)
+@RequireCDIImplementation
+@RequireJaxrsWhiteboard
+package org.apache.aries.cdi.extension.jaxrs;
+
+import static org.osgi.namespace.service.ServiceNamespace.SERVICE_NAMESPACE;
+import static org.osgi.service.cdi.CDIConstants.CDI_EXTENSION_PROPERTY;
+
+import org.osgi.annotation.bundle.Capability;
+import org.osgi.service.cdi.annotations.RequireCDIImplementation;
+import org.osgi.service.jaxrs.whiteboard.annotations.RequireJaxrsWhiteboard;
diff --git a/cdi-extension-servlet-common/pom.xml b/cdi-extension-servlet-common/pom.xml
index 23fb934..fcda251 100644
--- a/cdi-extension-servlet-common/pom.xml
+++ b/cdi-extension-servlet-common/pom.xml
@@ -59,6 +59,11 @@
<dependencies>
<dependency>
<groupId>org.apache.aries.cdi</groupId>
+ <artifactId>org.apache.aries.cdi.extension.spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.cdi</groupId>
<artifactId>org.apache.aries.cdi.extra</artifactId>
<version>${project.version}</version>
</dependency>
diff --git a/cdi-extension-servlet-common/src/main/java/org/apache/aries/cdi/extension/servlet/common/WebFilterProcessor.java b/cdi-extension-servlet-common/src/main/java/org/apache/aries/cdi/extension/servlet/common/WebFilterProcessor.java
index 5318efe..14007a4 100644
--- a/cdi-extension-servlet-common/src/main/java/org/apache/aries/cdi/extension/servlet/common/WebFilterProcessor.java
+++ b/cdi-extension-servlet-common/src/main/java/org/apache/aries/cdi/extension/servlet/common/WebFilterProcessor.java
@@ -14,17 +14,20 @@
package org.apache.aries.cdi.extension.servlet.common;
+import static java.util.Optional.ofNullable;
import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT;
-import java.lang.annotation.Annotation;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
+import javax.enterprise.inject.spi.configurator.AnnotatedTypeConfigurator;
import javax.servlet.Filter;
import javax.servlet.annotation.WebFilter;
+import org.apache.aries.cdi.extension.spi.annotation.AdaptedService;
import org.apache.aries.cdi.extra.propertytypes.HttpWhiteboardContextSelect;
import org.apache.aries.cdi.extra.propertytypes.HttpWhiteboardFilterAsyncSupported;
import org.apache.aries.cdi.extra.propertytypes.HttpWhiteboardFilterDispatcher;
@@ -52,45 +55,60 @@
final AnnotatedType<X> annotatedType = pat.getAnnotatedType();
+ if (annotatedType.isAnnotationPresent(Service.class)) {
+ return;
+ }
+
WebFilter webFilter = annotatedType.getAnnotation(WebFilter.class);
- final Set<Annotation> annotationsToAdd = new HashSet<>();
+ AnnotatedTypeConfigurator<X> configurator = pat.configureAnnotatedType();
- if (!annotatedType.isAnnotationPresent(Service.class)) {
- annotationsToAdd.add(Service.Literal.of(new Class[] {Filter.class}));
+ Set<Class<?>> serviceTypes = new HashSet<>();
+ serviceTypes.add(Filter.class);
+
+ AdaptedService adaptedService = annotatedType.getAnnotation(AdaptedService.class);
+
+ if (adaptedService != null) {
+ configurator.remove(adaptedService::equals);
+ serviceTypes.addAll(Arrays.asList(adaptedService.value()));
}
+ configurator.add(
+ AdaptedService.Literal.of(serviceTypes.toArray(new Class<?>[0])));
+
if(!annotatedType.isAnnotationPresent(HttpWhiteboardContextSelect.class)) {
- annotationsToAdd.add(HttpWhiteboardContextSelect.Literal.of((String)configuration.get(HTTP_WHITEBOARD_CONTEXT_SELECT)));
+ ofNullable((String)configuration.get(HTTP_WHITEBOARD_CONTEXT_SELECT)).ifPresent(
+ select -> configurator.add(HttpWhiteboardContextSelect.Literal.of(select))
+ );
}
- if (!webFilter.description().isEmpty()) {
- annotationsToAdd.add(ServiceDescription.Literal.of(webFilter.description()));
+ if (!annotatedType.isAnnotationPresent(ServiceDescription.class) && !webFilter.description().isEmpty()) {
+ configurator.add(ServiceDescription.Literal.of(webFilter.description()));
}
- if (!webFilter.filterName().isEmpty()) {
- annotationsToAdd.add(HttpWhiteboardFilterName.Literal.of(webFilter.filterName()));
+ if (!annotatedType.isAnnotationPresent(HttpWhiteboardFilterName.class) && !webFilter.filterName().isEmpty()) {
+ configurator.add(HttpWhiteboardFilterName.Literal.of(webFilter.filterName()));
}
- if (webFilter.servletNames().length > 0) {
- annotationsToAdd.add(HttpWhiteboardFilterServlet.Literal.of(webFilter.servletNames()));
+ if (!annotatedType.isAnnotationPresent(HttpWhiteboardFilterServlet.class) && webFilter.servletNames().length > 0) {
+ configurator.add(HttpWhiteboardFilterServlet.Literal.of(webFilter.servletNames()));
}
- if (webFilter.value().length > 0) {
- annotationsToAdd.add(HttpWhiteboardFilterPattern.Literal.of(webFilter.value()));
- }
- else if (webFilter.urlPatterns().length > 0) {
- annotationsToAdd.add(HttpWhiteboardFilterPattern.Literal.of(webFilter.urlPatterns()));
+ if (!annotatedType.isAnnotationPresent(HttpWhiteboardFilterPattern.class)) {
+ if (webFilter.value().length > 0) {
+ configurator.add(HttpWhiteboardFilterPattern.Literal.of(webFilter.value()));
+ }
+ else if (webFilter.urlPatterns().length > 0) {
+ configurator.add(HttpWhiteboardFilterPattern.Literal.of(webFilter.urlPatterns()));
+ }
}
- if (webFilter.dispatcherTypes().length > 0) {
- annotationsToAdd.add(HttpWhiteboardFilterDispatcher.Literal.of(webFilter.dispatcherTypes()));
+ if (!annotatedType.isAnnotationPresent(HttpWhiteboardFilterDispatcher.class) && webFilter.dispatcherTypes().length > 0) {
+ configurator.add(HttpWhiteboardFilterDispatcher.Literal.of(webFilter.dispatcherTypes()));
}
- annotationsToAdd.add(HttpWhiteboardFilterAsyncSupported.Literal.of(webFilter.asyncSupported()));
-
- if (!annotationsToAdd.isEmpty()) {
- annotationsToAdd.forEach(pat.configureAnnotatedType()::add);
+ if(!annotatedType.isAnnotationPresent(HttpWhiteboardFilterAsyncSupported.class)) {
+ configurator.add(HttpWhiteboardFilterAsyncSupported.Literal.of(webFilter.asyncSupported()));
}
}
diff --git a/cdi-extension-servlet-common/src/main/java/org/apache/aries/cdi/extension/servlet/common/WebListenerProcessor.java b/cdi-extension-servlet-common/src/main/java/org/apache/aries/cdi/extension/servlet/common/WebListenerProcessor.java
index c175a39..115d4fc 100644
--- a/cdi-extension-servlet-common/src/main/java/org/apache/aries/cdi/extension/servlet/common/WebListenerProcessor.java
+++ b/cdi-extension-servlet-common/src/main/java/org/apache/aries/cdi/extension/servlet/common/WebListenerProcessor.java
@@ -14,18 +14,19 @@
package org.apache.aries.cdi.extension.servlet.common;
+import static java.util.Optional.ofNullable;
import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT;
-import java.lang.annotation.Annotation;
-import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
+import javax.enterprise.inject.spi.configurator.AnnotatedTypeConfigurator;
import javax.servlet.annotation.WebListener;
+import org.apache.aries.cdi.extension.spi.annotation.AdaptedService;
import org.apache.aries.cdi.extra.propertytypes.HttpWhiteboardContextSelect;
import org.apache.aries.cdi.extra.propertytypes.HttpWhiteboardListener;
import org.apache.aries.cdi.extra.propertytypes.ServiceDescription;
@@ -49,52 +50,62 @@
final AnnotatedType<X> annotatedType = pat.getAnnotatedType();
+ if (annotatedType.isAnnotationPresent(Service.class)) {
+ return;
+ }
+
WebListener webListener = annotatedType.getAnnotation(WebListener.class);
- final Set<Annotation> annotationsToAdd = new HashSet<>();
+ AnnotatedTypeConfigurator<X> configurator = pat.configureAnnotatedType();
- if (!annotatedType.isAnnotationPresent(Service.class)) {
- List<Class<?>> listenerTypes = new ArrayList<>();
+ Set<Class<?>> serviceTypes = new HashSet<>();
- Class<X> javaClass = annotatedType.getJavaClass();
+ Class<X> javaClass = annotatedType.getJavaClass();
- if (javax.servlet.ServletContextListener.class.isAssignableFrom(javaClass)) {
- listenerTypes.add(javax.servlet.ServletContextListener.class);
- }
- if (javax.servlet.ServletContextAttributeListener.class.isAssignableFrom(javaClass)) {
- listenerTypes.add(javax.servlet.ServletContextAttributeListener.class);
- }
- if (javax.servlet.ServletRequestListener.class.isAssignableFrom(javaClass)) {
- listenerTypes.add(javax.servlet.ServletRequestListener.class);
- }
- if (javax.servlet.ServletRequestAttributeListener.class.isAssignableFrom(javaClass)) {
- listenerTypes.add(javax.servlet.ServletRequestAttributeListener.class);
- }
- if (javax.servlet.http.HttpSessionListener.class.isAssignableFrom(javaClass)) {
- listenerTypes.add(javax.servlet.http.HttpSessionListener.class);
- }
- if (javax.servlet.http.HttpSessionAttributeListener.class.isAssignableFrom(javaClass)) {
- listenerTypes.add(javax.servlet.http.HttpSessionAttributeListener.class);
- }
- if (javax.servlet.http.HttpSessionIdListener.class.isAssignableFrom(javaClass)) {
- listenerTypes.add(javax.servlet.http.HttpSessionIdListener.class);
- }
-
- annotationsToAdd.add(Service.Literal.of(listenerTypes.toArray(new Class<?>[0])));
+ if (javax.servlet.ServletContextListener.class.isAssignableFrom(javaClass)) {
+ serviceTypes.add(javax.servlet.ServletContextListener.class);
}
+ if (javax.servlet.ServletContextAttributeListener.class.isAssignableFrom(javaClass)) {
+ serviceTypes.add(javax.servlet.ServletContextAttributeListener.class);
+ }
+ if (javax.servlet.ServletRequestListener.class.isAssignableFrom(javaClass)) {
+ serviceTypes.add(javax.servlet.ServletRequestListener.class);
+ }
+ if (javax.servlet.ServletRequestAttributeListener.class.isAssignableFrom(javaClass)) {
+ serviceTypes.add(javax.servlet.ServletRequestAttributeListener.class);
+ }
+ if (javax.servlet.http.HttpSessionListener.class.isAssignableFrom(javaClass)) {
+ serviceTypes.add(javax.servlet.http.HttpSessionListener.class);
+ }
+ if (javax.servlet.http.HttpSessionAttributeListener.class.isAssignableFrom(javaClass)) {
+ serviceTypes.add(javax.servlet.http.HttpSessionAttributeListener.class);
+ }
+ if (javax.servlet.http.HttpSessionIdListener.class.isAssignableFrom(javaClass)) {
+ serviceTypes.add(javax.servlet.http.HttpSessionIdListener.class);
+ }
+
+ AdaptedService adaptedService = annotatedType.getAnnotation(AdaptedService.class);
+
+ if (adaptedService != null) {
+ configurator.remove(adaptedService::equals);
+ serviceTypes.addAll(Arrays.asList(adaptedService.value()));
+ }
+
+ configurator.add(
+ AdaptedService.Literal.of(serviceTypes.toArray(new Class<?>[0])));
if(!annotatedType.isAnnotationPresent(HttpWhiteboardContextSelect.class)) {
- annotationsToAdd.add(HttpWhiteboardContextSelect.Literal.of((String)configuration.get(HTTP_WHITEBOARD_CONTEXT_SELECT)));
+ ofNullable((String)configuration.get(HTTP_WHITEBOARD_CONTEXT_SELECT)).ifPresent(
+ select -> configurator.add(HttpWhiteboardContextSelect.Literal.of(select))
+ );
}
- annotationsToAdd.add(HttpWhiteboardListener.Literal.INSTANCE);
-
- if (!webListener.value().isEmpty()) {
- annotationsToAdd.add(ServiceDescription.Literal.of(webListener.value()));
+ if(!annotatedType.isAnnotationPresent(HttpWhiteboardListener.class)) {
+ configurator.add(HttpWhiteboardListener.Literal.INSTANCE);
}
- if (!annotationsToAdd.isEmpty()) {
- annotationsToAdd.forEach(pat.configureAnnotatedType()::add);
+ if (!annotatedType.isAnnotationPresent(ServiceDescription.class) && !webListener.value().isEmpty()) {
+ configurator.add(ServiceDescription.Literal.of(webListener.value()));
}
}
diff --git a/cdi-extension-servlet-common/src/main/java/org/apache/aries/cdi/extension/servlet/common/WebServletProcessor.java b/cdi-extension-servlet-common/src/main/java/org/apache/aries/cdi/extension/servlet/common/WebServletProcessor.java
index 3b6e7e2..f441a78 100644
--- a/cdi-extension-servlet-common/src/main/java/org/apache/aries/cdi/extension/servlet/common/WebServletProcessor.java
+++ b/cdi-extension-servlet-common/src/main/java/org/apache/aries/cdi/extension/servlet/common/WebServletProcessor.java
@@ -14,18 +14,21 @@
package org.apache.aries.cdi.extension.servlet.common;
+import static java.util.Optional.ofNullable;
import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT;
-import java.lang.annotation.Annotation;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
+import javax.enterprise.inject.spi.configurator.AnnotatedTypeConfigurator;
import javax.servlet.Servlet;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
+import org.apache.aries.cdi.extension.spi.annotation.AdaptedService;
import org.apache.aries.cdi.extra.propertytypes.HttpWhiteboardContextSelect;
import org.apache.aries.cdi.extra.propertytypes.HttpWhiteboardServletAsyncSupported;
import org.apache.aries.cdi.extra.propertytypes.HttpWhiteboardServletMultipart;
@@ -53,50 +56,69 @@
final AnnotatedType<X> annotatedType = pat.getAnnotatedType();
+ if (annotatedType.isAnnotationPresent(Service.class)) {
+ return;
+ }
+
WebServlet webServlet = annotatedType.getAnnotation(WebServlet.class);
- final Set<Annotation> annotationsToAdd = new HashSet<>();
+ AnnotatedTypeConfigurator<X> configurator = pat.configureAnnotatedType();
- if (!annotatedType.isAnnotationPresent(Service.class)) {
- annotationsToAdd.add(Service.Literal.of(new Class[] {Servlet.class}));
+ Set<Class<?>> serviceTypes = new HashSet<>();
+ serviceTypes.add(Servlet.class);
+
+ AdaptedService adaptedService = annotatedType.getAnnotation(AdaptedService.class);
+
+ if (adaptedService != null) {
+ configurator.remove(adaptedService::equals);
+ serviceTypes.addAll(Arrays.asList(adaptedService.value()));
}
+ configurator.add(
+ AdaptedService.Literal.of(serviceTypes.toArray(new Class<?>[0])));
+
if(!annotatedType.isAnnotationPresent(HttpWhiteboardContextSelect.class)) {
- annotationsToAdd.add(HttpWhiteboardContextSelect.Literal.of((String)configuration.get(HTTP_WHITEBOARD_CONTEXT_SELECT)));
+ ofNullable((String)configuration.get(HTTP_WHITEBOARD_CONTEXT_SELECT)).ifPresent(
+ select -> configurator.add(HttpWhiteboardContextSelect.Literal.of(select))
+ );
}
- if (!webServlet.name().isEmpty()) {
- annotationsToAdd.add(HttpWhiteboardServletName.Literal.of(webServlet.name()));
+ if (!annotatedType.isAnnotationPresent(HttpWhiteboardServletName.class) && !webServlet.name().isEmpty()) {
+ configurator.add(HttpWhiteboardServletName.Literal.of(webServlet.name()));
}
- if (webServlet.value().length > 0) {
- annotationsToAdd.add(HttpWhiteboardServletPattern.Literal.of(webServlet.value()));
- }
- else if (webServlet.urlPatterns().length > 0) {
- annotationsToAdd.add(HttpWhiteboardServletPattern.Literal.of(webServlet.urlPatterns()));
+ if(!annotatedType.isAnnotationPresent(HttpWhiteboardServletPattern.class)) {
+ if (webServlet.value().length > 0) {
+ configurator.add(HttpWhiteboardServletPattern.Literal.of(webServlet.value()));
+ }
+ else if (webServlet.urlPatterns().length > 0) {
+ configurator.add(HttpWhiteboardServletPattern.Literal.of(webServlet.urlPatterns()));
+ }
}
- annotationsToAdd.add(ServiceRanking.Literal.of(webServlet.loadOnStartup()));
+ if (!annotatedType.isAnnotationPresent(ServiceRanking.class)) {
+ configurator.add(ServiceRanking.Literal.of(webServlet.loadOnStartup()));
+ }
// TODO Howto: INIT PARAMS ???
- annotationsToAdd.add(HttpWhiteboardServletAsyncSupported.Literal.of(webServlet.asyncSupported()));
-
- if (!webServlet.description().isEmpty()) {
- annotationsToAdd.add(ServiceDescription.Literal.of(webServlet.description()));
+ if (!annotatedType.isAnnotationPresent(HttpWhiteboardServletAsyncSupported.class)) {
+ configurator.add(HttpWhiteboardServletAsyncSupported.Literal.of(webServlet.asyncSupported()));
}
- MultipartConfig multipartConfig = annotatedType.getAnnotation(MultipartConfig.class);
+ if (!annotatedType.isAnnotationPresent(ServiceDescription.class) && !webServlet.description().isEmpty()) {
+ configurator.add(ServiceDescription.Literal.of(webServlet.description()));
+ }
- if (multipartConfig != null) {
- annotationsToAdd.add(HttpWhiteboardServletMultipart.Literal.of(true, multipartConfig.fileSizeThreshold(), multipartConfig.location(), multipartConfig.maxFileSize(), multipartConfig.maxRequestSize()));
+ if (!annotatedType.isAnnotationPresent(HttpWhiteboardServletMultipart.class)) {
+ MultipartConfig multipartConfig = annotatedType.getAnnotation(MultipartConfig.class);
+
+ if (multipartConfig != null) {
+ configurator.add(HttpWhiteboardServletMultipart.Literal.of(true, multipartConfig.fileSizeThreshold(), multipartConfig.location(), multipartConfig.maxFileSize(), multipartConfig.maxRequestSize()));
+ }
}
// TODO HowTo: ServletSecurity ???
-
- if (!annotationsToAdd.isEmpty()) {
- annotationsToAdd.forEach(pat.configureAnnotatedType()::add);
- }
}
}
diff --git a/cdi-extension-servlet-weld/pom.xml b/cdi-extension-servlet-weld/pom.xml
index b3ed01e..4618274 100644
--- a/cdi-extension-servlet-weld/pom.xml
+++ b/cdi-extension-servlet-weld/pom.xml
@@ -151,7 +151,7 @@
<groupId>org.osgi</groupId>
<artifactId>osgi.annotation</artifactId>
</dependency>
- <dependency>
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
</dependency>
diff --git a/cdi-extension-spi/pom.xml b/cdi-extension-spi/pom.xml
new file mode 100644
index 0000000..f010ece
--- /dev/null
+++ b/cdi-extension-spi/pom.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/**
+ * Licensed 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.
+ */
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.aries.cdi</groupId>
+ <artifactId>org.apache.aries.cdi</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>org.apache.aries.cdi.extension.spi</artifactId>
+ <name>Apache Aries CDI - SPI classes for Portable Extensions</name>
+ <description>Apache Aries CDI - SPI classes for Portable Extensions</description>
+
+ <licenses>
+ <license>
+ <name>ASL 2.0</name>
+ <url>https://www.apache.org/licenses/LICENSE-2.0</url>
+ </license>
+ </licenses>
+
+ <scm>
+ <connection>scm:git:git@github.com:apache/aries-cdi.git</connection>
+ <developerConnection>scm:git:git@github.com:apache/aries-cdi.git</developerConnection>
+ <tag>HEAD</tag>
+ <url>https://github.com/apache/aries-cdi</url>
+ </scm>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>bnd-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jcdi_2.0_spec</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.cdi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.annotation</artifactId>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
diff --git a/cdi-extension-spi/src/main/java/org/apache/aries/cdi/extension/spi/annotation/AdaptedService.java b/cdi-extension-spi/src/main/java/org/apache/aries/cdi/extension/spi/annotation/AdaptedService.java
new file mode 100644
index 0000000..a710085
--- /dev/null
+++ b/cdi-extension-spi/src/main/java/org/apache/aries/cdi/extension/spi/annotation/AdaptedService.java
@@ -0,0 +1,67 @@
+/**
+ * Licensed 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.cdi.extension.spi.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+/**
+ * Annotation used to hold the service types when an extension is adapting
+ * annotated types for publication as OSGi CDI services.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface AdaptedService {
+
+ /**
+ * Support inline instantiation of the {@link AdaptedService} annotation.
+ */
+ public static final class Literal extends AnnotationLiteral<AdaptedService>
+ implements AdaptedService {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @param interfaces
+ * @return instance of {@link AdaptedService}
+ */
+ public static final Literal of(Class<?>[] interfaces) {
+ return new Literal(interfaces);
+ }
+
+ private Literal(Class<?>[] interfaces) {
+ _interfaces = interfaces;
+ }
+
+ @Override
+ public Class<?>[] value() {
+ return _interfaces;
+ }
+
+ private final Class<?>[] _interfaces;
+ }
+
+ /**
+ * Override the interfaces under which this service is published.
+ *
+ * @return the service types
+ */
+ Class<?>[] value() default {};
+
+}
diff --git a/cdi-extension-spi/src/main/java/org/apache/aries/cdi/extension/spi/annotation/package-info.java b/cdi-extension-spi/src/main/java/org/apache/aries/cdi/extension/spi/annotation/package-info.java
new file mode 100644
index 0000000..6fa3b4d
--- /dev/null
+++ b/cdi-extension-spi/src/main/java/org/apache/aries/cdi/extension/spi/annotation/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) OSGi Alliance (2018). All Rights Reserved.
+ *
+ * Licensed 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.
+ */
+
+@org.osgi.annotation.bundle.Export
+@org.osgi.annotation.versioning.Version("1.0.0")
+package org.apache.aries.cdi.extension.spi.annotation;
\ No newline at end of file
diff --git a/cdi-itests/base-itest.bndrun b/cdi-itests/base-itest.bndrun
index 9cfa771..4179a84 100644
--- a/cdi-itests/base-itest.bndrun
+++ b/cdi-itests/base-itest.bndrun
@@ -46,3 +46,6 @@
osgi.identity;filter:='(osgi.identity=org.apache.aries.cdi.itests)',\
osgi.identity;filter:='(osgi.identity=org.apache.aries.jndi.core)',\
osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.command)'
+
+-runblacklist.base: \
+ osgi.identity;filter:='(osgi.identity=biz.aQute.bndlib)'
\ No newline at end of file
diff --git a/cdi-itests/bnd.bnd b/cdi-itests/bnd.bnd
index aa1bc3d..9a54ba4 100644
--- a/cdi-itests/bnd.bnd
+++ b/cdi-itests/bnd.bnd
@@ -77,7 +77,8 @@
tb20.jar,\
tb21.jar,\
tb22.jar,\
- tb23.jar
+ tb23.jar,\
+ tb24.jar
# Don't forget that we had to coax the `maven-jar-plugin` NOT to include the `sub-bundle` packages in
# the root bundle:
diff --git a/cdi-itests/bnd/tb24.bnd b/cdi-itests/bnd/tb24.bnd
new file mode 100644
index 0000000..e6e2413
--- /dev/null
+++ b/cdi-itests/bnd/tb24.bnd
@@ -0,0 +1,13 @@
+# Licensed 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.
+
+Export-Package: ${p}.tb24.*;-split-package:=first
diff --git a/cdi-itests/owb-itest.bndrun b/cdi-itests/owb-itest.bndrun
index 709594b..6a9ca09 100644
--- a/cdi-itests/owb-itest.bndrun
+++ b/cdi-itests/owb-itest.bndrun
@@ -32,6 +32,7 @@
org.apache.aries.cdi.extension.mp-metrics;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.extension.servlet.common;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.extension.servlet.owb;version='[1.1.0,1.1.1)',\
+ org.apache.aries.cdi.extension.spi;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.extra;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.itests;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.owb;version='[1.1.0,1.1.1)',\
@@ -73,4 +74,5 @@
org.osgi.test.junit4;version='[1.0.0,1.0.1)',\
org.osgi.util.function;version='[1.1.0,1.1.1)',\
org.osgi.util.promise;version='[1.1.0,1.1.1)',\
- org.apache.felix.configurator;version='[1.0.10,1.0.11)'
+ org.apache.felix.configurator;version='[1.0.10,1.0.11)',\
+ org.apache.aries.cdi.extension.jaxrs;version='[1.1.0,1.1.1)'
diff --git a/cdi-itests/pom.xml b/cdi-itests/pom.xml
index 8a20b32..fe921fa 100644
--- a/cdi-itests/pom.xml
+++ b/cdi-itests/pom.xml
@@ -158,12 +158,6 @@
</dependency>
<dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.test.junit4</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </dependency>
-
- <dependency>
<groupId>org.eclipse.microprofile.jwt</groupId>
<artifactId>microprofile-jwt-auth-tck</artifactId>
<version>${mp.jwt.auth.version}</version>
diff --git a/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/AbstractTestCase.java b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/base/BaseTestCase.java
similarity index 99%
rename from cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/AbstractTestCase.java
rename to cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/base/BaseTestCase.java
index 1af2340..8629ad5 100644
--- a/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/AbstractTestCase.java
+++ b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/base/BaseTestCase.java
@@ -66,6 +66,7 @@
namespace = ServiceNamespace.SERVICE_NAMESPACE
)
@RequireCDIExtension("aries.cdi.http")
+@RequireCDIExtension("aries.cdi.jaxrs")
@RequireCDIExtension("aries.cdi.jndi")
@RequireCDIExtension("eclipse.microprofile.config")
@RequireCDIExtension("eclipse.microprofile.jwt-auth")
diff --git a/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/base/JaxrsBaseTestCase.java b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/base/JaxrsBaseTestCase.java
new file mode 100644
index 0000000..f70661f
--- /dev/null
+++ b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/base/JaxrsBaseTestCase.java
@@ -0,0 +1,96 @@
+/**
+ * Licensed 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.cdi.test.cases;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Collection;
+
+import javax.ws.rs.client.ClientBuilder;
+
+import org.junit.After;
+import org.junit.Before;
+import org.osgi.framework.ServiceObjects;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.runtime.HttpServiceRuntime;
+import org.osgi.service.jaxrs.runtime.JaxrsServiceRuntime;
+import org.osgi.service.jaxrs.runtime.JaxrsServiceRuntimeConstants;
+import org.osgi.util.tracker.ServiceTracker;
+
+public abstract class JaxrsBaseTestCase extends SlimTestCase {
+
+ public String getEndpoint() {
+ Object endpointsObj = jsrReference.getProperty(
+ JaxrsServiceRuntimeConstants.JAX_RS_SERVICE_ENDPOINT);
+
+ if (endpointsObj instanceof String) {
+ return String.valueOf(endpointsObj);
+ }
+ else if (endpointsObj instanceof String[]) {
+ return ((String[])endpointsObj)[0];
+ }
+ else if (endpointsObj instanceof Collection) {
+ return String.valueOf(((Collection<?>)endpointsObj).iterator().next());
+ }
+
+ return null;
+ }
+
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ hsrTracker = new ServiceTracker<>(bundleContext, HttpServiceRuntime.class, null);
+
+ hsrTracker.open();
+
+ hsr = hsrTracker.waitForService(timeout);
+
+ jsrTracker = new ServiceTracker<>(bundleContext, JaxrsServiceRuntime.class, null);
+
+ jsrTracker.open();
+
+ jsr = jsrTracker.waitForService(timeout);
+
+ jsrReference = jsrTracker.getServiceReference();
+
+ cbTracker = new ServiceTracker<>(bundleContext, ClientBuilder.class, null);
+
+ cbTracker.open();
+
+ cb = cbTracker.waitForService(timeout);
+
+ cbSO = bundleContext.getServiceObjects(cbTracker.getServiceReference());
+
+ assertThat(cb).isNotNull();
+ }
+
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ hsrTracker.close();
+ jsrTracker.close();
+ cbTracker.close();
+ }
+
+ protected ClientBuilder cb;
+ protected ServiceObjects<ClientBuilder> cbSO;
+ protected ServiceTracker<ClientBuilder, ClientBuilder> cbTracker;
+ protected HttpServiceRuntime hsr;
+ protected ServiceTracker<HttpServiceRuntime, HttpServiceRuntime> hsrTracker = new ServiceTracker<>(bundleContext, HttpServiceRuntime.class, null);
+ protected JaxrsServiceRuntime jsr;
+ protected ServiceReference<JaxrsServiceRuntime> jsrReference;
+ protected ServiceTracker<JaxrsServiceRuntime, JaxrsServiceRuntime> jsrTracker;
+
+}
diff --git a/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/SlimTestCase.java b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/base/SlimBaseTestCase.java
similarity index 100%
rename from cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/SlimTestCase.java
rename to cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/base/SlimBaseTestCase.java
diff --git a/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/jaxrs/ResourceTests.java b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/jaxrs/ResourceTests.java
new file mode 100644
index 0000000..ce40ef7
--- /dev/null
+++ b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/jaxrs/ResourceTests.java
@@ -0,0 +1,66 @@
+package org.apache.aries.cdi.test.cases.jaxrs;
+
+import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+
+import java.util.concurrent.TimeUnit;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+
+import org.apache.aries.cdi.test.cases.JaxrsBaseTestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.osgi.test.junit4.service.ServiceUseRule;
+
+public class ResourceTests extends JaxrsBaseTestCase {
+ @Rule
+ public ServiceUseRule<ClientBuilder> cbr = new ServiceUseRule.Builder<>(ClientBuilder.class) //
+ .build();
+
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ cdiBundle = installBundle("tb24.jar");
+
+ int count = 100;
+ while (jsr.getRuntimeDTO().defaultApplication.resourceDTOs.length < 1 && (count > 0)) {
+ count--;
+ Thread.sleep(100);
+ }
+
+ assertThat(jsr.getRuntimeDTO().defaultApplication.resourceDTOs).extracting("name").contains(
+ "A");
+ }
+
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ cdiBundle.uninstall();
+ super.tearDown();
+ }
+
+ @Test
+ public void test() throws Exception {
+ final ClientBuilder cb = cbr.getService();
+ cb.connectTimeout(1000, TimeUnit.SECONDS);
+ cb.readTimeout(1000, TimeUnit.SECONDS);
+
+ final Client client = cb.build();
+
+ try {
+ final String serverToken = client.target(getEndpoint())
+ .path("a")
+ .request(TEXT_PLAIN_TYPE)
+ .get(String.class);
+ assertEquals("a", serverToken);
+ } finally {
+ client.close();
+ }
+ }
+
+}
diff --git a/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/mpjwt/MpJwtAuthTests.java b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/mpjwt/MpJwtAuthTests.java
index 9dbe41f..3c86fb9 100644
--- a/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/mpjwt/MpJwtAuthTests.java
+++ b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/mpjwt/MpJwtAuthTests.java
@@ -16,66 +16,16 @@
import static org.assertj.core.api.Assertions.assertThat;
-import java.util.Collection;
-
-import javax.ws.rs.client.ClientBuilder;
-
-import org.apache.aries.cdi.test.cases.SlimTestCase;
+import org.apache.aries.cdi.test.cases.JaxrsBaseTestCase;
import org.junit.After;
import org.junit.Before;
-import org.osgi.framework.ServiceObjects;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.http.runtime.HttpServiceRuntime;
-import org.osgi.service.jaxrs.runtime.JaxrsServiceRuntime;
-import org.osgi.service.jaxrs.runtime.JaxrsServiceRuntimeConstants;
-import org.osgi.util.tracker.ServiceTracker;
-public class MpJwtAuthTests extends SlimTestCase {
-
- String getEndpoint() {
- Object endpointsObj = jsrReference.getProperty(
- JaxrsServiceRuntimeConstants.JAX_RS_SERVICE_ENDPOINT);
-
- if (endpointsObj instanceof String) {
- return String.valueOf(endpointsObj);
- }
- else if (endpointsObj instanceof String[]) {
- return ((String[])endpointsObj)[0];
- }
- else if (endpointsObj instanceof Collection) {
- return String.valueOf(((Collection<?>)endpointsObj).iterator().next());
- }
-
- return null;
- }
+public class MpJwtAuthTests extends JaxrsBaseTestCase {
@Before
@Override
public void setUp() throws Exception {
- hsrTracker = new ServiceTracker<>(bundleContext, HttpServiceRuntime.class, null);
-
- hsrTracker.open();
-
- hsr = hsrTracker.waitForService(timeout);
-
- jsrTracker = new ServiceTracker<>(bundleContext, JaxrsServiceRuntime.class, null);
-
- jsrTracker.open();
-
- jsr = jsrTracker.waitForService(timeout);
-
- jsrReference = jsrTracker.getServiceReference();
-
- cbTracker = new ServiceTracker<>(bundleContext, ClientBuilder.class, null);
-
- cbTracker.open();
-
- cb = cbTracker.waitForService(timeout);
-
- cbSO = bundleContext.getServiceObjects(cbTracker.getServiceReference());
-
- assertThat(cb).isNotNull();
-
+ super.setUp();
cdiBundle = installBundle("tb23.jar");
int count = 100;
@@ -92,19 +42,7 @@
@Override
public void tearDown() throws Exception {
cdiBundle.uninstall();
-
- hsrTracker.close();
- jsrTracker.close();
- cbTracker.close();
+ super.tearDown();
}
- ClientBuilder cb;
- ServiceObjects<ClientBuilder> cbSO;
- ServiceTracker<ClientBuilder, ClientBuilder> cbTracker;
- HttpServiceRuntime hsr;
- ServiceTracker<HttpServiceRuntime, HttpServiceRuntime> hsrTracker = new ServiceTracker<>(bundleContext, HttpServiceRuntime.class, null);
- JaxrsServiceRuntime jsr;
- ServiceReference<JaxrsServiceRuntime> jsrReference;
- ServiceTracker<JaxrsServiceRuntime, JaxrsServiceRuntime> jsrTracker;
-
}
diff --git a/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb24/A.java b/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb24/A.java
new file mode 100644
index 0000000..b6c6cdb
--- /dev/null
+++ b/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb24/A.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed 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.cdi.test.tb24;
+
+import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+@Path("a")
+public class A {
+
+ @GET
+ @Produces(TEXT_PLAIN)
+ public String get() {
+ return "a";
+ }
+
+}
diff --git a/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb24/package-info.java b/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb24/package-info.java
new file mode 100644
index 0000000..737d907
--- /dev/null
+++ b/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb24/package-info.java
@@ -0,0 +1,20 @@
+/**
+ * Licensed 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.
+ */
+
+@Beans
+@RequireCDIExtension("aries.cdi.jaxrs")
+package org.apache.aries.cdi.test.tb24;
+
+import org.apache.aries.cdi.extra.RequireCDIExtension;
+import org.osgi.service.cdi.annotations.Beans;
diff --git a/cdi-itests/weld-itest.bndrun b/cdi-itests/weld-itest.bndrun
index 6d08c95..5278e0c 100644
--- a/cdi-itests/weld-itest.bndrun
+++ b/cdi-itests/weld-itest.bndrun
@@ -33,6 +33,7 @@
org.apache.aries.cdi.extension.mp-metrics;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.extension.servlet.common;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.extension.servlet.weld;version='[1.1.0,1.1.1)',\
+ org.apache.aries.cdi.extension.spi;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.extra;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.itests;version='[1.1.0,1.1.1)',\
org.apache.aries.cdi.spi;version='[1.1.0,1.1.1)',\
@@ -73,4 +74,5 @@
org.osgi.test.junit4;version='[1.0.0,1.0.1)',\
org.osgi.util.function;version='[1.1.0,1.1.1)',\
org.osgi.util.promise;version='[1.1.0,1.1.1)',\
- org.apache.felix.configurator;version='[1.0.10,1.0.11)'
+ org.apache.felix.configurator;version='[1.0.10,1.0.11)',\
+ org.apache.aries.cdi.extension.jaxrs;version='[1.1.0,1.1.1)'
diff --git a/pom.xml b/pom.xml
index 87b5d1e..ecfda34 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,8 +71,10 @@
<module>cdi-build-tools</module>
<module>cdi-extra</module>
<module>cdi-spi</module>
+ <module>cdi-extension-spi</module>
<module>cdi-extender</module>
<module>cdi-extension-el-jsp</module>
+ <module>cdi-extension-jaxrs</module>
<module>cdi-extension-jndi</module>
<module>cdi-extension-servlet-common</module>
<module>cdi-extension-servlet-owb</module>