You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ro...@apache.org on 2019/11/25 18:43:33 UTC
[aries-cdi] 14/27: these extensions are for weld for the moment
This is an automated email from the ASF dual-hosted git repository.
rotty3000 pushed a commit to branch rotty3000/cdi-spi
in repository https://gitbox.apache.org/repos/asf/aries-cdi.git
commit bbad287153ea3033e728d4548c2cd79a4c2b4d87
Author: Raymond Augé <ro...@apache.org>
AuthorDate: Fri Nov 22 16:48:27 2019 -0500
these extensions are for weld for the moment
Signed-off-by: Raymond Augé <ro...@apache.org>
---
cdi-extension-el-jsp/pom.xml | 1 +
cdi-extension-http/pom.xml | 1 +
.../aries/cdi/extension/http/HttpExtension.java | 137 ++++++---------------
3 files changed, 43 insertions(+), 96 deletions(-)
diff --git a/cdi-extension-el-jsp/pom.xml b/cdi-extension-el-jsp/pom.xml
index 16acbd3..5b5c252 100644
--- a/cdi-extension-el-jsp/pom.xml
+++ b/cdi-extension-el-jsp/pom.xml
@@ -91,6 +91,7 @@
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-osgi-bundle</artifactId>
+ <version>${weld.version}</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
diff --git a/cdi-extension-http/pom.xml b/cdi-extension-http/pom.xml
index b1a6a1c..51d3da0 100644
--- a/cdi-extension-http/pom.xml
+++ b/cdi-extension-http/pom.xml
@@ -81,6 +81,7 @@
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-osgi-bundle</artifactId>
+ <version>${weld.version}</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
diff --git a/cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/HttpExtension.java b/cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/HttpExtension.java
index 7aed15f..5b0c55d 100644
--- a/cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/HttpExtension.java
+++ b/cdi-extension-http/src/main/java/org/apache/aries/cdi/extension/http/HttpExtension.java
@@ -24,7 +24,6 @@ import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHIT
import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER;
import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Dictionary;
@@ -39,9 +38,6 @@ import javax.annotation.Priority;
import javax.enterprise.event.Observes;
import javax.enterprise.event.ObservesAsync;
import javax.enterprise.inject.spi.AfterDeploymentValidation;
-import javax.enterprise.inject.spi.AnnotatedConstructor;
-import javax.enterprise.inject.spi.AnnotatedField;
-import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
@@ -96,42 +92,44 @@ public class HttpExtension implements Extension {
WebFilter webFilter = annotatedType.getAnnotation(WebFilter.class);
- final Set<Annotation> annotations = new HashSet<>(annotatedType.getAnnotations());
+ final Set<Annotation> annotationsToAdd = new HashSet<>();
if (!annotatedType.isAnnotationPresent(Service.class)) {
- annotations.add(Service.Literal.of(new Class[] {Filter.class}));
+ annotationsToAdd.add(Service.Literal.of(new Class[] {Filter.class}));
}
if(!annotatedType.isAnnotationPresent(HttpWhiteboardContextSelect.class)) {
- annotations.add(HttpWhiteboardContextSelect.Literal.of(getSelectedContext()));
+ annotationsToAdd.add(HttpWhiteboardContextSelect.Literal.of(getSelectedContext()));
}
if (!webFilter.description().isEmpty()) {
- annotations.add(ServiceDescription.Literal.of(webFilter.description()));
+ annotationsToAdd.add(ServiceDescription.Literal.of(webFilter.description()));
}
if (!webFilter.filterName().isEmpty()) {
- annotations.add(HttpWhiteboardFilterName.Literal.of(webFilter.filterName()));
+ annotationsToAdd.add(HttpWhiteboardFilterName.Literal.of(webFilter.filterName()));
}
if (webFilter.servletNames().length > 0) {
- annotations.add(HttpWhiteboardFilterServlet.Literal.of(webFilter.servletNames()));
+ annotationsToAdd.add(HttpWhiteboardFilterServlet.Literal.of(webFilter.servletNames()));
}
if (webFilter.value().length > 0) {
- annotations.add(HttpWhiteboardFilterPattern.Literal.of(webFilter.value()));
+ annotationsToAdd.add(HttpWhiteboardFilterPattern.Literal.of(webFilter.value()));
}
else if (webFilter.urlPatterns().length > 0) {
- annotations.add(HttpWhiteboardFilterPattern.Literal.of(webFilter.urlPatterns()));
+ annotationsToAdd.add(HttpWhiteboardFilterPattern.Literal.of(webFilter.urlPatterns()));
}
if (webFilter.dispatcherTypes().length > 0) {
- annotations.add(HttpWhiteboardFilterDispatcher.Literal.of(webFilter.dispatcherTypes()));
+ annotationsToAdd.add(HttpWhiteboardFilterDispatcher.Literal.of(webFilter.dispatcherTypes()));
}
- annotations.add(HttpWhiteboardFilterAsyncSupported.Literal.of(webFilter.asyncSupported()));
+ annotationsToAdd.add(HttpWhiteboardFilterAsyncSupported.Literal.of(webFilter.asyncSupported()));
- pat.setAnnotatedType(new WebAnnotated<>(annotatedType, annotations));
+ if (!annotationsToAdd.isEmpty()) {
+ annotationsToAdd.forEach(pat.configureAnnotatedType()::add);
+ }
}
<X> void processWebListener(@Observes @WithAnnotations(WebListener.class) ProcessAnnotatedType<X> pat) {
@@ -139,7 +137,7 @@ public class HttpExtension implements Extension {
WebListener webListener = annotatedType.getAnnotation(WebListener.class);
- final Set<Annotation> annotations = new HashSet<>(annotatedType.getAnnotations());
+ final Set<Annotation> annotationsToAdd = new HashSet<>();
if (!annotatedType.isAnnotationPresent(Service.class)) {
List<Class<?>> listenerTypes = new ArrayList<>();
@@ -168,20 +166,22 @@ public class HttpExtension implements Extension {
listenerTypes.add(javax.servlet.http.HttpSessionIdListener.class);
}
- annotations.add(Service.Literal.of(listenerTypes.toArray(new Class<?>[0])));
+ annotationsToAdd.add(Service.Literal.of(listenerTypes.toArray(new Class<?>[0])));
}
if(!annotatedType.isAnnotationPresent(HttpWhiteboardContextSelect.class)) {
- annotations.add(HttpWhiteboardContextSelect.Literal.of(getSelectedContext()));
+ annotationsToAdd.add(HttpWhiteboardContextSelect.Literal.of(getSelectedContext()));
}
- annotations.add(HttpWhiteboardListener.Literal.INSTANCE);
+ annotationsToAdd.add(HttpWhiteboardListener.Literal.INSTANCE);
if (!webListener.value().isEmpty()) {
- annotations.add(ServiceDescription.Literal.of(webListener.value()));
+ annotationsToAdd.add(ServiceDescription.Literal.of(webListener.value()));
}
- pat.setAnnotatedType(new WebAnnotated<>(annotatedType, annotations));
+ if (!annotationsToAdd.isEmpty()) {
+ annotationsToAdd.forEach(pat.configureAnnotatedType()::add);
+ }
}
<X> void processWebServlet(@Observes @WithAnnotations(WebServlet.class) ProcessAnnotatedType<X> pat) {
@@ -189,46 +189,48 @@ public class HttpExtension implements Extension {
WebServlet webServlet = annotatedType.getAnnotation(WebServlet.class);
- final Set<Annotation> annotations = new HashSet<>(annotatedType.getAnnotations());
+ final Set<Annotation> annotationsToAdd = new HashSet<>();
if (!annotatedType.isAnnotationPresent(Service.class)) {
- annotations.add(Service.Literal.of(new Class[] {Servlet.class}));
+ annotationsToAdd.add(Service.Literal.of(new Class[] {Servlet.class}));
}
if(!annotatedType.isAnnotationPresent(HttpWhiteboardContextSelect.class)) {
- annotations.add(HttpWhiteboardContextSelect.Literal.of(getSelectedContext()));
+ annotationsToAdd.add(HttpWhiteboardContextSelect.Literal.of(getSelectedContext()));
}
if (!webServlet.name().isEmpty()) {
- annotations.add(HttpWhiteboardServletName.Literal.of(webServlet.name()));
+ annotationsToAdd.add(HttpWhiteboardServletName.Literal.of(webServlet.name()));
}
if (webServlet.value().length > 0) {
- annotations.add(HttpWhiteboardServletPattern.Literal.of(webServlet.value()));
+ annotationsToAdd.add(HttpWhiteboardServletPattern.Literal.of(webServlet.value()));
}
else if (webServlet.urlPatterns().length > 0) {
- annotations.add(HttpWhiteboardServletPattern.Literal.of(webServlet.urlPatterns()));
+ annotationsToAdd.add(HttpWhiteboardServletPattern.Literal.of(webServlet.urlPatterns()));
}
- annotations.add(ServiceRanking.Literal.of(webServlet.loadOnStartup()));
+ annotationsToAdd.add(ServiceRanking.Literal.of(webServlet.loadOnStartup()));
// TODO Howto: INIT PARAMS ???
- annotations.add(HttpWhiteboardServletAsyncSupported.Literal.of(webServlet.asyncSupported()));
+ annotationsToAdd.add(HttpWhiteboardServletAsyncSupported.Literal.of(webServlet.asyncSupported()));
if (!webServlet.description().isEmpty()) {
- annotations.add(ServiceDescription.Literal.of(webServlet.description()));
+ annotationsToAdd.add(ServiceDescription.Literal.of(webServlet.description()));
}
MultipartConfig multipartConfig = annotatedType.getAnnotation(MultipartConfig.class);
if (multipartConfig != null) {
- annotations.add(HttpWhiteboardServletMultipart.Literal.of(true, multipartConfig.fileSizeThreshold(), multipartConfig.location(), multipartConfig.maxFileSize(), multipartConfig.maxRequestSize()));
+ annotationsToAdd.add(HttpWhiteboardServletMultipart.Literal.of(true, multipartConfig.fileSizeThreshold(), multipartConfig.location(), multipartConfig.maxFileSize(), multipartConfig.maxRequestSize()));
}
// TODO HowTo: ServletSecurity ???
- pat.setAnnotatedType(new WebAnnotated<>(annotatedType, annotations));
+ if (!annotationsToAdd.isEmpty()) {
+ annotationsToAdd.forEach(pat.configureAnnotatedType()::add);
+ }
}
void afterDeploymentValidation(
@@ -241,7 +243,7 @@ public class HttpExtension implements Extension {
void ready(@ObservesAsync Ready ready, BeanManager beanManager) {
Dictionary<String, Object> properties = new Hashtable<>();
- properties.put(SERVICE_DESCRIPTION, "Aries CDI - HTTP Portable Extension");
+ properties.put(SERVICE_DESCRIPTION, "Aries CDI - HTTP Portable Extension for Weld");
properties.put(SERVICE_VENDOR, "Apache Software Foundation");
properties.put(HTTP_WHITEBOARD_CONTEXT_SELECT, getSelectedContext());
properties.put(HTTP_WHITEBOARD_LISTENER, Boolean.TRUE.toString());
@@ -259,7 +261,12 @@ public class HttpExtension implements Extension {
void beforeShutdown(@Observes BeforeShutdown bs) {
if (_listenerRegistration != null && !destroyed.get()) {
- _listenerRegistration.unregister();
+ try {
+ _listenerRegistration.unregister();
+ }
+ catch (IllegalStateException ise) {
+ // the service was already unregistered.
+ }
}
}
@@ -371,66 +378,4 @@ public class HttpExtension implements Extension {
}
- private class WebAnnotated<X> implements AnnotatedType<X> {
-
- private final AnnotatedType<X> annotatedType;
- private final Set<Annotation> annotations;
-
- public WebAnnotated(AnnotatedType<X> annotatedType, Set<Annotation> annotations) {
- this.annotatedType = annotatedType;
- this.annotations = annotations;
- }
-
- @Override
- public Type getBaseType() {
- return annotatedType.getBaseType();
- }
-
- @Override
- public Set<Type> getTypeClosure() {
- return annotatedType.getTypeClosure();
- }
-
- @Override
- public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
- return annotations.stream().filter(
- ann -> annotationType.isAssignableFrom(ann.annotationType())
- ).map(
- ann -> annotationType.cast(ann)
- ).findFirst().orElse(null);
- }
-
- @Override
- public Set<Annotation> getAnnotations() {
- return annotations;
- }
-
- @Override
- public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
- return annotations.stream().anyMatch(
- ann -> annotationType.isAssignableFrom(ann.annotationType())
- );
- }
-
- @Override
- public Class<X> getJavaClass() {
- return annotatedType.getJavaClass();
- }
-
- @Override
- public Set<AnnotatedConstructor<X>> getConstructors() {
- return annotatedType.getConstructors();
- }
-
- @Override
- public Set<AnnotatedMethod<? super X>> getMethods() {
- return annotatedType.getMethods();
- }
-
- @Override
- public Set<AnnotatedField<? super X>> getFields() {
- return annotatedType.getFields();
- }
- }
-
}