This is an automated email from the ASF dual-hosted git repository.
sergeyb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push:
new efa3c8a [CXF-7593] Supporting the injection of Application into
Feature
efa3c8a is described below
commit efa3c8a93e85278a2f6eca5740b1b5aca6dd8f15
Author: Sergey Beryozkin <[email protected]>
AuthorDate: Tue Dec 19 17:16:33 2017 +0000
[CXF-7593] Supporting the injection of Application into Feature
---
.../cxf/jaxrs/provider/ServerProviderFactory.java | 34 +++++++++++++++++++++-
.../org/apache/cxf/systest/jaxrs/BookServer20.java | 8 +++++
2 files changed, 41 insertions(+), 1 deletion(-)
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 2e85900..ee12a1d 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;
@@ -205,7 +207,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()) {
@@ -273,6 +277,34 @@ public final class ServerProviderFactory extends
ProviderFactory {
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 21b2fa6..d1b5148 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
['"[email protected]" <[email protected]>'].