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

commit 7c4b57901818dc4d9d6589253fdc9e345e0ecfdb
Author: JamesBognar <[email protected]>
AuthorDate: Sat Jan 16 15:45:23 2021 -0500

    REST refactoring.
---
 .../main/java/org/apache/juneau/rest/RestCall.java | 41 ++++------------------
 .../java/org/apache/juneau/rest/RestContext.java   | 21 +++++++++--
 2 files changed, 25 insertions(+), 37 deletions(-)

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 43d2249..2893ab9 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
@@ -58,7 +58,11 @@ public class RestCall {
         * @param res The incoming HTTP servlet response object.
         */
        public RestCall(Object resource, RestContext context, 
HttpServletRequest req, HttpServletResponse res) {
-               resource(resource).context(context).request(req).response(res);
+               this.context = context;
+               this.resource = resource;
+               beanFactory = new BeanFactory(context.rootBeanFactory,  
resource);
+               beanFactory.addBean(RestContext.class, context);
+               request(req).response(res);
        }
 
        
//------------------------------------------------------------------------------------------------------------------
@@ -103,19 +107,6 @@ public class RestCall {
        }
 
        /**
-        * Overrides the context object on this call.
-        *
-        * @param value The context that's creating this call.
-        * @return This object (for method chaining).
-        */
-       public RestCall context(RestContext value) {
-               context = value;
-               beanFactory = new BeanFactory(value.rootBeanFactory, 
value.getResource());
-               beanFactory.addBean(RestContext.class, value);
-               return this;
-       }
-
-       /**
         * Sets the method context on this call.
         *
         * Used for logging statistics on the method.
@@ -294,18 +285,9 @@ public class RestCall {
         * @throws InternalServerError If the RestRequest object has not yet 
been created on this call.
         */
        public RestRequest getRestRequest() {
-               return getRestRequestOptional().orElseThrow(()->new 
InternalServerError("RestRequest object has not yet been created."));
+               return Optional.ofNullable(rreq).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);
-       }
 
        /**
         * Returns the REST response of this REST call.
@@ -313,16 +295,7 @@ public class RestCall {
         * @return the REST response of this REST call.
         */
        public RestResponse getRestResponse() {
-               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);
+               return Optional.ofNullable(rres).orElseThrow(()->new 
InternalServerError("RestResponse object has not yet been created."));
        }
 
        /**
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 e0d5ea6..8e44a99 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
@@ -4831,6 +4831,7 @@ public class RestContext extends BeanContext {
         *      The resource object.
         *      <br>Never <jk>null</jk>.
         */
+       @BeanIgnore
        public Object getResource() {
                return resource.get();
        }
@@ -5845,9 +5846,9 @@ public class RestContext extends BeanContext {
         *
         * @return The HTTP request object, or <jk>null</jk> if it hasn't been 
created.
         */
+       @BeanIgnore
        public RestRequest getRequest() {
-               RestCall rc = call.get();
-               return rc == null ? null : 
rc.getRestRequestOptional().orElse(null);
+               return getCall().getRestRequest();
        }
 
        /**
@@ -5855,9 +5856,23 @@ public class RestContext extends BeanContext {
         *
         * @return The HTTP response object, or <jk>null</jk> if it hasn't been 
created.
         */
+       @BeanIgnore
        public RestResponse getResponse() {
+               return getCall().getRestResponse();
+       }
+
+       /**
+        * Returns the HTTP call for the current request.
+        *
+        * @return The HTTP call for the current request, never <jk>null</jk>?
+        * @throws InternalServerError If no active request exists on the 
current thread.
+        */
+       @BeanIgnore
+       public RestCall getCall() {
                RestCall rc = call.get();
-               return rc == null ? null : 
rc.getRestResponseOptional().orElse(null);
+               if (rc == null)
+                       throw new InternalServerError("No active request on 
current thread.");
+               return rc;
        }
 
        /**

Reply via email to