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 410dfebf2 Rest server code cleanup.
410dfebf2 is described below

commit 410dfebf2e003bcfc1257e0e647af58197568bee
Author: JamesBognar <[email protected]>
AuthorDate: Sat Aug 20 13:10:15 2022 -0400

    Rest server code cleanup.
---
 .../juneau/rest/httppart/RequestFormParam.java     | 82 +++++++++++++++++++---
 .../apache/juneau/rest/httppart/RequestHeader.java | 26 +------
 .../juneau/rest/httppart/RequestHttpPart.java      | 37 +++++++---
 .../juneau/rest/httppart/RequestPathParam.java     | 25 +------
 .../juneau/rest/httppart/RequestQueryParam.java    | 30 +-------
 5 files changed, 101 insertions(+), 99 deletions(-)

diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestFormParam.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestFormParam.java
index 3cc75338f..47bd93cc6 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestFormParam.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestFormParam.java
@@ -17,6 +17,7 @@ import static org.apache.juneau.internal.ThrowableUtils.*;
 
 import java.io.*;
 import java.lang.reflect.*;
+import java.util.*;
 import java.util.regex.*;
 
 import org.apache.http.*;
@@ -93,7 +94,6 @@ import org.apache.juneau.rest.*;
 public class RequestFormParam extends RequestHttpPart implements NameValuePair 
{
 
        private final javax.servlet.http.Part part;
-       private String value;
 
        /**
         * Constructor.
@@ -102,7 +102,7 @@ public class RequestFormParam extends RequestHttpPart 
implements NameValuePair {
         * @param part The HTTP part.
         */
        public RequestFormParam(RestRequest request, javax.servlet.http.Part 
part) {
-               super(FORMDATA, request, part.getName());
+               super(FORMDATA, request, part.getName(), null);
                this.part = part;
        }
 
@@ -114,8 +114,7 @@ public class RequestFormParam extends RequestHttpPart 
implements NameValuePair {
         * @param value The parameter value.
         */
        public RequestFormParam(RestRequest request, String name, String value) 
{
-               super(FORMDATA, request, name);
-               this.value = value;
+               super(FORMDATA, request, name, value);
                this.part = null;
        }
 
@@ -134,17 +133,78 @@ public class RequestFormParam extends RequestHttpPart 
implements NameValuePair {
                return value;
        }
 
+       /**
+        * Returns this part value as an input stream.
+        *
+        * @return This part value as an input stream.
+        * @throws IOException If an error occurs in retrieving the content.
+        */
+       public InputStream getStream() throws IOException {
+               if (value != null)
+                       return new 
ByteArrayInputStream(value.getBytes(IOUtils.UTF8));
+               return part.getInputStream();
+       }
 
        /**
-        * Sets a default value for this part.
+        * Returns the content type of this part.
         *
-        * @param def The default value.
-        * @return This object.
+        * @return The content type of this part, or <jk>null</jk> if not known.
         */
-       public RequestFormParam def(String def) {
-               if (getValue() == null)
-                       value = def;
-               return this;
+       public String getContentType() {
+               return (part == null ? null : part.getContentType());
+       }
+
+       /**
+        * Returns the value of the specified mime header as a String.
+        *
+        * <p>
+        * If the Part did not include a header of the specified name, this 
method returns null.
+        * If there are multiple headers with the same name, this method 
returns the first header in the part.
+        * The header name is case insensitive.
+        * You can use this method with any request header.
+        *
+        * @param name The header name.
+        * @return The value of the specified mime header as a String.
+        */
+       public String getHeader(String name) {
+               return part.getHeader(name);
+       }
+
+       /**
+        * Returns the header names of this param.
+        *
+        * @return The header names of this param.
+        */
+       public Collection<String> getHeaderNames() {
+               return part.getHeaderNames();
+       }
+
+       /**
+        * Returns the values of the param header with the given name.
+        *
+        * @param name The param name.
+        * @return The values of the param header with the given name.
+        */
+       public Collection<String> getHeaders(String name) {
+               return part.getHeaders(name);
+       }
+
+       /**
+        * Returns the size of this file.
+        *
+        * @return A long specifying the size of this part, in bytes.
+        */
+       public long getSize() {
+               return part.getSize();
+       }
+
+       /**
+        * Returns the file name specified by the client.
+        *
+        * @return The file name specified by the client.
+        */
+       public String getSubmittedFileName() {
+               return part.getSubmittedFileName();
        }
 
        // <FluentSetters>
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestHeader.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestHeader.java
index 0547a3f9a..0d08b535a 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestHeader.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestHeader.java
@@ -94,8 +94,6 @@ import org.apache.juneau.rest.*;
  */
 public class RequestHeader extends RequestHttpPart implements Header {
 
-       private String value;
-
        /**
         * Constructor.
         *
@@ -104,29 +102,7 @@ public class RequestHeader extends RequestHttpPart 
implements Header {
         * @param value The header value.
         */
        public RequestHeader(RestRequest request, String name, String value) {
-               super(HEADER, request, name);
-               this.value = value;
-       }
-
-       /**
-        * Sets a default value for this part.
-        *
-        * @param def The default value.
-        * @return This object.
-        */
-       public RequestHeader def(String def) {
-               if (value == null)
-                       value = def;
-               return this;
-       }
-
-       
//------------------------------------------------------------------------------------------------------------------
-       // Retrievers
-       
//------------------------------------------------------------------------------------------------------------------
-
-       @Override /* RequestHttpPart */
-       public String getValue() {
-               return value;
+               super(HEADER, request, name, value);
        }
 
        /**
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestHttpPart.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestHttpPart.java
index 19dea2af8..40eb995c1 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestHttpPart.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestHttpPart.java
@@ -50,25 +50,28 @@ import org.apache.juneau.rest.*;
  * </ul>
  */
 @FluentSetters
-public abstract class RequestHttpPart {
+public class RequestHttpPart {
 
        private final HttpPartType partType;
        private final String name;
        private final RestRequest request;
        private HttpPartParserSession parser;
        private HttpPartSchema schema;
+       String value;
 
        /**
         * Constructor.
         *
         * @param partType The HTTP part type.
         * @param request The request object.
-        * @param name The header name.
+        * @param name The part name.
+        * @param value The part value.
         */
-       public RequestHttpPart(HttpPartType partType, RestRequest request, 
String name) {
+       public RequestHttpPart(HttpPartType partType, RestRequest request, 
String name, String value) {
                this.partType = partType;
                this.request = request;
                this.name = name;
+               this.value = value;
                parser(null);
        }
 
@@ -109,10 +112,31 @@ public abstract class RequestHttpPart {
                return this;
        }
 
+       /**
+        * Sets a default value for this part.
+        *
+        * @param def The default value.
+        * @return This object.
+        */
+       public RequestHttpPart def(String def) {
+               if (value == null)
+                       value = def;
+               return this;
+       }
+
        
//------------------------------------------------------------------------------------------------------------------
        // Retrievers
        
//------------------------------------------------------------------------------------------------------------------
 
+       /**
+        * Returns the value of this part.
+        *
+        * @return The value of this part.
+        */
+       public String getValue() {
+               return value;
+       }
+
        /**
         * Returns <jk>true</jk> if this part exists on the request.
         *
@@ -522,13 +546,6 @@ public abstract class RequestHttpPart {
                return name;
        }
 
-       /**
-        * Gets the value of this part.
-        *
-        * @return The value of this part, may be <jk>null</jk>.
-        */
-       public abstract String getValue();
-
        @Override /* Object */
        public String toString() {
                return getName() + "=" + getValue();
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestPathParam.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestPathParam.java
index 305212dbd..dc8e7d805 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestPathParam.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestPathParam.java
@@ -89,8 +89,6 @@ import org.apache.juneau.rest.*;
  */
 public class RequestPathParam extends RequestHttpPart implements NameValuePair 
{
 
-       private String value;
-
        /**
         * Constructor.
         *
@@ -99,31 +97,10 @@ public class RequestPathParam extends RequestHttpPart 
implements NameValuePair {
         * @param value The parameter value.
         */
        public RequestPathParam(RestRequest request, String name, String value) 
{
-               super(PATH, request, name);
+               super(PATH, request, name, value);
                this.value = value;
        }
 
-       /**
-        * Sets a default value for this part.
-        *
-        * @param def The default value.
-        * @return This object.
-        */
-       public RequestPathParam def(String def) {
-               if (value == null)
-                       value = def;
-               return this;
-       }
-
-       
//------------------------------------------------------------------------------------------------------------------
-       // Retrievers
-       
//------------------------------------------------------------------------------------------------------------------
-
-       @Override /* RequestHttpPart */
-       public String getValue() {
-               return value;
-       }
-
        // <FluentSetters>
 
        @Override /* GENERATED */
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestQueryParam.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestQueryParam.java
index 4f7708957..53a02e70e 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestQueryParam.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/httppart/RequestQueryParam.java
@@ -89,8 +89,6 @@ import org.apache.juneau.rest.*;
  */
 public class RequestQueryParam extends RequestHttpPart implements 
NameValuePair {
 
-       private String value;
-
        /**
         * Constructor.
         *
@@ -99,35 +97,9 @@ public class RequestQueryParam extends RequestHttpPart 
implements NameValuePair
         * @param value The parameter value.
         */
        public RequestQueryParam(RestRequest request, String name, String 
value) {
-               super(QUERY, request, name);
-               this.value = value;
+               super(QUERY, request, name, value);
        }
 
-       /**
-        * Sets a default value for this part.
-        *
-        * @param def The default value.
-        * @return This object.
-        */
-       public RequestQueryParam def(String def) {
-               if (value == null)
-                       value = def;
-               return this;
-       }
-
-       
//------------------------------------------------------------------------------------------------------------------
-       // Retrievers
-       
//------------------------------------------------------------------------------------------------------------------
-
-       @Override /* RequestHttpPart */
-       public String getValue() {
-               return value;
-       }
-
-       
//------------------------------------------------------------------------------------------------------------------
-       // Assertions
-       
//------------------------------------------------------------------------------------------------------------------
-
        // <FluentSetters>
 
        @Override /* GENERATED */

Reply via email to