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

commit e5d5be5d0e1a56b0e713a03ec1a6cc1dec48807f
Author: JamesBognar <[email protected]>
AuthorDate: Tue Feb 9 15:23:21 2021 -0500

    REST refactoring.
---
 .../java/org/apache/juneau/rest/RequestPath.java   |  5 ++--
 .../main/java/org/apache/juneau/rest/RestCall.java | 34 +++++-----------------
 .../java/org/apache/juneau/rest/RestContext.java   | 12 ++++----
 .../apache/juneau/rest/RestOperationContext.java   |  3 +-
 .../java/org/apache/juneau/rest/RestRequest.java   |  8 ++---
 .../java/org/apache/juneau/rest/RestResponse.java  |  5 ++--
 .../java/org/apache/juneau/rest/Swagger_Test.java  |  4 +--
 .../apache/juneau/rest/testutils/TestUtils.java    |  2 +-
 8 files changed, 26 insertions(+), 47 deletions(-)

diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestPath.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestPath.java
index d7e83ae..2964566 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestPath.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestPath.java
@@ -40,10 +40,9 @@ public class RequestPath extends TreeMap<String,String> {
        private final RestRequest req;
        private HttpPartParserSession parser;
 
-       RequestPath(RestCall call) {
+       RequestPath(RestRequest req) {
                super(String.CASE_INSENSITIVE_ORDER);
-               this.req = call.getRestRequest();
-               putAll(call.getPathVars());
+               this.req = req;
        }
 
        RequestPath parser(HttpPartParserSession parser) {
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 5ad0edd..f9f35ca 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
@@ -111,38 +111,20 @@ public class RestCall {
        /**
         * Sets the method context on this call.
         *
-        * Used for logging statistics on the method.
+        * <p>
+        * This triggers the creation of the {@link RestRequest} and {@link 
RestResponse}.
         *
         * @param value The new value.
         * @return This object (for method chaining).
+        * @throws Exception If thrown from the {@link RestRequest} or {@link 
RestResponse} constructors.
         */
-       public RestCall restOperationContext(RestOperationContext value) {
+       public RestCall restOperationContext(RestOperationContext value) throws 
Exception {
                opContext = value;
                beanFactory.addBean(RestOperationContext.class, value);
-               return this;
-       }
-
-       /**
-        * Set the {@link RestRequest} object on this REST call.
-        *
-        * @param value The {@link RestRequest} object on this REST call.
-        * @return This object (for method chaining).
-        */
-       public RestCall restRequest(RestRequest value) {
-               rreq = value;
-               beanFactory.addBean(RestRequest.class, value);
-               return this;
-       }
-
-       /**
-        * Set the {@link RestResponse} object on this REST call.
-        *
-        * @param value The {@link RestResponse} object on this REST call.
-        * @return This object (for method chaining).
-        */
-       public RestCall restResponse(RestResponse value) {
-               rres = value;
-               beanFactory.addBean(RestResponse.class, value);
+               rreq = context.createRequest(this);
+               beanFactory.addBean(RestRequest.class, rreq);
+               rres = context.createResponse(this);
+               beanFactory.addBean(RestResponse.class, rres);
                return this;
        }
 
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 e41681c..47a4df4 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
@@ -6633,25 +6633,23 @@ public class RestContext extends BeanContext {
         * This method is called immediately after {@link #startCall(RestCall)} 
has been called.
         *
         * @param call The current REST call.
-        * @param opContext The context of the matched Java method.
         * @return The wrapped request object.
         * @throws Exception If any errors occur trying to interpret the 
request.
         */
-       public RestRequest createRequest(RestCall call, RestOperationContext 
opContext) throws Exception {
-               return new RestRequest(call, opContext);
+       public RestRequest createRequest(RestCall call) throws Exception {
+               return new RestRequest(call);
        }
 
        /**
         * Creates a {@link RestResponse} object based on the specified 
incoming {@link HttpServletResponse} object
-        * and the request returned by {@link 
#createRequest(RestCall,RestOperationContext)}.
+        * and the request returned by {@link #createRequest(RestCall)}.
         *
         * @param call The current REST call.
-        * @param opContext The context of the matched Java method.
         * @return The wrapped response object.
         * @throws Exception If any errors occur trying to interpret the 
request or response.
         */
-       public RestResponse createResponse(RestCall call, RestOperationContext 
opContext) throws Exception {
-               return new RestResponse(call, opContext);
+       public RestResponse createResponse(RestCall call) throws Exception {
+               return new RestResponse(call);
        }
 
        /**
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContext.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContext.java
index 855bcb1..479d593 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContext.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContext.java
@@ -1856,8 +1856,7 @@ public class RestOperationContext extends BeanContext 
implements Comparable<Rest
         */
        protected void invoke(RestCall call) throws Throwable {
 
-               context.createRequest(call, this);
-               context.createResponse(call, this);
+               call.restOperationContext(this);
 
                UrlPathMatch pm = call.getUrlPathMatch();
                if (pm == null)
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
index 1c0906e..ef8e911 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
@@ -124,12 +124,11 @@ public final class RestRequest extends 
HttpServletRequestWrapper {
        /**
         * Constructor.
         */
-       RestRequest(RestCall call, RestOperationContext opContext) throws 
Exception {
+       RestRequest(RestCall call) throws Exception {
                super(call.getRequest());
-               call.restRequest(this);
 
                this.call = call;
-               this.opContext = opContext;
+               this.opContext = call.getRestOperationContext();
 
                inner = call.getRequest();
                context = call.getContext();
@@ -157,7 +156,8 @@ public final class RestRequest extends 
HttpServletRequestWrapper {
                if (! s.isEmpty())
                        headers.queryParams(queryParams, s);
 
-               pathParams = new RequestPath(call);
+               pathParams = new RequestPath(this);
+               pathParams.putAll(call.getPathVars());
 
                beanSession = opContext.createSession();
 
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
index febc7a4..ad659af 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
@@ -72,12 +72,13 @@ public final class RestResponse extends 
HttpServletResponseWrapper {
        /**
         * Constructor.
         */
-       RestResponse(RestCall call, RestOperationContext opContext) throws 
Exception {
+       RestResponse(RestCall call) throws Exception {
                super(call.getResponse());
-               call.restResponse(this);
 
                inner = call.getResponse();
                request = call.getRestRequest();
+
+               RestOperationContext opContext = call.getRestOperationContext();
                responseMeta = opContext.getResponseMeta();
 
                RestContext context = call.getContext();
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/rest/Swagger_Test.java 
b/juneau-utest/src/test/java/org/apache/juneau/rest/Swagger_Test.java
index ba28682..35db1a8 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/Swagger_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/Swagger_Test.java
@@ -48,7 +48,7 @@ public class Swagger_Test {
        private org.apache.juneau.dto.swagger.Swagger getSwaggerWithFile(Object 
resource) throws Exception {
                RestContext rc = 
RestContext.create(resource).fileFinder(TestClasspathFileFinder.class).build();
                RestOperationContext roc = 
RestOperationContext.create(Swagger_Test.class.getMethod("testMethod"), 
rc).build();
-               RestRequest req = rc.createRequest(new RestCall(resource, rc, 
new MockServletRequest(), null), roc);
+               RestRequest req = rc.createRequest(new RestCall(resource, rc, 
new MockServletRequest(), new MockServletResponse()).restOperationContext(roc));
                SwaggerProvider ip = rc.getSwaggerProvider();
                return ip.getSwagger(rc, req.getLocale());
        }
@@ -56,7 +56,7 @@ public class Swagger_Test {
        private static org.apache.juneau.dto.swagger.Swagger getSwagger(Object 
resource) throws Exception {
                RestContext rc = RestContext.create(resource).build();
                RestOperationContext roc = 
RestOperationContext.create(Swagger_Test.class.getMethod("testMethod"), 
rc).build();
-               RestRequest req = rc.createRequest(new RestCall(resource, rc, 
new MockServletRequest(), null), roc);
+               RestRequest req = rc.createRequest(new RestCall(resource, rc, 
new MockServletRequest(), new MockServletResponse()).restOperationContext(roc));
                SwaggerProvider ip = rc.getSwaggerProvider();
                return ip.getSwagger(rc, req.getLocale());
        }
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/rest/testutils/TestUtils.java 
b/juneau-utest/src/test/java/org/apache/juneau/rest/testutils/TestUtils.java
index 29d9767..36dcd5f 100755
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/testutils/TestUtils.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/testutils/TestUtils.java
@@ -29,7 +29,7 @@ public class TestUtils extends 
org.apache.juneau.testutils.TestUtils {
                        Object r = c.newInstance();
                        RestContext rc = RestContext.create(r).build();
                        RestOperationContext ctx = 
RestOperationContext.create(TestUtils.class.getMethod("getSwagger", 
Class.class), rc).build();
-                       RestRequest req = rc.createRequest(new RestCall(r, rc, 
new MockServletRequest(), null), ctx);
+                       RestRequest req = rc.createRequest(new RestCall(r, rc, 
new MockServletRequest(), new MockServletResponse()).restOperationContext(ctx));
                        SwaggerProvider ip = rc.getSwaggerProvider();
                        return ip.getSwagger(rc, req.getLocale());
                } catch (Exception e) {

Reply via email to