cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6112] Adding ResourceContextProvider
Date Thu, 20 Nov 2014 18:05:16 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 4df8e2e90 -> 0f941edd3


[CXF-6112] Adding ResourceContextProvider


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

Branch: refs/heads/3.0.x-fixes
Commit: 0f941edd39a0f5e31298ba4757019fabd3044809
Parents: 4df8e2e
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Thu Nov 20 18:01:52 2014 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Thu Nov 20 18:04:45 2014 +0000

----------------------------------------------------------------------
 .../cxf/jaxrs/ext/ResourceContextProvider.java  | 23 ++++++++++++++++++++
 .../cxf/jaxrs/impl/ResourceContextImpl.java     | 11 ++++++++--
 2 files changed, 32 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/0f941edd/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ResourceContextProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ResourceContextProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ResourceContextProvider.java
new file mode 100644
index 0000000..f9337ff
--- /dev/null
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ResourceContextProvider.java
@@ -0,0 +1,23 @@
+/**
+ * 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.jaxrs.ext;
+
+public interface ResourceContextProvider {
+    <T> T getResource(Class<T> cls);
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/0f941edd/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
index 60b70aa..0a74deb 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
@@ -20,6 +20,7 @@ package org.apache.cxf.jaxrs.impl;
 
 import javax.ws.rs.container.ResourceContext;
 
+import org.apache.cxf.jaxrs.ext.ResourceContextProvider;
 import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
@@ -27,7 +28,7 @@ import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
 import org.apache.cxf.message.Message;
 
 public class ResourceContextImpl implements ResourceContext {
-
+    private static final String CONTEXT_PROVIDER_PROP = "org.apache.cxf.jaxrs.resource.context.provider";
     private ClassResourceInfo cri;
     private Class<?> subClass;
     private Message m;
@@ -39,7 +40,13 @@ public class ResourceContextImpl implements ResourceContext {
     
     @Override
     public <T> T getResource(Class<T> cls) {
-        T resource = cls.cast(new PerRequestResourceProvider(cls).getInstance(m));
+        T resource = null;
+        Object propValue = m.getContextualProperty(CONTEXT_PROVIDER_PROP);
+        if (propValue instanceof ResourceContextProvider) {
+            resource = ((ResourceContextProvider)propValue).getResource(cls);
+        } else { 
+            resource = cls.cast(new PerRequestResourceProvider(cls).getInstance(m));
+        }
         return doInitResource(cls, resource);
     }
     


Mime
View raw message