[ 
https://issues.apache.org/jira/browse/CXF-7571?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16275978#comment-16275978
 ] 

ASF GitHub Bot commented on CXF-7571:
-------------------------------------

johnament commented on a change in pull request #351: [CXF-7571] Adding support 
for CDI injection of @Context objects.
URL: https://github.com/apache/cxf/pull/351#discussion_r154527715
 
 

 ##########
 File path: 
integration/cdi/src/main/java/org/apache/cxf/cdi/DelegateContextAnnotatedType.java
 ##########
 @@ -0,0 +1,182 @@
+/**
+ * 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.cxf.cdi;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import static java.util.stream.Collectors.toSet;
+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.util.AnnotationLiteral;
+import javax.inject.Inject;
+import javax.ws.rs.core.Context;
+
+final class DelegateContextAnnotatedType<X> implements AnnotatedType<X> {
+    private static final Inject INJECT = new InjectLiteral();
+    private static final ContextResolved CONTEXT_RESOLVED = 
ContextResolved.LITERAL;
+    private final AnnotatedType<X> original;
+    private final Set<AnnotatedField<? super X>> replacedFields;
+
+    DelegateContextAnnotatedType(AnnotatedType<X> original) {
+        this.original = original;
+        this.replacedFields = replaceFields(original);
+    }
+
+    private Set<AnnotatedField<? super X>> replaceFields(AnnotatedType<? super 
X> delegate) {
+        return delegate.getFields().stream().map(this::wrap).collect(toSet());
+    }
+
+    Set<Type> getContextFieldTypes() {
+        return replacedFields.stream()
+                .filter(f -> f.isAnnotationPresent(Context.class) || 
f.isAnnotationPresent(ContextResolved.class))
 
 Review comment:
   Just to make sure the issue is understood, not sure if I'm not clear.  I'm 
registering a CDI bean per `@Context` object that can be injected.  I'm 
discovering them two ways:
   
   - Any `@Context` injection point
   - Any of the standard context objects, as defined by 
`InjectionUtils.STANDARD_CONTEXT_CLASSES`.
   
   The latter is what enables `@Inject UriInfo` to work properly.  Without it, 
the injection point would not be satisfied.  The problem is that this works 
fine for the standard context classes, but not custom objects (e.g. 
`TracerContext`).  The closest I can do is if they have an injection point 
`@Inject @ContextResolved TracerContext` then I can still resolve that 
injection point, but I can't resolve `@Inject TracerContext` since I have no 
idea its supposed to be from the `@Context`.  
   
   If we changed the behavior of these custom context objects so that they were 
added to a map in `InjectionUtils`, then I could resolve those classes as well 
and remove that extra check.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


>  Revamp of the CXF injection implementation
> -------------------------------------------
>
>                 Key: CXF-7571
>                 URL: https://issues.apache.org/jira/browse/CXF-7571
>             Project: CXF
>          Issue Type: Improvement
>            Reporter: Andriy Redko
>            Assignee: John D. Ament
>
> As more deep integration with CDI revealed, there are complexities in 
> bringing together {{@Context}}- and {{@Inject}}-based injections. 
> Encapsulating CXF injection implementation and than delegating the hard work 
> to appropriate strategy (CDI, Spring, ...) would be the right solution to 
> address the problem at its roots.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to