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 5fcefe7  REST refactoring.
5fcefe7 is described below

commit 5fcefe76d4e08d546a1d2f747b04958f883a3d4b
Author: JamesBognar <[email protected]>
AuthorDate: Sat Jan 16 14:54:53 2021 -0500

    REST refactoring.
---
 .../apache/juneau/rest/RestMethod_Params_Test.java |   4 +-
 .../main/java/org/apache/juneau/rest/RestCall.java |  25 ++-
 .../java/org/apache/juneau/rest/RestContext.java   | 149 ++++++++---------
 .../org/apache/juneau/rest/RestMethodContext.java  |   4 +-
 .../org/apache/juneau/rest/RestMethodInvoker.java  |  66 ++++++++
 .../org/apache/juneau/rest/RestMethodParam.java    |  19 +--
 .../org/apache/juneau/rest/RestParamDefaults.java  | 182 +++++++++++----------
 7 files changed, 260 insertions(+), 189 deletions(-)

diff --git 
a/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/RestMethod_Params_Test.java
 
b/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/RestMethod_Params_Test.java
index 3e597b9..5a86bf2 100644
--- 
a/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/RestMethod_Params_Test.java
+++ 
b/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/RestMethod_Params_Test.java
@@ -381,8 +381,8 @@ public class RestMethod_Params_Test {
                        super(RestParamType.HEADER, "Custom", B2b.class);
                }
                @Override
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return new B2b(req.getHeader("Custom"));
+               public Object resolve(RestCall call) throws Exception {
+                       return new 
B2b(call.getRestRequest().getHeader("Custom"));
                }
        }
 
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestCall.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestCall.java
index 79ab9c3..43d2249 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestCall.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestCall.java
@@ -19,6 +19,7 @@ import java.util.*;
 import javax.servlet.http.*;
 
 import org.apache.juneau.cp.*;
+import org.apache.juneau.http.exception.*;
 import org.apache.juneau.httppart.bean.*;
 import org.apache.juneau.rest.logging.*;
 import org.apache.juneau.rest.util.*;
@@ -290,9 +291,20 @@ public class RestCall {
         * Returns the REST request of this REST call.
         *
         * @return the REST request of this REST call.
+        * @throws InternalServerError If the RestRequest object has not yet 
been created on this call.
         */
        public RestRequest getRestRequest() {
-               return rreq;
+               return getRestRequestOptional().orElseThrow(()->new 
InternalServerError("RestRequest object has not yet been created."));
+       }
+
+       /**
+        * Returns the REST request of this REST call.
+        *
+        * @return the REST request of this REST call.
+        * @throws InternalServerError If the RestRequest object has not yet 
been created on this call.
+        */
+       public Optional<RestRequest> getRestRequestOptional() {
+               return Optional.ofNullable(rreq);
        }
 
        /**
@@ -301,7 +313,16 @@ public class RestCall {
         * @return the REST response of this REST call.
         */
        public RestResponse getRestResponse() {
-               return rres;
+               return getRestResponseOptional().orElseThrow(()->new 
InternalServerError("RestResponse object has not yet been created."));
+       }
+
+       /**
+        * Returns the REST response of this REST call.
+        *
+        * @return the REST response of this REST call.
+        */
+       public Optional<RestResponse> getRestResponseOptional() {
+               return Optional.ofNullable(rres);
        }
 
        /**
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 34f9280..e0d5ea6 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
@@ -3214,14 +3214,13 @@ public class RestContext extends BeanContext {
        private final MethodInvoker[]
                postInitMethods,
                postInitChildFirstMethods,
-               preCallMethods,
-               postCallMethods,
                startCallMethods,
                endCallMethods,
                destroyMethods;
-       private final RestMethodParam[][]
-               preCallMethodParams,
-               postCallMethodParams;
+
+       private final RestMethodInvoker[]
+               preCallMethods,
+               postCallMethods;
 
        private final FileFinder fileFinder;
        private final StaticFiles staticFiles;
@@ -3400,11 +3399,14 @@ public class RestContext extends BeanContext {
 
                        this.childResources = Collections.synchronizedMap(new 
LinkedHashMap<String,RestContext>());  // Not unmodifiable on purpose so that 
children can be replaced.
 
-                       this.startCallMethods = 
createStartCallMethods(r).stream().map(x->new MethodInvoker(x, 
getMethodExecStats(x))).toArray(MethodInvoker[]::new);
-                       this.endCallMethods = 
createEndCallMethods(r).stream().map(x->new MethodInvoker(x, 
getMethodExecStats(x))).toArray(MethodInvoker[]::new);
-                       this.postInitMethods = 
createPostInitMethods(r).stream().map(x->new MethodInvoker(x, 
getMethodExecStats(x))).toArray(MethodInvoker[]::new);
-                       this.postInitChildFirstMethods = 
createPostInitChildFirstMethods(r).stream().map(x->new MethodInvoker(x, 
getMethodExecStats(x))).toArray(MethodInvoker[]::new);
-                       this.destroyMethods = 
createDestroyMethods(r).stream().map(x->new MethodInvoker(x, 
getMethodExecStats(x))).toArray(MethodInvoker[]::new);
+                       this.startCallMethods = 
createStartCallMethods(r).stream().map(this::toMethodInvoker).toArray(MethodInvoker[]::new);
+                       this.endCallMethods = 
createEndCallMethods(r).stream().map(this::toMethodInvoker).toArray(MethodInvoker[]::new);
+                       this.postInitMethods = 
createPostInitMethods(r).stream().map(this::toMethodInvoker).toArray(MethodInvoker[]::new);
+                       this.postInitChildFirstMethods = 
createPostInitChildFirstMethods(r).stream().map(this::toMethodInvoker).toArray(MethodInvoker[]::new);
+                       this.destroyMethods = 
createDestroyMethods(r).stream().map(this::toMethodInvoker).toArray(MethodInvoker[]::new);
+
+                       this.preCallMethods = 
createPreCallMethods(r).stream().map(this::toRestMethodInvoker).toArray(RestMethodInvoker[]::
 new);
+                       this.postCallMethods = 
createPostCallMethods(r).stream().map(this::toRestMethodInvoker).toArray(RestMethodInvoker[]::
 new);
 
                        
//----------------------------------------------------------------------------------------------------
                        // Initialize the child resources.
@@ -3412,12 +3414,6 @@ public class RestContext extends BeanContext {
                        
//----------------------------------------------------------------------------------------------------
                        List<String> methodsFound = new LinkedList<>();   // 
Temporary to help debug transient duplicate method issue.
                        MethodMapBuilder methodMapBuilder = new 
MethodMapBuilder();
-                       AMap<String,Method>
-                               _preCallMethods = AMap.of(),
-                               _postCallMethods = AMap.of();
-                       AList<RestMethodParam[]>
-                               _preCallMethodParams = AList.of(),
-                               _postCallMethodParams = AList.of();
 
                        for (MethodInfo mi : rci.getPublicMethods()) {
                                RestMethod a = 
mi.getLastAnnotation(RestMethod.class);
@@ -3509,37 +3505,6 @@ public class RestContext extends BeanContext {
                                }
                        }
 
-                       for (MethodInfo m : rci.getAllMethodsParentFirst()) {
-                               if (m.isPublic() && 
m.hasAnnotation(RestHook.class)) {
-                                       HookEvent he = 
m.getLastAnnotation(RestHook.class).value();
-                                       String sig = m.getSignature();
-                                       switch(he) {
-                                               case PRE_CALL: {
-                                                       if (! 
_preCallMethods.containsKey(sig)) {
-                                                               
m.setAccessible();
-                                                               
_preCallMethods.put(sig, m.inner());
-                                                               
_preCallMethodParams.add(findParams(m, true, null));
-                                                       }
-                                                       break;
-                                               }
-                                               case POST_CALL: {
-                                                       if (! 
_postCallMethods.containsKey(sig)) {
-                                                               
m.setAccessible();
-                                                               
_postCallMethods.put(sig, m.inner());
-                                                               
_postCallMethodParams.add(findParams(m, true, null));
-                                                       }
-                                                       break;
-                                               }
-                                               default: // Ignore INIT
-                                       }
-                               }
-                       }
-
-                       this.preCallMethods = 
_preCallMethods.values().stream().map(x->new MethodInvoker(x, 
getMethodExecStats(x))).collect(Collectors.toList()).toArray(new 
MethodInvoker[_preCallMethods.size()]);
-                       this.postCallMethods = 
_postCallMethods.values().stream().map(x->new MethodInvoker(x, 
getMethodExecStats(x))).collect(Collectors.toList()).toArray(new 
MethodInvoker[_postCallMethods.size()]);
-                       this.preCallMethodParams = 
_preCallMethodParams.toArray(new 
RestMethodParam[_preCallMethodParams.size()][]);
-                       this.postCallMethodParams = 
_postCallMethodParams.toArray(new 
RestMethodParam[_postCallMethodParams.size()][]);
-
                        this.methodMap = methodMapBuilder.getMap();
                        this.methods = methodMapBuilder.getList();
 
@@ -3591,6 +3556,14 @@ public class RestContext extends BeanContext {
                }
        }
 
+       private MethodInvoker toMethodInvoker(Method m) {
+               return new MethodInvoker(m, getMethodExecStats(m));
+       }
+
+       private MethodInvoker toRestMethodInvoker(Method m) {
+               return new RestMethodInvoker(m, findParams(m, true, null),  
getMethodExecStats(m));
+       }
+
        /**
         * Instantiates the file finder for this REST resource.
         *
@@ -4642,6 +4615,40 @@ public class RestContext extends BeanContext {
        }
 
        /**
+        * Instantiates the list of {@link HookEvent#PRE_CALL} methods.
+        *
+        * @param resource The REST resource object.
+        * @return The default response headers for this REST object.
+        */
+       protected List<Method> createPreCallMethods(Object resource) {
+               Map<String,Method> x = AMap.of();
+
+               for (MethodInfo m : 
ClassInfo.ofProxy(resource).getAllMethodsParentFirst())
+                       for (RestHook h : m.getAnnotations(RestHook.class))
+                               if (h.value() == HookEvent.PRE_CALL)
+                                       x.put(m.getSignature(), 
m.accessible().inner());
+
+               return AList.of(x.values());
+       }
+
+       /**
+        * Instantiates the list of {@link HookEvent#POST_CALL} methods.
+        *
+        * @param resource The REST resource object.
+        * @return The default response headers for this REST object.
+        */
+       protected List<Method> createPostCallMethods(Object resource) {
+               Map<String,Method> x = AMap.of();
+
+               for (MethodInfo m : 
ClassInfo.ofProxy(resource).getAllMethodsParentFirst())
+                       for (RestHook h : m.getAnnotations(RestHook.class))
+                               if (h.value() == HookEvent.POST_CALL)
+                                       x.put(m.getSignature(), 
m.accessible().inner());
+
+               return AList.of(x.values());
+       }
+
+       /**
         * Returns the bean factory associated with this context.
         *
         * <p>
@@ -5258,14 +5265,14 @@ public class RestContext extends BeanContext {
        /**
         * Finds the {@link RestMethodParam} instances to handle resolving 
objects on the calls to the specified Java method.
         *
-        * @param mi The Java method being called.
+        * @param m The Java method being called.
         * @param isPreOrPost Whether this is a {@link HookEvent#PRE_CALL} or 
{@link HookEvent#POST_CALL}.
         * @param urlPathMatcher The path pattern to match against.
         * @return The array of resolvers.
-        * @throws ServletException If an annotation usage error was detected.
         */
-       protected RestMethodParam[] findParams(MethodInfo mi, boolean 
isPreOrPost, UrlPathMatcher urlPathMatcher) throws ServletException {
+       protected RestMethodParam[] findParams(Method m, boolean isPreOrPost, 
UrlPathMatcher urlPathMatcher) {
 
+               MethodInfo mi = MethodInfo.of(m);
                List<ClassInfo> pt = mi.getParamTypes();
                RestMethodParam[] rp = new RestMethodParam[pt.size()];
                PropertyStore ps = getPropertyStore();
@@ -5308,12 +5315,9 @@ public class RestContext extends BeanContext {
                                rp[i] = new 
RestParamDefaults.HasQueryObject(mpi);
                        } else if 
(mpi.hasAnnotation(org.apache.juneau.rest.annotation.Method.class)) {
                                rp[i] = new RestParamDefaults.MethodObject(mi, 
t, mpi);
-                       } else if (beanFactory.hasBean(t.inner())) {
-                               rp[i] = new 
RestParamDefaults.BeanFactoryObject(mi, t, mpi, beanFactory);
+                       } else if (rp[i] == null) {
+                               rp[i] = new 
RestParamDefaults.BeanFactoryObject(mi, t, mpi);
                        }
-
-                       if (rp[i] == null && ! isPreOrPost)
-                               throw new RestServletException("Invalid 
parameter specified for method ''{0}'' at index position {1}", mi.inner(), i);
                }
 
                return rp;
@@ -5720,10 +5724,7 @@ public class RestContext extends BeanContext {
                        try {
                                x.invokeUsingFactory(call.getBeanFactory(), 
call.getContext().getResource());
                        } catch (ExecutableException e) {
-                               Throwable t = e.unwrap();
-                               if (! (t instanceof HttpException))
-                                       t = new InternalServerError(e);
-                               throw (HttpException)t;
+                               throw toHttpException(e.unwrap(), 
InternalServerError.class);
                        }
                }
        }
@@ -5735,8 +5736,8 @@ public class RestContext extends BeanContext {
         * @throws HttpException If thrown from call methods.
         */
        protected void preCall(RestCall call) throws HttpException {
-               for (int i = 0; i < preCallMethods.length; i++)
-                       preOrPost(getResource(), preCallMethods[i], 
preCallMethodParams[i], call);
+               for (RestMethodInvoker m : preCallMethods)
+                       m.invokeFromCall(call, getResource());
        }
 
        /**
@@ -5746,26 +5747,8 @@ public class RestContext extends BeanContext {
         * @throws HttpException If thrown from call methods.
         */
        protected void postCall(RestCall call) throws HttpException {
-               for (int i = 0; i < postCallMethods.length; i++)
-                       preOrPost(getResource(), postCallMethods[i], 
postCallMethodParams[i], call);
-       }
-
-       private static void preOrPost(Object resource, MethodInvoker m, 
RestMethodParam[] mp, RestCall call) throws HttpException {
-               if (m != null) {
-                       Object[] args = new Object[mp.length];
-                       for (int i = 0; i < mp.length; i++) {
-                               try {
-                                       args[i] = 
mp[i].resolve(call.getRestRequest(), call.getRestResponse());
-                               } catch (Exception e) {
-                                       throw toHttpException(e, 
BadRequest.class, "Invalid data conversion.  Could not convert {0} ''{1}'' to 
type ''{2}'' on method ''{3}.{4}''.", mp[i].getParamType().name(), 
mp[i].getName(), mp[i].getType(), m.getDeclaringClass().getName(), m.getName());
-                               }
-                       }
-                       try {
-                               m.invoke(resource, args);
-                       } catch (Exception e) {
-                               throw toHttpException(e, 
InternalServerError.class);
-                       }
-               }
+               for (RestMethodInvoker m : postCallMethods)
+                       m.invokeFromCall(call, getResource());
        }
 
        /**
@@ -5864,7 +5847,7 @@ public class RestContext extends BeanContext {
         */
        public RestRequest getRequest() {
                RestCall rc = call.get();
-               return rc == null ? null : rc.getRestRequest();
+               return rc == null ? null : 
rc.getRestRequestOptional().orElse(null);
        }
 
        /**
@@ -5874,7 +5857,7 @@ public class RestContext extends BeanContext {
         */
        public RestResponse getResponse() {
                RestCall rc = call.get();
-               return rc == null ? null : rc.getRestResponse();
+               return rc == null ? null : 
rc.getRestResponseOptional().orElse(null);
        }
 
        /**
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 331630c..1e95f74 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
@@ -713,7 +713,7 @@ public class RestMethodContext extends BeanContext 
implements Comparable<RestMet
 
                        responseMeta = ResponseBeanMeta.create(mi, ps);
 
-                       methodParams = context.findParams(mi, false, 
pathMatchers[this.pathMatchers.length-1]);
+                       methodParams = context.findParams(mi.inner(), false, 
pathMatchers[this.pathMatchers.length-1]);
 
                        this.priority = getIntegerProperty(RESTMETHOD_priority, 
0);
 
@@ -1681,7 +1681,7 @@ public class RestMethodContext extends BeanContext 
implements Comparable<RestMet
                Object[] args = new Object[methodParams.length];
                for (int i = 0; i < methodParams.length; i++) {
                        try {
-                               args[i] = methodParams[i].resolve(req, res);
+                               args[i] = methodParams[i].resolve(call);
                        } catch (Exception e) {
                                throw toHttpException(e, BadRequest.class, 
"Invalid data conversion.  Could not convert {0} ''{1}'' to type ''{2}'' on 
method ''{3}.{4}''.", methodParams[i].getParamType().name(), 
methodParams[i].getName(), methodParams[i].getType(), 
mi.getDeclaringClass().getFullName(), mi.getSimpleName());
                        }
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodInvoker.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodInvoker.java
new file mode 100644
index 0000000..c77bb39
--- /dev/null
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodInvoker.java
@@ -0,0 +1,66 @@
+// 
***************************************************************************************************************************
+// * 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.juneau.rest;
+
+import static org.apache.juneau.rest.HttpRuntimeException.*;
+
+import java.lang.reflect.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.http.exception.*;
+import org.apache.juneau.mstat.*;
+import org.apache.juneau.utils.*;
+
+/**
+ * A specialized invoker for methods that are called during a servlet request.
+ */
+public class RestMethodInvoker extends MethodInvoker {
+
+       private final RestMethodParam[] params;
+
+       /**
+        * Constructor.
+        *
+        * @param m The method being wrapped.
+        * @param params The parameter resolvers.
+        * @param stats The instrumentor.
+        */
+       public RestMethodInvoker(Method m, RestMethodParam[] params, 
MethodExecStats stats) {
+               super(m, stats);
+               this.params = params;
+       }
+
+       /**
+        * Invokes this method from the specified {@link RestCall}.
+        *
+        * @param call The REST call.
+        * @param resource The REST resource object.
+        * @return The results of the call.
+        * @throws HttpException If an error occurred during either parameter 
resolution or method invocation.
+        */
+       public Object invokeFromCall(RestCall call, Object resource) throws 
HttpException {
+               Object[] args = new Object[params.length];
+               for (int i = 0; i < params.length; i++) {
+                       try {
+                               args[i] = params[i].resolve(call);
+                       } catch (Exception e) {
+                               throw toHttpException(e, BadRequest.class, 
"Could not resolve parameter {0} of type ''{1}'' on method ''{2}.{3}''.", i, 
params[i].getParamType(), getDeclaringClass().getName(), getName());
+                       }
+               }
+               try {
+                       return invoke(resource, args);
+               } catch (ExecutableException e) {
+                       throw toHttpException(e.unwrap(), 
InternalServerError.class, "Method ''{0}.{1}'' threw an unexpected exception.", 
getDeclaringClass().getName(), getName());
+               }
+       }
+}
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodParam.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodParam.java
index c8b84db..f7c7eb7 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodParam.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodParam.java
@@ -118,6 +118,15 @@ public abstract class RestMethodParam {
        final Class<?> c;
 
        /**
+        * Resolves the parameter object.
+        *
+        * @param call The rest call.
+        * @return The resolved object.
+        * @throws Exception Generic error occurred.
+        */
+       public abstract Object resolve(RestCall call) throws Exception;
+
+       /**
         * Constructor.
         *
         * @param paramType The Swagger parameter type.
@@ -192,16 +201,6 @@ public abstract class RestMethodParam {
        }
 
        /**
-        * Resolves the parameter object.
-        *
-        * @param req The rest request.
-        * @param res The rest response.
-        * @return The resolved object.
-        * @throws Exception Generic error occurred.
-        */
-       public abstract Object resolve(RestRequest req, RestResponse res) 
throws Exception;
-
-       /**
         * Returns the parameter class type that this parameter resolver is 
meant for.
         *
         * @return The parameter class type, or <jk>null</jk> if the type 
passed in isn't an instance of {@link Class}.
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
index f13a7a2..69dc6aa 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
@@ -126,8 +126,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) {
-                       return req;
+               public Object resolve(RestCall call) {
+                       return call.getRequest();
                }
        }
 
@@ -138,8 +138,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) {
-                       return res;
+               public Object resolve(RestCall call) {
+                       return call.getResponse();
                }
        }
 
@@ -150,8 +150,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) {
-                       return req;
+               public Object resolve(RestCall call) {
+                       return call.getRestRequest();
                }
        }
 
@@ -162,8 +162,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) {
-                       return res;
+               public Object resolve(RestCall call) {
+                       return call.getRestResponse();
                }
        }
 
@@ -178,8 +178,8 @@ class RestParamDefaults {
                }
 
                @Override
-               public TimeZone resolve(RestRequest req, RestResponse res) {
-                       return req.getHeaders().getTimeZone();
+               public TimeZone resolve(RestCall call) {
+                       return call.getRestRequest().getHeaders().getTimeZone();
                }
        }
 
@@ -228,9 +228,10 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
+               public Object resolve(RestCall call) throws Exception {
+                       RestRequest req = call.getRestRequest();
                        HttpPartParserSession ps = partParser == null ? 
req.getPartParser() : partParser.createPartSession(req.getParserSessionArgs());
-                       return req.getPathMatch().get(ps, schema, name, type);
+                       return call.getRestRequest().getPathMatch().get(ps, 
schema, name, type);
                }
        }
 
@@ -243,8 +244,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getBody().schema(schema).asType(type);
+               public Object resolve(RestCall call) throws Exception {
+                       return 
call.getRestRequest().getBody().schema(schema).asType(type);
                }
        }
 
@@ -280,9 +281,10 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
+               public Object resolve(RestCall call) throws Exception {
+                       RestRequest req = call.getRestRequest();
                        HttpPartParserSession ps = partParser == null ? 
req.getPartParser() : partParser.createPartSession(req.getParserSessionArgs());
-                       RequestHeaders rh = req.getHeaders();
+                       RequestHeaders rh = call.getRestRequest().getHeaders();
                        return multi ? rh.getAll(ps, schema, name, type) : 
rh.get(ps, schema, name, type);
                }
        }
@@ -303,8 +305,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getAttributes().get(name, type);
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getAttributes().get(name, 
type);
                }
        }
 
@@ -317,8 +319,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getRequest(meta);
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getRequest(meta);
                }
        }
 
@@ -345,12 +347,14 @@ class RestParamDefaults {
 
                @SuppressWarnings({ "unchecked", "rawtypes" })
                @Override /* RestMethodParam */
-               public Object resolve(final RestRequest req, final RestResponse 
res) throws Exception {
+               public Object resolve(final RestCall call) throws Exception {
                        Value<Object> v = 
(Value<Object>)getTypeClass().newInstance();
                        v.listener(new ValueListener() {
                                @Override
                                public void onSet(Object o) {
                                        try {
+                                               RestRequest req = 
call.getRestRequest();
+                                               RestResponse res = 
call.getRestResponse();
                                                ResponsePartMeta rpm = 
req.getResponseHeaderMeta(o);
                                                if (rpm == null)
                                                        rpm = 
ResponseHeaderObject.this.meta;
@@ -377,11 +381,13 @@ class RestParamDefaults {
 
                @SuppressWarnings({ "unchecked", "rawtypes" })
                @Override /* RestMethodParam */
-               public Object resolve(final RestRequest req, final RestResponse 
res) throws Exception {
+               public Object resolve(final RestCall call) throws Exception {
                        Value<Object> v = (Value<Object>)c.newInstance();
                        v.listener(new ValueListener() {
                                @Override
                                public void onSet(Object o) {
+                                       RestRequest req = call.getRestRequest();
+                                       RestResponse res = 
call.getRestResponse();
                                        ResponseBeanMeta meta = 
req.getResponseBeanMeta(o);
                                        if (meta == null)
                                                meta = ResponseObject.this.meta;
@@ -403,12 +409,12 @@ class RestParamDefaults {
 
                @SuppressWarnings({ "unchecked", "rawtypes" })
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, final RestResponse res) 
throws Exception {
+               public Object resolve(final RestCall call) throws Exception {
                        Value<Object> v = (Value<Object>)c.newInstance();
                        v.listener(new ValueListener() {
                                @Override
                                public void onSet(Object o) {
-                                       
res.setStatus(Integer.parseInt(o.toString()));
+                                       
call.getRestResponse().setStatus(Integer.parseInt(o.toString()));
                                }
                        });
                        return v;
@@ -417,32 +423,28 @@ class RestParamDefaults {
 
        static final class MethodObject extends RestMethodParam {
 
-               protected MethodObject(MethodInfo m, ClassInfo t, ParamInfo 
mpi) throws ServletException {
+               protected MethodObject(MethodInfo m, ClassInfo t, ParamInfo 
mpi) {
                        super(OTHER, mpi);
-                       if (! t.is(String.class))
-                               throw new RestServletException("Use of @Method 
annotation on parameter that is not a String on method ''{0}''", m.inner());
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getMethod();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getMethod();
                }
        }
 
        static final class BeanFactoryObject extends RestMethodParam {
 
-               private final BeanFactory beanFactory;
                private final ClassInfo type;
 
-               protected BeanFactoryObject(MethodInfo m, ClassInfo t, 
ParamInfo mpi, BeanFactory beanFactory) {
+               protected BeanFactoryObject(MethodInfo m, ClassInfo t, 
ParamInfo mpi) {
                        super(OTHER, mpi);
-                       this.beanFactory = beanFactory;
                        this.type = t;
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return 
beanFactory.getBean(type.inner()).orElseThrow(()->new ServletException("Could 
not resolve bean type :" + type.inner().getName()));
+               public Object resolve(RestCall call) throws Exception {
+                       return 
call.getBeanFactory().getBean(type.inner()).orElseThrow(()->new 
ServletException("Could not resolve bean type: " + type.inner().getName()));
                }
        }
 
@@ -478,7 +480,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
+               public Object resolve(RestCall call) throws Exception {
+                       RestRequest req = call.getRestRequest();
                        HttpPartParserSession ps = partParser == null ? 
req.getPartParser() : partParser.createPartSession(req.getParserSessionArgs());
                        RequestFormData fd = req.getFormData();
                        return multi ? fd.getAll(ps, schema, name, type) : 
fd.get(ps, schema, name, type);
@@ -517,7 +520,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
+               public Object resolve(RestCall call) throws Exception {
+                       RestRequest req = call.getRestRequest();
                        HttpPartParserSession ps = partParser == null ? 
req.getPartParser() : partParser.createPartSession(req.getParserSessionArgs());
                        RequestQuery rq = req.getQuery();
                        return multi ? rq.getAll(ps, schema, name, type) : 
rq.get(ps, schema, name, type);
@@ -526,10 +530,8 @@ class RestParamDefaults {
 
        static final class HasFormDataObject extends RestMethodParam {
 
-               protected HasFormDataObject(ParamInfo mpi) throws 
ServletException {
+               protected HasFormDataObject(ParamInfo mpi) {
                        super(FORM_DATA, mpi, getName(mpi));
-                       if (getType() != Boolean.class && getType() != 
boolean.class)
-                               throw new RestServletException("Use of @HasForm 
annotation on parameter that is not a boolean on method ''{0}''", 
mpi.getMethod());
                }
 
                private static String getName(ParamInfo mpi) {
@@ -542,7 +544,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
+               public Object resolve(RestCall call) throws Exception {
+                       RestRequest req = call.getRestRequest();
                        BeanSession bs = req.getBeanSession();
                        return 
bs.convertToType(req.getFormData().containsKey(name), bs.getClassMeta(type));
                }
@@ -550,10 +553,8 @@ class RestParamDefaults {
 
        static final class HasQueryObject extends RestMethodParam {
 
-               protected HasQueryObject(ParamInfo mpi) throws ServletException 
{
+               protected HasQueryObject(ParamInfo mpi) {
                        super(QUERY, mpi, getName(mpi));
-                       if (getType() != Boolean.class && getType() != 
boolean.class)
-                               throw new RestServletException("Use of 
@HasQuery annotation on parameter that is not a boolean on method ''{0}''", 
mpi.getMethod());
                }
 
                private static String getName(ParamInfo mpi) {
@@ -566,7 +567,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
+               public Object resolve(RestCall call) throws Exception {
+                       RestRequest req = call.getRestRequest();
                        BeanSession bs = req.getBeanSession();
                        return 
bs.convertToType(req.getQuery().containsKey(name), bs.getClassMeta(type));
                }
@@ -583,8 +585,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getMessages();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getMessages();
                }
        }
 
@@ -595,8 +597,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getMessages();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getMessages();
                }
        }
 
@@ -607,8 +609,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getInputStream();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getInputStream();
                }
        }
 
@@ -619,8 +621,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getInputStream();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getInputStream();
                }
        }
 
@@ -631,8 +633,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getReader();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getReader();
                }
        }
 
@@ -643,8 +645,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return res.getOutputStream();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestResponse().getOutputStream();
                }
        }
 
@@ -655,8 +657,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return res.getOutputStream();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestResponse().getOutputStream();
                }
        }
 
@@ -667,8 +669,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return res.getWriter();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestResponse().getWriter();
                }
        }
 
@@ -679,8 +681,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getHeaders();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getHeaders();
                }
        }
 
@@ -691,8 +693,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getAttributes();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getAttributes();
                }
        }
 
@@ -703,8 +705,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getQuery();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getQuery();
                }
        }
 
@@ -715,8 +717,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getFormData();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getFormData();
                }
        }
 
@@ -727,8 +729,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getContext();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getContext();
                }
        }
 
@@ -739,8 +741,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getBody().getParser();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getBody().getParser();
                }
        }
 
@@ -751,8 +753,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getBody().getReaderParser();
+               public Object resolve(RestCall call) throws Exception {
+                       return 
call.getRestRequest().getBody().getReaderParser();
                }
        }
 
@@ -763,8 +765,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getBody().getInputStreamParser();
+               public Object resolve(RestCall call) throws Exception {
+                       return 
call.getRestRequest().getBody().getInputStreamParser();
                }
        }
 
@@ -775,8 +777,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getLocale();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getLocale();
                }
        }
 
@@ -787,8 +789,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getSwagger();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getSwagger();
                }
        }
 
@@ -799,8 +801,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getPathMatch();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getPathMatch();
                }
        }
 
@@ -811,8 +813,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getBody();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getBody();
                }
        }
 
@@ -823,8 +825,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getConfig();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getConfig();
                }
        }
 
@@ -835,8 +837,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getUriContext();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getUriContext();
                }
        }
 
@@ -847,8 +849,8 @@ class RestParamDefaults {
                }
 
                @Override /* RestMethodParam */
-               public Object resolve(RestRequest req, RestResponse res) throws 
Exception {
-                       return req.getUriResolver();
+               public Object resolve(RestCall call) throws Exception {
+                       return call.getRestRequest().getUriResolver();
                }
        }
 

Reply via email to