Repository: incubator-juneau Updated Branches: refs/heads/master b96f60147 -> e8803a1b7
RestResourceResolvers should be inherited by child resources. Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/e8803a1b Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/e8803a1b Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/e8803a1b Branch: refs/heads/master Commit: e8803a1b755b154b4cc2d33fa4569413a70a9cf1 Parents: b96f601 Author: JamesBognar <[email protected]> Authored: Thu Jul 13 23:04:32 2017 -0400 Committer: JamesBognar <[email protected]> Committed: Thu Jul 13 23:04:32 2017 -0400 ---------------------------------------------------------------------- juneau-core/src/main/javadoc/overview.html | 3 +++ .../java/org/apache/juneau/rest/RestConfig.java | 1 + .../org/apache/juneau/rest/RestContext.java | 23 ++++++++++++++++++-- .../juneau/rest/annotation/RestResource.java | 3 +++ 4 files changed, 28 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e8803a1b/juneau-core/src/main/javadoc/overview.html ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/javadoc/overview.html b/juneau-core/src/main/javadoc/overview.html index eb21b94..d42b630 100644 --- a/juneau-core/src/main/javadoc/overview.html +++ b/juneau-core/src/main/javadoc/overview.html @@ -6902,6 +6902,9 @@ <br>Exposes an abstract method {@link org.apache.juneau.rest.widget.MenuItemWidget#getContent()} that can return raw HTML via readers or char-sequences, or any other object (such as HTML5 beans) that will get converted to HTML using {@link org.apache.juneau.html.HtmlSerializer#DEFAULT}. + <li> + {@link org.apache.juneau.rest.RestResourceResolver} instances are now inherited from parent resources to child resources + unless explicitly overridden at the child level. </ul> </div> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e8803a1b/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java index 0f3be32..0a6c44e 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java @@ -140,6 +140,7 @@ public class RestConfig implements ServletConfig { this.inner = config; this.resourceClass = resourceClass; this.parentContext = parentContext; + this.resourceResolver = parentContext == null ? RestResourceResolver.class : parentContext.getResourceResolver(); try { ConfigFileBuilder cfb = new ConfigFileBuilder(); http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e8803a1b/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java index 139569a..d37aaa3 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java @@ -293,6 +293,7 @@ public final class RestContext extends Context { private final RestInfoProvider infoProvider; private final RestException initException; private final RestContext parentContext; + private final RestResourceResolver resourceResolver; // In-memory cache of images and stylesheets in the org.apache.juneau.rest.htdocs package. private final Map<String,StreamResource> staticFilesCache = new ConcurrentHashMap<String,StreamResource>(); @@ -454,7 +455,7 @@ public final class RestContext extends Context { this.callRouters = Collections.unmodifiableMap(_callRouters); // Initialize our child resources. - RestResourceResolver rrr = resolve(RestResourceResolver.class, config.resourceResolver); + resourceResolver = resolve(RestResourceResolver.class, config.resourceResolver); for (Object o : config.childResources) { String path = null; Object r = null; @@ -477,7 +478,7 @@ public final class RestContext extends Context { if (o instanceof Class) { Class<?> oc = (Class<?>)o; childConfig = new RestConfig(config.inner, oc, this); - r = rrr.resolve(oc, childConfig); + r = resourceResolver.resolve(oc, childConfig); } else { r = o; childConfig = new RestConfig(config.inner, o.getClass(), this); @@ -692,6 +693,24 @@ public final class RestContext extends Context { } /** + * Returns the resource resolver associated with this context. + * + * <p> + * The resource resolver is used for instantiating child resource classes. + * + * <p> + * Unless overridden via the {@link RestResource#resourceResolver()} annotation or the {@link RestConfig#setResourceResolver(Class)} + * method, this value is always inherited from parent to child. + * This allows a single resource resolver to be passed in to the top-level servlet to handle instantiation of all + * child resources. + * + * @return The resource resolver associated with this context. + */ + protected RestResourceResolver getResourceResolver() { + return resourceResolver; + } + + /** * Returns the variable resolver for this servlet. * * <p> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e8803a1b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java index d5fa611..b111260 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java @@ -627,6 +627,9 @@ public @interface RestResource { * Subclasses can be used to provide customized resolution of REST resource class instances. * * <p> + * If not specified on a child resource, the resource resolver is inherited from the parent resource context. + * + * <p> * The programmatic equivalent to this annotation are the {@link RestConfig#setResourceResolver(Class)}/ * {@link RestConfig#setResourceResolver(RestResourceResolver)} methods. */
