You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2017/12/19 17:20:53 UTC
[cxf] branch 3.1.x-fixes updated: [CXF-7593] Supporting the
injection of Application into Feature
This is an automated email from the ASF dual-hosted git repository.
sergeyb pushed a commit to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.1.x-fixes by this push:
new d258f05 [CXF-7593] Supporting the injection of Application into Feature
d258f05 is described below
commit d258f05255f000cc1473e4a7261e4ef9e3ac0375
Author: Sergey Beryozkin <sb...@gmail.com>
AuthorDate: Tue Dec 19 17:16:33 2017 +0000
[CXF-7593] Supporting the injection of Application into Feature
---
.../cxf/jaxrs/provider/ServerProviderFactory.java | 36 ++++++++++++++++++++--
.../org/apache/cxf/systest/jaxrs/BookServer20.java | 8 +++++
2 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
index ba53f1b..bb57122 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
@@ -38,6 +38,7 @@ import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.container.DynamicFeature;
import javax.ws.rs.container.PreMatching;
+import javax.ws.rs.core.Application;
import javax.ws.rs.core.Configurable;
import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.Feature;
@@ -57,6 +58,7 @@ import org.apache.cxf.jaxrs.impl.RequestPreprocessor;
import org.apache.cxf.jaxrs.impl.ResourceInfoImpl;
import org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper;
import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
import org.apache.cxf.jaxrs.model.ApplicationInfo;
import org.apache.cxf.jaxrs.model.BeanParamInfo;
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
@@ -203,7 +205,9 @@ public final class ServerProviderFactory extends ProviderFactory {
for (Object p : providers) {
if (p instanceof Feature) {
FeatureContext featureContext = createServerFeatureContext();
- ((Feature)p).configure(featureContext);
+ Feature feature = (Feature)p;
+ injectApplicationIntoFeature(feature);
+ feature.configure(featureContext);
Configuration cfg = featureContext.getConfiguration();
for (Object featureProvider : cfg.getInstances()) {
@@ -270,7 +274,35 @@ public final class ServerProviderFactory extends ProviderFactory {
postMatchContainerRequestFilters.values(), preMatchContainerRequestFilters,
containerResponseFilters.values());
}
-
+
+ protected void injectApplicationIntoFeature(Feature feature) {
+ if (application != null) {
+ AbstractResourceInfo info = new AbstractResourceInfo(feature.getClass(),
+ ClassHelper.getRealClass(feature),
+ true,
+ true,
+ getBus()) {
+ @Override
+ public boolean isSingleton() {
+ return false;
+ }
+ };
+ Method contextMethod = info.getContextMethods().get(Application.class);
+ if (contextMethod != null) {
+ InjectionUtils.injectThroughMethod(feature, contextMethod, application.getProvider());
+ return;
+ }
+ for (Field contextField : info.getContextFields()) {
+ if (Application.class == contextField.getType()) {
+ InjectionUtils.injectContextField(info, contextField, feature, application.getProvider());
+ break;
+ }
+ }
+
+ }
+
+ }
+
@Override
protected void injectContextProxiesIntoProvider(ProviderInfo<?> pi) {
injectContextProxiesIntoProvider(pi, application == null ? null : application.getProvider());
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
index 717ff6e..5ce099f 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
@@ -48,6 +48,7 @@ import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.container.DynamicFeature;
import javax.ws.rs.container.PreMatching;
import javax.ws.rs.container.ResourceInfo;
+import javax.ws.rs.core.Application;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Feature;
import javax.ws.rs.core.FeatureContext;
@@ -101,6 +102,7 @@ public class BookServer20 extends AbstractBusTestServerBase {
providers.add(new ServerTestFeature());
providers.add(new JacksonJaxbJsonProvider());
providers.add(new IOExceptionMapper());
+ sf.setApplication(new Application());
sf.setProviders(providers);
sf.setResourceProvider(BookStore.class,
new SingletonResourceProvider(new BookStore(), true));
@@ -521,8 +523,14 @@ public class BookServer20 extends AbstractBusTestServerBase {
}
private static class ServerTestFeature implements Feature {
+ @Context
+ private Application app;
+
@Override
public boolean configure(FeatureContext context) {
+ if (app == null) {
+ throw new RuntimeException();
+ }
context.register(new GenericHandlerWriter());
return true;
}
--
To stop receiving notification emails like this one, please contact
['"commits@cxf.apache.org" <co...@cxf.apache.org>'].