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

commit 156b044efa6d6a258393b3e56dc1f57946ce1624
Author: JamesBognar <[email protected]>
AuthorDate: Wed Mar 10 18:37:55 2021 -0500

    REST refactoring.
---
 .../juneau/http/entity/SerializedEntity.java       | 14 ----------
 .../juneau/http/header/SerializedHeader.java       | 30 ++------------------
 .../apache/juneau/http/part/SerializedPart.java    | 32 ++++++++++------------
 .../org/apache/juneau/rest/client/RestClient.java  |  4 +--
 .../main/java/org/apache/juneau/rest/RestCall.java |  2 +-
 .../juneau/rest/processors/DefaultProcessor.java   | 11 ++++----
 .../apache/juneau/http/SerializedHeader_Test.java  |  4 +--
 .../apache/juneau/http/SerializedPart_Test.java    |  4 +--
 8 files changed, 28 insertions(+), 73 deletions(-)

diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/entity/SerializedEntity.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/entity/SerializedEntity.java
index ef54591..28d0e3c 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/entity/SerializedEntity.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/entity/SerializedEntity.java
@@ -47,20 +47,6 @@ public class SerializedEntity extends BasicHttpEntity {
                schema = builder.schema;
        }
 
-       /**
-        * Sets the schema to use to serialize the content.
-        *
-        * <p>
-        * Value is ignored if the serializer is not schema-aware.
-        *
-        * @param value The schema.
-        * @return This object (for method chaining).
-        */
-       public SerializedEntity schema(HttpPartSchema value) {
-               this.schema = value;
-               return this;
-       }
-
        @Override /* HttpEntity */
        public void writeTo(OutputStream os) throws IOException {
                try {
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/SerializedHeader.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/SerializedHeader.java
index 8e7b9f3..d95c651 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/SerializedHeader.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/SerializedHeader.java
@@ -132,19 +132,6 @@ public class SerializedHeader extends BasicHeader {
        }
 
        /**
-        * Copies this bean and sets the serializer on it.
-        * 
-        * @param value The new serializer for the bean.  Can be <jk>null</jk>.
-        * @return Either a new bean with the serializer set, or this bean if
-        *      the value is <jk>null</jk> or the serializer was already set.
-        */
-       public SerializedHeader copyWithSerializer(HttpPartSerializerSession 
value) {
-               if (serializer == null && value != null)
-                       return copy().serializer(value);
-               return this;
-       }
-
-       /**
         * Sets the schema object that defines the format of the output.
         *
         * @param value The new value for this property.
@@ -156,27 +143,14 @@ public class SerializedHeader extends BasicHeader {
        }
 
        /**
-        * Copies this bean and sets the schema on it.
-        * 
-        * @param value The new schema for the bean.  Can be <jk>null</jk>.
-        * @return Either a new bean with the schema set, or this bean if
-        *      the value is <jk>null</jk> or the schema was already set.
-        */
-       public SerializedHeader copyWithSchema(HttpPartSchema value) {
-               if (schema == null && value != null)
-                       return copy().schema(value);
-               return this;
-       }
-
-       /**
         * Copies this bean and sets the serializer and schema on it.
-        * 
+        *
         * @param serializer The new serializer for the bean.  Can be 
<jk>null</jk>.
         * @param schema The new schema for the bean.  Can be <jk>null</jk>.
         * @return Either a new bean with the serializer set, or this bean if
         *      both values are <jk>null</jk> or the serializer and schema were 
already set.
         */
-       public SerializedHeader 
copyWithSerializerAndSchema(HttpPartSerializerSession serializer, 
HttpPartSchema schema) {
+       public SerializedHeader copyWith(HttpPartSerializerSession serializer, 
HttpPartSchema schema) {
                if ((this.serializer == null && serializer != null) || 
(this.schema == null && schema != null)) {
                        SerializedHeader h = copy();
                        if (serializer != null)
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/part/SerializedPart.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/part/SerializedPart.java
index fabe075..64ac610 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/part/SerializedPart.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/part/SerializedPart.java
@@ -153,18 +153,6 @@ public class SerializedPart extends BasicPart implements 
Headerable {
        }
 
        /**
-        * Sets the serializer to use for serializing the value to a string 
value if it's not already set on this object.
-        *
-        * @param value The new value for this property.
-        * @return This object (for method chaining).
-        */
-       public SerializedPart serializerIfNotSet(HttpPartSerializerSession 
value) {
-               if (serializer == null)
-                       serializer = value;
-               return this;
-       }
-
-       /**
         * Sets the schema object that defines the format of the output.
         *
         * @param value The new value for this property.
@@ -176,14 +164,22 @@ public class SerializedPart extends BasicPart implements 
Headerable {
        }
 
        /**
-        * Sets the schema object that defines the format of the output if it's 
not already set on this object.
+        * Copies this bean and sets the serializer and schema on it.
         *
-        * @param value The new value for this property.
-        * @return This object (for method chaining).
+        * @param serializer The new serializer for the bean.  Can be 
<jk>null</jk>.
+        * @param schema The new schema for the bean.  Can be <jk>null</jk>.
+        * @return Either a new bean with the serializer set, or this bean if
+        *      both values are <jk>null</jk> or the serializer and schema were 
already set.
         */
-       public SerializedPart schemaIfNotSet(HttpPartSchema value) {
-               if (schema == null)
-                       schema = value;
+       public SerializedPart copyWith(HttpPartSerializerSession serializer, 
HttpPartSchema schema) {
+               if ((this.serializer == null && serializer != null) || 
(this.schema == null && schema != null)) {
+                       SerializedPart p = copy();
+                       if (serializer != null)
+                               p.serializer(serializer);
+                       if (schema != null)
+                               p.schema(schema);
+                       return p;
+               }
                return this;
        }
 
diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
index 70d8149..868664e 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
@@ -2125,9 +2125,9 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
 
        private static Object buildBuilders(Object o, HttpPartSerializerSession 
ss) {
                if (o instanceof SerializedHeader)
-                       return ((SerializedHeader)o).copyWithSerializer(ss);
+                       return ((SerializedHeader)o).copyWith(ss, null);
                if (o instanceof SerializedPart)
-                       return 
((SerializedPart)o).copy().serializerIfNotSet(ss);
+                       return ((SerializedPart)o).copy().copyWith(ss, null);
                return o;
        }
 
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 3761179..211d9a3 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
@@ -228,7 +228,7 @@ public class RestCall {
                        BasicUriHeader x = (BasicUriHeader)h;
                        addResponseHeader(x.getName(), 
rreq.getUriResolver().resolve(x.getValue()));
                } else if (h instanceof SerializedHeader) {
-                       SerializedHeader x = 
((SerializedHeader)h).copyWithSerializer(rreq.getPartSerializerSession());
+                       SerializedHeader x = 
((SerializedHeader)h).copyWith(rreq.getPartSerializerSession(), null);
                        addResponseHeader(x.getName(), 
rreq.getUriResolver().resolve(x.getValue()));
                } else {
                        addResponseHeader(h.getName(), h.getValue());
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/processors/DefaultProcessor.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/processors/DefaultProcessor.java
index 45cc06d..568ea3c 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/processors/DefaultProcessor.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/processors/DefaultProcessor.java
@@ -106,11 +106,11 @@ public class DefaultProcessor implements 
ResponseProcessor {
                                                                
res.setHeader(new HttpPart(k, RESPONSE_HEADER, partSchema.getProperty(k), 
hm.getSerializerSession().orElse(ps), v));
                                                        } else if (ho2 
instanceof SerializedHeader) {
                                                                
SerializedHeader x = ((SerializedHeader)ho2);
-                                                               x = 
x.copyWithSerializerAndSchema(ps, partSchema.getProperty(x.getName()));
+                                                               x = 
x.copyWith(ps, partSchema.getProperty(x.getName()));
                                                                
res.setHeader(x.getName(), x.getValue());
                                                        } else if (ho2 
instanceof SerializedPart) {
-                                                               SerializedPart 
x = ((SerializedPart)ho2).copy().serializerIfNotSet(ps);
-                                                               
x.schemaIfNotSet(partSchema.getProperty(x.getName()));
+                                                               SerializedPart 
x = ((SerializedPart)ho2);
+                                                               x = 
x.copyWith(ps, partSchema.getProperty(x.getName()));
                                                                
res.setHeader(x.getName(), x.getValue());
                                                        } else if (ho2 
instanceof BasicUriHeader) {
                                                                BasicUriHeader 
x = (BasicUriHeader)ho2;
@@ -127,11 +127,10 @@ public class DefaultProcessor implements 
ResponseProcessor {
                                                }
                                        } else {
                                                if (ho instanceof 
SerializedHeader) {
-                                                       SerializedHeader x = 
((SerializedHeader)ho).copyWithSerializerAndSchema(ps, schema);
+                                                       SerializedHeader x = 
((SerializedHeader)ho).copyWith(ps, schema);
                                                        
res.setHeader(x.getName(), x.getValue());
                                                } else if (ho instanceof 
SerializedPart) {
-                                                       SerializedPart x = 
((SerializedPart)ho).copy().serializerIfNotSet(ps);
-                                                       
x.schemaIfNotSet(schema);
+                                                       SerializedPart x = 
((SerializedPart)ho).copyWith(ps, schema);
                                                        
res.setHeader(x.getName(), x.getValue());
                                                } else if (ho instanceof 
Header) {
                                                        Header x = (Header)ho;
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/http/SerializedHeader_Test.java 
b/juneau-utest/src/test/java/org/apache/juneau/http/SerializedHeader_Test.java
index 746cd16..a29a36f 100644
--- 
a/juneau-utest/src/test/java/org/apache/juneau/http/SerializedHeader_Test.java
+++ 
b/juneau-utest/src/test/java/org/apache/juneau/http/SerializedHeader_Test.java
@@ -55,9 +55,9 @@ public class SerializedHeader_Test {
                assertString(x2.getValue()).is("bar,baz");
                SerializedHeader x3 = 
serializedHeader("Foo",list("bar","baz")).serializer(OAPI_SERIALIZER).serializer((HttpPartSerializerSession)null);
                assertString(x3.getValue()).is("['bar','baz']");
-               SerializedHeader x4 = 
serializedHeader("Foo",list("bar","baz")).serializer(OAPI_SERIALIZER).copyWithSerializer((HttpPartSerializerSession)null);
+               SerializedHeader x4 = 
serializedHeader("Foo",list("bar","baz")).serializer(OAPI_SERIALIZER).copyWith(null,null);
                assertString(x4.getValue()).is("bar,baz");
-               SerializedHeader x5 = 
serializedHeader("Foo",list("bar","baz")).copyWithSerializer(OAPI_SERIALIZER.createPartSession(null));
+               SerializedHeader x5 = 
serializedHeader("Foo",list("bar","baz")).copyWith(OAPI_SERIALIZER.createPartSession(null),null);
                assertString(x5.getValue()).is("bar,baz");
        }
 
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/http/SerializedPart_Test.java 
b/juneau-utest/src/test/java/org/apache/juneau/http/SerializedPart_Test.java
index 56972d7..e21bd34 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/http/SerializedPart_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/http/SerializedPart_Test.java
@@ -56,9 +56,9 @@ public class SerializedPart_Test {
                assertString(x2.getValue()).is("bar,baz");
                SerializedPart x3 = 
serializedPart("Foo",list("bar","baz")).serializer(OAPI_SERIALIZER).serializer((HttpPartSerializerSession)null);
                assertString(x3.getValue()).is("['bar','baz']");
-               SerializedPart x4 = 
serializedPart("Foo",list("bar","baz")).serializer(OAPI_SERIALIZER).serializerIfNotSet((HttpPartSerializerSession)null);
+               SerializedPart x4 = 
serializedPart("Foo",list("bar","baz")).serializer(OAPI_SERIALIZER).copyWith(null,null);
                assertString(x4.getValue()).is("bar,baz");
-               SerializedPart x5 = 
serializedPart("Foo",list("bar","baz")).serializerIfNotSet(OAPI_SERIALIZER.createPartSession(null));
+               SerializedPart x5 = 
serializedPart("Foo",list("bar","baz")).copyWith(OAPI_SERIALIZER.createPartSession(null),null);
                assertString(x5.getValue()).is("bar,baz");
        }
 

Reply via email to