cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cxf git commit: Fixed handling resource classes in CDI context by introducing dedicated resource provider implementation
Date Fri, 11 Nov 2016 02:22:13 GMT
Repository: cxf
Updated Branches:
  refs/heads/master d94cb4384 -> 3be9aac26


Fixed handling resource classes in CDI context by introducing dedicated resource provider
implementation


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/3be9aac2
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/3be9aac2
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/3be9aac2

Branch: refs/heads/master
Commit: 3be9aac26a003ef43995054da875ffd5fa5a2eb4
Parents: d94cb43
Author: reta <drreta@gmail.com>
Authored: Thu Nov 10 21:07:02 2016 -0500
Committer: reta <drreta@gmail.com>
Committed: Thu Nov 10 21:21:55 2016 -0500

----------------------------------------------------------------------
 .../org/apache/cxf/cdi/CdiResourceProvider.java | 51 ++++++++++++++++++++
 .../cxf/cdi/JAXRSCdiResourceExtension.java      |  8 ++-
 2 files changed, 58 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/3be9aac2/integration/cdi/src/main/java/org/apache/cxf/cdi/CdiResourceProvider.java
----------------------------------------------------------------------
diff --git a/integration/cdi/src/main/java/org/apache/cxf/cdi/CdiResourceProvider.java b/integration/cdi/src/main/java/org/apache/cxf/cdi/CdiResourceProvider.java
new file mode 100644
index 0000000..997cf40
--- /dev/null
+++ b/integration/cdi/src/main/java/org/apache/cxf/cdi/CdiResourceProvider.java
@@ -0,0 +1,51 @@
+/**
+ * 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 org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
+import org.apache.cxf.message.Message;
+
+public class CdiResourceProvider implements ResourceProvider {
+    private final Object instance;
+    private final Class<?> resourceClass;
+    
+    CdiResourceProvider(final Class<?> resourceClass, final Object instance) {
+        this.resourceClass = resourceClass;
+        this.instance = instance;
+    }
+    
+    @Override
+    public Object getInstance(Message m) {
+        return instance;
+    }
+
+    @Override
+    public void releaseInstance(Message m, Object o) {
+    }
+
+    @Override
+    public Class<?> getResourceClass() {
+        return resourceClass;
+    }
+
+    @Override
+    public boolean isSingleton() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/3be9aac2/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
----------------------------------------------------------------------
diff --git a/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
b/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
index 0a6e032..52ff3f8 100644
--- a/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
+++ b/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
@@ -172,9 +172,14 @@ public class JAXRSCdiResourceExtension implements Extension {
 
         final JAXRSServerFactoryBean instance = ResourceUtils.createApplication(application,
false, false, bus);
         final Map< Class< ? >, List< Object > > classified = classes2singletons(application,
beanManager);
-        instance.setServiceBeans(classified.get(Path.class));
+        
         instance.setProviders(classified.get(Provider.class));
         instance.getFeatures().addAll(CastUtils.cast(classified.get(Feature.class), Feature.class));
+        
+        for (final Object resource: classified.get(Path.class)) {
+            instance.setResourceProvider(resource.getClass(), 
+                new CdiResourceProvider(resource.getClass(), resource));
+        }
 
         return instance;
     }
@@ -201,6 +206,7 @@ public class JAXRSCdiResourceExtension implements Extension {
             classified.get(Provider.class).addAll(loadProviders(beanManager, classes));
             classified.get(Feature.class).addAll(loadFeatures(beanManager, classes));
         }
+        
         return classified;
     }
 


Mime
View raw message