Repository: cxf Updated Branches: refs/heads/master f8f07890a -> 5520b06e2
[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/5520b06e Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/5520b06e Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/5520b06e Branch: refs/heads/master Commit: 5520b06e2e348b5c5fc6707aa8f64777e6100e86 Parents: f8f0789 Author: Sergey Beryozkin <[email protected]> Authored: Thu Nov 20 18:01:52 2014 +0000 Committer: Sergey Beryozkin <[email protected]> Committed: Thu Nov 20 18:01:52 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/5520b06e/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/5520b06e/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); }
