cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CXF-7501) Cannot inject field in ContainerRequestFilter
Date Fri, 27 Oct 2017 15:44:00 GMT

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

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

johnament commented on a change in pull request #329: CXF-7501: Cannot inject field in ContainerRequestFilter
(and generally, into any providers registered using FeatureContext)
URL: https://github.com/apache/cxf/pull/329#discussion_r147445943
 
 

 ##########
 File path: integration/cdi/src/main/java/org/apache/cxf/cdi/CdiServerConfigurableFactory.java
 ##########
 @@ -0,0 +1,85 @@
+/**
+ * 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 javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanAttributes;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionTargetFactory;
+import javax.ws.rs.RuntimeType;
+import javax.ws.rs.core.Configurable;
+import javax.ws.rs.core.FeatureContext;
+
+import org.apache.cxf.jaxrs.impl.ConfigurableImpl;
+import org.apache.cxf.jaxrs.impl.ConfigurableImpl.Instantiator;
+import org.apache.cxf.jaxrs.provider.ServerConfigurableFactory;
+
+/** 
+ * Creates the instance of Configurable<?> suitable for CDI-managed runtime.
+ */
+public class CdiServerConfigurableFactory implements ServerConfigurableFactory {
+    private final BeanManager beanManager;
+    
+    CdiServerConfigurableFactory(final BeanManager beanManager) {
+        this.beanManager = beanManager;
+    }
+    
+    @Override
+    public Configurable<FeatureContext> create(FeatureContext context) {
+        return new CdiServerFeatureContextConfigurable(context, beanManager);
+    }
+    
+    /** 
+     * Instantiates the instance of the provider using CDI/BeanManager 
+     */
+    private static class CdiInstantiator implements Instantiator {
+        private final BeanManager beanManager;
+        
+        CdiInstantiator(final BeanManager beanManager) {
+            this.beanManager = beanManager;
+        }
+        
+        @Override
+        public <T> Object create(Class<T> cls) {
 
 Review comment:
   I see we have a create... should we also have a destroy?  Otherwise, in CDI, you run the
risk of having dependent scoped beans lying around.  I'm not sure if these are meant to be
per-request objects or global objects, but if they are per request and `@Dependent` scoped
then you'll want to destroy them.

----------------------------------------------------------------
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:
users@infra.apache.org


> Cannot inject field in ContainerRequestFilter
> ---------------------------------------------
>
>                 Key: CXF-7501
>                 URL: https://issues.apache.org/jira/browse/CXF-7501
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.1.10, 3.2.0
>         Environment: Linux Mint 64 bit, TomEE Plus 7.0.3, JavaEE 7 application using
MVC specification and reference implementation(Libs Attached)
>            Reporter: Jeyvison Nascimento
>            Assignee: Andriy Redko
>              Labels: cdi
>         Attachments: javax-mvc.jar, ozark.jar
>
>
> Hey folks.
> We found a weird behavior while running MVC specification(JSR 371) on TomEE witch CXF.
We have a *ContainerRequestFilter* defined called *JaxRsContextFilter* 
> {code:java}
> @PreMatching
> @Priority(0)
> public class JaxRsContextFilter implements ContainerRequestFilter {
>     @Inject
>     private JaxRsContextProducer jaxRsContextProducer;
>     @Context
>     private Configuration configuration;
>     @Context
>     private HttpServletRequest request;
>     @Context
>     private HttpServletResponse response;
>     public JaxRsContextFilter() {
>     }
>     public void filter(ContainerRequestContext requestContext) throws IOException {
>         this.jaxRsContextProducer.populate(this.configuration, this.request, this.response);
>     }
> }
> {code}
> You can see that we have a JaxRsContextProducer annotated to be injected as a field in
our object but when JAXRSUtils is called to run the the container filters it injects the fields
annotated as *@Context* , not the fields annotated with *@Inject*.
> {code:java}
>  for (ProviderInfo<ContainerRequestFilter> filter : containerFilters) {
>                 try {
>                     InjectionUtils.injectContexts(filter.getProvider(), filter, m);
>                     filter.getProvider().filter(context);
>                 } catch (IOException ex) {
>                     throw ExceptionUtils.toInternalServerErrorException(ex, null); 
>                 }
> {code}
> It causes our filter(*JaxRsContextFilter*) to throw a NullPointerException when filtering
the request because it uses the producer to perform some actions in  this operation.
> I believe this field should be injected as well, not only the *@Context* fields.



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

Mime
View raw message