This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new 3e0472c  REST refactoring.
3e0472c is described below

commit 3e0472c5f32922ce74e2cf2bdf9c30f545b31480
Author: JamesBognar <[email protected]>
AuthorDate: Tue Jan 12 18:57:01 2021 -0500

    REST refactoring.
---
 .../org/apache/juneau/cp/BeanFactory_Test.java     | 52 ++++++------
 .../java/org/apache/juneau/cp/BeanFactory.java     | 25 +++++-
 .../java/org/apache/juneau/rest/RestContext.java   | 93 ++++++++++++----------
 .../org/apache/juneau/rest/RestContextBuilder.java |  2 +-
 .../org/apache/juneau/rest/RestMethodContext.java  | 70 +++++++++-------
 5 files changed, 143 insertions(+), 99 deletions(-)

diff --git 
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/cp/BeanFactory_Test.java
 
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/cp/BeanFactory_Test.java
index 4368671..3e09892 100644
--- 
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/cp/BeanFactory_Test.java
+++ 
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/cp/BeanFactory_Test.java
@@ -355,32 +355,32 @@ public class BeanFactory_Test {
                BeanFactory bf = new BeanFactory();
                E1 x = new E1();
 
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createA0")).doesNotExist();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createA1")).exists();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createA2")).doesNotExist();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createA3")).doesNotExist();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createA4")).doesNotExist();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createA5")).doesNotExist();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createA6")).doesNotExist();
-               assertThrown(()->bf.createBeanViaMethod(E.class, x, 
"createA7")).contains("foo");
-
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createB0")).doesNotExist();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createB1")).exists();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createB2")).doesNotExist();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createB3")).doesNotExist();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createB4")).doesNotExist();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createB5")).doesNotExist();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createB6")).doesNotExist();
-               assertThrown(()->bf.createBeanViaMethod(E.class, x, 
"createB7")).contains("foo");
-
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createC1")).doesNotExist();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createC2")).doesNotExist();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createC3")).exists();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createC3").a).doesNotExist();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createA0", 
null)).doesNotExist();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createA1", 
null)).exists();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createA2", 
null)).doesNotExist();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createA3", 
null)).doesNotExist();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createA4", 
null)).doesNotExist();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createA5", 
null)).doesNotExist();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createA6", 
null)).doesNotExist();
+               assertThrown(()->bf.createBeanViaMethod(E.class, x, "createA7", 
null)).contains("foo");
+
+               assertObject(bf.createBeanViaMethod(E.class, x, "createB0", 
null)).doesNotExist();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createB1", 
null)).exists();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createB2", 
null)).doesNotExist();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createB3", 
null)).doesNotExist();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createB4", 
null)).doesNotExist();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createB5", 
null)).doesNotExist();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createB6", 
null)).doesNotExist();
+               assertThrown(()->bf.createBeanViaMethod(E.class, x, "createB7", 
null)).contains("foo");
+
+               assertObject(bf.createBeanViaMethod(E.class, x, "createC1", 
null)).doesNotExist();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createC2", 
null)).doesNotExist();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createC3", 
null)).exists();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createC3", 
null).a).doesNotExist();
                bf.addBean(A.class, new A());
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createC1")).exists();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createC2")).exists();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createC3")).exists();
-               assertObject(bf.createBeanViaMethod(E.class, x, 
"createC3").a).exists();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createC1", 
null)).exists();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createC2", 
null)).exists();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createC3", 
null)).exists();
+               assertObject(bf.createBeanViaMethod(E.class, x, "createC3", 
null).a).exists();
        }
 }
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/BeanFactory.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/BeanFactory.java
index fc1964f..247ee46 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/BeanFactory.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/BeanFactory.java
@@ -41,6 +41,26 @@ public class BeanFactory {
        private final Optional<Object> outer;
 
        /**
+        * Static creator.
+        * 
+        * @return A new {@link BeanFactory} object.
+        */
+       public static BeanFactory of() {
+               return new BeanFactory();
+       }
+
+       /**
+        * Static creator.
+        * 
+        * @param parent Parent bean factory.  Can be <jk>null</jk> if this is 
the root resource.
+        * @param outer Outer bean context to use when instantiating local 
classes.  Can be <jk>null</jk>.
+        * @return A new {@link BeanFactory} object.
+        */
+       public static BeanFactory of(BeanFactory parent, Object outer) {
+               return new BeanFactory(parent, outer);
+       }
+
+       /**
         * Default constructor.
         */
        public BeanFactory() {
@@ -202,11 +222,12 @@ public class BeanFactory {
         * @param c The bean type to create.
         * @param resource The object where the method is defined.
         * @param methodName The method name on the object to call.
+        * @param def The default value to return if method doesn't exist.
         * @param requiredParams The parameter types that must be present on 
the method.
         * @return A newly-created bean or <jk>null</jk> if method not found or 
it returns <jk>null</jk>.
         * @throws ExecutableException If bean could not be created.
         */
-       public <T> T createBeanViaMethod(Class<T> c, Object resource, String 
methodName, Class<?>...requiredParams) throws ExecutableException {
+       public <T> T createBeanViaMethod(Class<T> c, Object resource, String 
methodName, T def, Class<?>...requiredParams) throws ExecutableException {
                ClassInfo ci = ClassInfo.of(resource);
                for (MethodInfo m : ci.getPublicMethods()) {
                        if (m.isAll(NOT_DEPRECATED) && m.hasReturnType(c) && 
m.getSimpleName().equals(methodName) && (!m.hasAnnotation(BeanIgnore.class))) {
@@ -215,7 +236,7 @@ public class BeanFactory {
                                        return m.invoke(resource, 
getParams(m.getParamTypes()));
                        }
                }
-               return null;
+               return def;
        }
 
        /**
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
index 8d46870..4d2936f 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -3696,13 +3696,14 @@ public class RestContext extends BeanContext {
                if (x == null)
                        x = getInstanceProperty(REST_fileFinder, 
FileFinder.class, null, beanFactory);
                if (x == null)
-                       x = beanFactory.createBeanViaMethod(FileFinder.class, 
resource, "createFileFinder");
-               if (x == null)
                        x = beanFactory.getBean(FileFinder.class).orElse(null);
                if (x == null)
                        x = getInstanceProperty(REST_fileFinderDefault, 
FileFinder.class, null, beanFactory);
                if (x == null)
                        x = new BasicFileFinder(this);
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(FileFinder.class, x)
+                       .createBeanViaMethod(FileFinder.class, resource, 
"createFileFinder", x);
                return x;
        }
 
@@ -3742,11 +3743,12 @@ public class RestContext extends BeanContext {
                if (x == null)
                        x = getInstanceProperty(REST_infoProvider, 
RestInfoProvider.class, null, beanFactory);
                if (x == null)
-                       x = 
beanFactory.createBeanViaMethod(RestInfoProvider.class, resource, 
"createInfoProvider");
-               if (x == null)
                        x = 
beanFactory.getBean(RestInfoProvider.class).orElse(null);
                if (x == null)
                        x = new BasicRestInfoProvider(this);
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(RestInfoProvider.class, x)
+                       .createBeanViaMethod(RestInfoProvider.class, resource, 
"createInfoProvider", x);
                return x;
        }
 
@@ -3788,13 +3790,14 @@ public class RestContext extends BeanContext {
                if (x == null)
                        x = getInstanceProperty(REST_staticFiles, 
StaticFiles.class, null, beanFactory);
                if (x == null)
-                       x = beanFactory.createBeanViaMethod(StaticFiles.class, 
resource, "createStaticFiles");
-               if (x == null)
                        x = beanFactory.getBean(StaticFiles.class).orElse(null);
                if (x == null)
                        x = getInstanceProperty(REST_staticFilesDefault, 
StaticFiles.class, null, beanFactory);
                if (x == null)
                        x = new BasicStaticFiles(this);
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(StaticFiles.class, x)
+                       .createBeanViaMethod(StaticFiles.class, resource, 
"createStaticFiles", x);
                return x;
        }
 
@@ -3836,13 +3839,14 @@ public class RestContext extends BeanContext {
                if (x == null)
                        x = getInstanceProperty(REST_callLogger, 
RestLogger.class, null, beanFactory);
                if (x == null)
-                       x = beanFactory.createBeanViaMethod(RestLogger.class, 
resource, "createCallLogger");
-               if (x == null)
                        x = beanFactory.getBean(RestLogger.class).orElse(null);
                if (x == null)
                        x = getInstanceProperty(REST_callLoggerDefault, 
RestLogger.class, null, beanFactory);
                if (x == null)
                        x = new BasicRestLogger(this);
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(RestLogger.class, x)
+                       .createBeanViaMethod(RestLogger.class, resource, 
"createCallLogger", x);
                return x;
        }
 
@@ -3886,9 +3890,8 @@ public class RestContext extends BeanContext {
                if (x == null)
                        x = getInstanceProperty(REST_beanFactory, 
BeanFactory.class, null, bf);
                if (x == null)
-                       x = bf.createBeanViaMethod(BeanFactory.class, resource, 
"createBeanFactory");
-               if (x == null)
                        x = bf;
+               x = bf.createBeanViaMethod(BeanFactory.class, resource, 
"createBeanFactory", x);
                return x;
        }
 
@@ -3933,9 +3936,8 @@ public class RestContext extends BeanContext {
                if (x == null)
                        x = getInstanceProperty(REST_beanFactory, 
BeanFactory.class, null, bf);
                if (x == null)
-                       x = bf.createBeanViaMethod(BeanFactory.class, resource, 
"createBeanFactory");
-               if (x == null)
                        x = bf;
+               x = bf.createBeanViaMethod(BeanFactory.class, resource, 
"createBeanFactory", x);
                return x;
        }
 
@@ -3970,11 +3972,12 @@ public class RestContext extends BeanContext {
        protected ResponseHandler[] createResponseHandlers(Object resource, 
BeanFactory beanFactory) throws Exception {
                ResponseHandler[] x = 
getInstanceArrayProperty(REST_responseHandlers, ResponseHandler.class, null, 
beanFactory);
                if (x == null)
-                       x = 
beanFactory.createBeanViaMethod(ResponseHandler[].class, resource, 
"createResponseHandlers");
-               if (x == null)
                        x = 
beanFactory.getBean(ResponseHandler[].class).orElse(null);
                if (x == null)
                        x = new ResponseHandler[0];
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(ResponseHandler[].class, x)
+                       .createBeanViaMethod(ResponseHandler[].class, resource, 
"createResponseHandlers", x);
                return x;
        }
 
@@ -4010,11 +4013,11 @@ public class RestContext extends BeanContext {
        protected SerializerGroup createSerializers(Object resource, 
BeanFactory beanFactory, PropertyStore ps) throws Exception {
                Object x = getArrayProperty(REST_serializers, Object.class);
                if (x == null)
-                       x = beanFactory.createBeanViaMethod(Serializer[].class, 
resource, "createSerializers");
+                       x = beanFactory.createBeanViaMethod(Serializer[].class, 
resource, "createSerializers", null);
                if (x == null)
-                       x = beanFactory.createBeanViaMethod(Class[].class, 
resource, "createSerializers");
+                       x = beanFactory.createBeanViaMethod(Class[].class, 
resource, "createSerializers", null);
                if (x == null) {
-                       x = 
beanFactory.createBeanViaMethod(SerializerGroup.class, resource, 
"createSerializers");
+                       x = 
beanFactory.createBeanViaMethod(SerializerGroup.class, resource, 
"createSerializers", null);
                        if (x != null)
                                return (SerializerGroup)x;
                }
@@ -4066,11 +4069,11 @@ public class RestContext extends BeanContext {
        protected ParserGroup createParsers(Object resource, BeanFactory 
beanFactory, PropertyStore ps) throws Exception {
                Object x = getArrayProperty(REST_parsers, Object.class);
                if (x == null)
-                       x = beanFactory.createBeanViaMethod(Parser[].class, 
resource, "createParsers");
+                       x = beanFactory.createBeanViaMethod(Parser[].class, 
resource, "createParsers", null);
                if (x == null)
-                       x = beanFactory.createBeanViaMethod(Class[].class, 
resource, "createParsers");
+                       x = beanFactory.createBeanViaMethod(Class[].class, 
resource, "createParsers", null);
                if (x == null) {
-                       x = beanFactory.createBeanViaMethod(ParserGroup.class, 
resource, "createParsers");
+                       x = beanFactory.createBeanViaMethod(ParserGroup.class, 
resource, "createParsers", null);
                        if (x != null)
                                return (ParserGroup)x;
                }
@@ -4126,11 +4129,12 @@ public class RestContext extends BeanContext {
                if (x == null)
                        x = getInstanceProperty(REST_partSerializer, 
HttpPartSerializer.class, null, beanFactory);
                if (x == null)
-                       x = 
beanFactory.createBeanViaMethod(HttpPartSerializer.class, resource, 
"createPartSerializer");
-               if (x == null)
                        x = 
beanFactory.getBean(HttpPartSerializer.class).orElse(null);
                if (x == null)
                        x = new OpenApiSerializer(getPropertyStore());
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(HttpPartSerializer.class, x)
+                       .createBeanViaMethod(HttpPartSerializer.class, 
resource, "createPartSerializer", x);
                return x;
        }
 
@@ -4170,11 +4174,12 @@ public class RestContext extends BeanContext {
                if (x == null)
                        x = getInstanceProperty(REST_partParser, 
HttpPartParser.class, null, beanFactory);
                if (x == null)
-                       x = 
beanFactory.createBeanViaMethod(HttpPartParser.class, resource, 
"createPartParser");
-               if (x == null)
                        x = 
beanFactory.getBean(HttpPartParser.class).orElse(null);
                if (x == null)
                        x = new OpenApiParser(getPropertyStore());
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(HttpPartParser.class, x)
+                       .createBeanViaMethod(HttpPartParser.class, resource, 
"createPartParser", x);
                return x;
        }
 
@@ -4209,11 +4214,12 @@ public class RestContext extends BeanContext {
        protected RestMethodParam[] createParamResolvers(Object resource, 
BeanFactory beanFactory) throws Exception {
                RestMethodParam[] x = 
getInstanceArrayProperty(REST_paramResolvers, RestMethodParam.class, null, 
beanFactory);
                if (x == null)
-                       x = 
beanFactory.createBeanViaMethod(RestMethodParam[].class, resource, 
"createParamResolvers");
-               if (x == null)
                        x = 
beanFactory.getBean(RestMethodParam[].class).orElse(null);
                if (x == null)
                        x = new RestMethodParam[0];
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(RestMethodParam[].class, x)
+                       .createBeanViaMethod(RestMethodParam[].class, resource, 
"createParamResolvers", x);
                return x;
        }
 
@@ -4240,11 +4246,12 @@ public class RestContext extends BeanContext {
         * @throws Exception If logger could not be instantiated.
         */
        protected Logger createLogger(Object resource, BeanFactory beanFactory) 
throws Exception {
-               Logger x = beanFactory.createBeanViaMethod(Logger.class, 
resource, "createLogger");
-               if (x == null)
-                       x = beanFactory.getBean(Logger.class).orElse(null);
+               Logger x = beanFactory.getBean(Logger.class).orElse(null);
                if (x == null)
                        x = Logger.getLogger(resource.getClass().getName());
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(Logger.class, x)
+                       .createBeanViaMethod(Logger.class, resource, 
"createLogger", x);
                return x;
        }
 
@@ -4271,14 +4278,15 @@ public class RestContext extends BeanContext {
         * @throws Exception If JSON schema generator could not be instantiated.
         */
        protected JsonSchemaGenerator createJsonSchemaGenerator(Object 
resource, BeanFactory beanFactory) throws Exception {
-               JsonSchemaGenerator x = 
beanFactory.createBeanViaMethod(JsonSchemaGenerator.class, resource, 
"createJsonSchemaGenerator");
-               if (x == null)
-                       x = 
beanFactory.getBean(JsonSchemaGenerator.class).orElse(null);
+               JsonSchemaGenerator x = 
beanFactory.getBean(JsonSchemaGenerator.class).orElse(null);
                if (x == null)
                        x = JsonSchemaGenerator
                                .create()
                                .apply(getPropertyStore())
                                .build();
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(JsonSchemaGenerator.class, x)
+                       .createBeanViaMethod(JsonSchemaGenerator.class, 
resource, "createJsonSchemaGenerator", x);
                return x;
        }
 
@@ -4305,14 +4313,15 @@ public class RestContext extends BeanContext {
         * @throws Exception If variable resolver could not be instantiated.
         */
        protected VarResolver createVarResolver(Object resource, BeanFactory 
beanFactory) throws Exception {
-               VarResolver x = 
beanFactory.createBeanViaMethod(VarResolver.class, resource, 
"createVarResolver");
-               if (x == null)
-                       x = beanFactory.getBean(VarResolver.class).orElse(null);
+               VarResolver x = 
beanFactory.getBean(VarResolver.class).orElse(null);
                if (x == null)
                        x = builder.varResolverBuilder
                        .vars(createVars(resource,beanFactory))
                        .build()
                ;
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(VarResolver.class, x)
+                       .createBeanViaMethod(VarResolver.class, resource, 
"createVarResolver", x);
                return x;
        }
 
@@ -4340,9 +4349,7 @@ public class RestContext extends BeanContext {
         */
        @SuppressWarnings("unchecked")
        protected VarList createVars(Object resource, BeanFactory beanFactory) 
throws Exception {
-               VarList x = beanFactory.createBeanViaMethod(VarList.class, 
resource, "createVars");
-               if (x == null)
-                       x = beanFactory.getBean(VarList.class).orElse(null);
+               VarList x = beanFactory.getBean(VarList.class).orElse(null);
                if (x == null)
                        x = VarList.of(
                                FileVar.class,
@@ -4361,6 +4368,9 @@ public class RestContext extends BeanContext {
                                UrlEncodeVar.class,
                                HtmlWidgetVar.class
                        );
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(VarList.class, x)
+                       .createBeanViaMethod(VarList.class, resource, 
"createVars", x);
                return x;
        }
 
@@ -4387,11 +4397,12 @@ public class RestContext extends BeanContext {
         * @throws Exception If stack trace store could not be instantiated.
         */
        protected StackTraceStore createStackTraceStore(Object resource, 
BeanFactory beanFactory) throws Exception {
-               StackTraceStore x = 
beanFactory.createBeanViaMethod(StackTraceStore.class, resource, 
"createStackTraceStore");
-               if (x == null)
-                       x = 
beanFactory.getBean(StackTraceStore.class).orElse(null);
+               StackTraceStore x = 
beanFactory.getBean(StackTraceStore.class).orElse(null);
                if (x == null)
                        x = StackTraceStore.GLOBAL;
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(StackTraceStore.class, x)
+                       .createBeanViaMethod(StackTraceStore.class, resource, 
"createStackTraceStore", x);
                return x;
        }
 
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java
index 8782cd1..d42ef49 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java
@@ -204,7 +204,7 @@ public class RestContextBuilder extends BeanContextBuilder 
implements ServletCon
                if (resource.isPresent()) {
                        Object r = resource.get();
                        BeanFactory bf = new 
BeanFactory(parentContext.isPresent() ? parentContext.get().rootBeanFactory : 
null, r);
-                       x = bf.createBeanViaMethod(BeanFactory.class, r, 
"createBeanFactory");
+                       x = bf.createBeanViaMethod(BeanFactory.class, r, 
"createBeanFactory", null);
                }
                if (x == null && parentContext.isPresent()) {
                        x = parentContext.get().rootBeanFactory;
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContext.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContext.java
index 77218e8..69bcac0 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContext.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContext.java
@@ -757,11 +757,12 @@ public class RestMethodContext extends BeanContext 
implements Comparable<RestMet
        protected RestConverter[] createConverters(Object resource, BeanFactory 
beanFactory) throws Exception {
                RestConverter[] x = getInstanceArrayProperty(REST_converters, 
RestConverter.class, null, beanFactory);
                if (x == null)
-                       x = 
beanFactory.createBeanViaMethod(RestConverter[].class, resource, 
"createConverters");
-               if (x == null)
                        x = 
beanFactory.getBean(RestConverter[].class).orElse(null);
                if (x == null)
                        x = new RestConverter[0];
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(RestConverter[].class, x)
+                       .createBeanViaMethod(RestConverter[].class, resource, 
"createConverters", x);
                return x;
        }
 
@@ -798,8 +799,6 @@ public class RestMethodContext extends BeanContext 
implements Comparable<RestMet
        protected RestGuard[] createGuards(Object resource, BeanFactory 
beanFactory) throws Exception {
                RestGuard[] x = getInstanceArrayProperty(REST_guards, 
RestGuard.class, null, beanFactory);
                if (x == null)
-                       x = beanFactory.createBeanViaMethod(RestGuard[].class, 
resource, "createGuards");
-               if (x == null)
                        x = beanFactory.getBean(RestGuard[].class).orElse(null);
                if (x == null)
                        x = new RestGuard[0];
@@ -818,7 +817,13 @@ public class RestMethodContext extends BeanContext 
implements Comparable<RestMet
                        }
                }
 
-               return xl.toArray(new RestGuard[xl.size()]);
+               x = xl.toArray(new RestGuard[xl.size()]);
+
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(RestGuard[].class, x)
+                       .createBeanViaMethod(RestGuard[].class, resource, 
"createGuards", x);
+
+               return x;
        }
 
        /**
@@ -852,8 +857,6 @@ public class RestMethodContext extends BeanContext 
implements Comparable<RestMet
        protected RestMatcher[] createMatchers(Object resource, BeanFactory 
beanFactory) throws Exception {
                RestMatcher[] x = getInstanceArrayProperty(RESTMETHOD_matchers, 
RestMatcher.class, null, beanFactory);
                if (x == null)
-                       x = 
beanFactory.createBeanViaMethod(RestMatcher[].class, resource, 
"createMatchers", Method.class);
-               if (x == null)
                        x = 
beanFactory.getBean(RestMatcher[].class).orElse(null);
                if (x == null)
                        x = new RestMatcher[0];
@@ -862,6 +865,10 @@ public class RestMethodContext extends BeanContext 
implements Comparable<RestMet
                if (clientVersion != null)
                        x = ArrayUtils.append(x, new 
ClientVersionMatcher(context.getClientVersionHeader(), mi));
 
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(RestMatcher[].class, x)
+                       .createBeanViaMethod(RestMatcher[].class, resource, 
"createMatchers", x);
+
                return x;
        }
 
@@ -898,11 +905,12 @@ public class RestMethodContext extends BeanContext 
implements Comparable<RestMet
        protected Encoder[] createEncoders(Object resource, BeanFactory 
beanFactory) throws Exception {
                Encoder[] x = getInstanceArrayProperty(REST_encoders, 
Encoder.class, null, beanFactory);
                if (x == null)
-                       x = beanFactory.createBeanViaMethod(Encoder[].class, 
resource, "createEncoders");
-               if (x == null)
                        x = beanFactory.getBean(Encoder[].class).orElse(null);
                if (x == null)
                        x = new Encoder[0];
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(Encoder[].class, x)
+                       .createBeanViaMethod(Encoder[].class, resource, 
"createEncoders", x);
                return x;
        }
 
@@ -938,20 +946,20 @@ public class RestMethodContext extends BeanContext 
implements Comparable<RestMet
        protected SerializerGroup createSerializers(Object resource, 
BeanFactory beanFactory, PropertyStore ps) throws Exception {
                Object x = getArrayProperty(REST_serializers, Object.class);
                if (x == null)
-                       x = beanFactory.createBeanViaMethod(Serializer[].class, 
resource, "createSerializers", Method.class);
+                       x = beanFactory.createBeanViaMethod(Serializer[].class, 
resource, "createSerializers", null, Method.class);
                if (x == null)
-                       x = beanFactory.createBeanViaMethod(Class[].class, 
resource, "createSerializers", Method.class);
+                       x = beanFactory.createBeanViaMethod(Class[].class, 
resource, "createSerializers", null, Method.class);
                if (x == null) {
-                       x = 
beanFactory.createBeanViaMethod(SerializerGroup.class, resource, 
"createSerializers", Method.class);
+                       x = 
beanFactory.createBeanViaMethod(SerializerGroup.class, resource, 
"createSerializers", null, Method.class);
                        if (x != null)
                                return (SerializerGroup)x;
                }
                if (x == null)
-                       x = beanFactory.createBeanViaMethod(Serializer[].class, 
resource, "createSerializers");
+                       x = beanFactory.createBeanViaMethod(Serializer[].class, 
resource, "createSerializers", null);
                if (x == null)
-                       x = beanFactory.createBeanViaMethod(Class[].class, 
resource, "createSerializers");
+                       x = beanFactory.createBeanViaMethod(Class[].class, 
resource, "createSerializers", null);
                if (x == null) {
-                       x = 
beanFactory.createBeanViaMethod(SerializerGroup.class, resource, 
"createSerializers");
+                       x = 
beanFactory.createBeanViaMethod(SerializerGroup.class, resource, 
"createSerializers", null);
                        if (x != null)
                                return (SerializerGroup)x;
                }
@@ -1003,20 +1011,20 @@ public class RestMethodContext extends BeanContext 
implements Comparable<RestMet
        protected ParserGroup createParsers(Object resource, BeanFactory 
beanFactory, PropertyStore ps) throws Exception {
                Object x = getArrayProperty(REST_parsers, Object.class);
                if (x == null)
-                       x = beanFactory.createBeanViaMethod(Parser[].class, 
resource, "createParsers", Method.class);
+                       x = beanFactory.createBeanViaMethod(Parser[].class, 
resource, "createParsers", null, Method.class);
                if (x == null)
-                       x = beanFactory.createBeanViaMethod(Class[].class, 
resource, "createParsers", Method.class);
+                       x = beanFactory.createBeanViaMethod(Class[].class, 
resource, "createParsers", null, Method.class);
                if (x == null) {
-                       x = beanFactory.createBeanViaMethod(ParserGroup.class, 
resource, "createParsers", Method.class);
+                       x = beanFactory.createBeanViaMethod(ParserGroup.class, 
resource, "createParsers", null, Method.class);
                        if (x != null)
                                return (ParserGroup)x;
                }
                if (x == null)
-                       x = beanFactory.createBeanViaMethod(Parser[].class, 
resource, "createParsers");
+                       x = beanFactory.createBeanViaMethod(Parser[].class, 
resource, "createParsers", null);
                if (x == null)
-                       x = beanFactory.createBeanViaMethod(Class[].class, 
resource, "createParsers");
+                       x = beanFactory.createBeanViaMethod(Class[].class, 
resource, "createParsers", null);
                if (x == null) {
-                       x = beanFactory.createBeanViaMethod(ParserGroup.class, 
resource, "createParsers");
+                       x = beanFactory.createBeanViaMethod(ParserGroup.class, 
resource, "createParsers", null);
                        if (x != null)
                                return (ParserGroup)x;
                }
@@ -1073,13 +1081,15 @@ public class RestMethodContext extends BeanContext 
implements Comparable<RestMet
                if (x == null)
                        x = getInstanceProperty(REST_partSerializer, 
HttpPartSerializer.class, null, beanFactory);
                if (x == null)
-                       x = 
beanFactory.createBeanViaMethod(HttpPartSerializer.class, resource, 
"createPartSerializer", Method.class);
-               if (x == null)
-                       x = 
beanFactory.createBeanViaMethod(HttpPartSerializer.class, resource, 
"createPartSerializer");
-               if (x == null)
                        x = 
beanFactory.getBean(HttpPartSerializer.class).orElse(null);
                if (x == null)
                        x = new OpenApiSerializer(ps);
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(HttpPartSerializer.class, x)
+                       .createBeanViaMethod(HttpPartSerializer.class, 
resource, "createPartSerializer", x, Method.class);
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(HttpPartSerializer.class, x)
+                       .createBeanViaMethod(HttpPartSerializer.class, 
resource, "createPartSerializer", x);
                return x;
        }
 
@@ -1120,13 +1130,15 @@ public class RestMethodContext extends BeanContext 
implements Comparable<RestMet
                if (x == null)
                        x = getInstanceProperty(REST_partParser, 
HttpPartParser.class, null, beanFactory);
                if (x == null)
-                       x = 
beanFactory.createBeanViaMethod(HttpPartParser.class, resource, 
"createPartParser", Method.class);
-               if (x == null)
-                       x = 
beanFactory.createBeanViaMethod(HttpPartParser.class, resource, 
"createPartParser");
-               if (x == null)
                        x = 
beanFactory.getBean(HttpPartParser.class).orElse(null);
                if (x == null)
                        x = new OpenApiParser(ps);
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(HttpPartParser.class, x)
+                       .createBeanViaMethod(HttpPartParser.class, resource, 
"createPartParser", x, Method.class);
+               x = BeanFactory.of(beanFactory, resource)
+                       .addBean(HttpPartParser.class, x)
+                       .createBeanViaMethod(HttpPartParser.class, resource, 
"createPartParser", x);
                return x;
        }
 

Reply via email to