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 3a08483 REST refactoring.
3a08483 is described below
commit 3a084839683a029bad7ba851fb3792713ca67ef2
Author: JamesBognar <[email protected]>
AuthorDate: Wed Feb 17 10:06:14 2021 -0500
REST refactoring.
---
.../apache/juneau/rest/client/ResponseBody.java | 243 ---------------------
.../rest/client/RestClient_Response_Body_Test.java | 36 ---
2 files changed, 279 deletions(-)
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseBody.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseBody.java
index fee02de..72a1db2 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseBody.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseBody.java
@@ -545,56 +545,6 @@ public class ResponseBody implements HttpEntity {
}
/**
- * Same as {@link #as(Type,Type...)} but sets the value in a mutable
for fluent calls.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Parse into a linked-list of strings and also pipe to an
output stream.</jc>
- * Mutable<List<String>> <jv>mutable</jv> =
Mutable.<jsm>create()</jsm>;
- *
- * <jv>client</jv>
- * .get(<jsf>URI</jsf>)
- * .run()
- * .cache()
- * .getBody().as(<jv>mutable</jv>,
LinkedList.<jk>class</jk>, String.<jk>class</jk>)
- * .getBody().pipeTo(outputStream)
- * .assertStatus().is(200);
- *
- * List<String> <jv>list</jv> = <jv>mutable</jv>.get();
- * </p>
- *
- * <ul class='notes'>
- * <li>
- * If {@link #cache()} or {@link RestResponse#cacheBody()}
has been called, this method can be can be called multiple times and/or
combined with
- * other methods that retrieve the content of the
response. Otherwise a {@link RestCallException}
- * with an inner {@link IllegalStateException} will be
thrown.
- * <li>
- * The input stream is automatically closed after this
call.
- * </ul>
- *
- * @param <T> The class type of the object to create.
- * @param m The mutable to set the parsed value in.
- * @param type
- * The object type to create.
- * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
- * @param args
- * The type arguments of the class if it's a collection or map.
- * <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
- * <br>Ignored if the main type is not a map or collection.
- * @return The response object (for method chaining).
- * @throws RestCallException
- * <ul>
- * <li>If the input contains a syntax error or is
malformed, or is not valid for the specified type.
- * <li>If a connection error occurred.
- * </ul>
- * @see BeanSession#getClassMeta(Class) for argument syntax for maps
and collections.
- */
- public <T> RestResponse as(Mutable<T> m, Type type, Type...args) throws
RestCallException {
- m.set(as(type, args));
- return response;
- }
-
- /**
* Same as {@link #as(Type,Type...)} except optimized for a
non-parameterized class.
*
* <p>
@@ -649,51 +599,6 @@ public class ResponseBody implements HttpEntity {
}
/**
- * Same as {@link #as(Class)} but sets the value in a mutable for
fluent calls.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Parse into a bean and also pipe to an output stream.</jc>
- * Mutable<MyBean> <jv>mutable</jv> =
Mutable.<jsm>create()</jsm>;
- *
- * <jv>client</jv>
- * .get(<jsf>URI</jsf>)
- * .run()
- * .cache()
- * .getBody().as(<jv>mutable</jv>, MyBean.<jk>class</jk>)
- * .getBody().pipeTo(<jv>outputStream</jv>)
- * .assertStatus().is(200);
- *
- * MyBean <jv>bean</jv> = <jv>mutable</jv>.get();
- * </p>
- *
- * <ul class='notes'>
- * <li>
- * If {@link #cache()} or {@link RestResponse#cacheBody()}
has been called, this method can be can be called multiple times and/or
combined with
- * other methods that retrieve the content of the
response. Otherwise a {@link RestCallException}
- * with an inner {@link IllegalStateException} will be
thrown.
- * <li>
- * The input stream is automatically closed after this
call.
- * </ul>
- *
- * @param <T> The class type of the object to create.
- * @param m The mutable to set the parsed value in.
- * @param type
- * The object type to create.
- * @return The response object (for method chaining).
- * @throws RestCallException
- * <ul>
- * <li>If the input contains a syntax error or is
malformed, or is not valid for the specified type.
- * <li>If a connection error occurred.
- * </ul>
- * @see BeanSession#getClassMeta(Class) for argument syntax for maps
and collections.
- */
- public <T> RestResponse as(Mutable<T> m, Class<T> type) throws
RestCallException {
- m.set(as(type));
- return response;
- }
-
- /**
* Same as {@link #as(Class)} except allows you to predefine complex
data types using the {@link ClassMeta} API.
*
* <h5 class='section'>Examples:</h5>
@@ -831,52 +736,6 @@ public class ResponseBody implements HttpEntity {
}
/**
- * Identical to {@link #as(ClassMeta)} but sets the value in a mutable
for fluent calls.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Parse into a bean and also pipe to an output stream.</jc>
- * Mutable<List<MyBean>> <jv>mutable</jv> =
Mutable.<jsm>create()</jsm>;
- * ClassMeta<List<MyBean>> <jv>cm</jv> =
BeanContext.<jsf>DEFAULT</jsf>.getClassMeta(LinkedList.<jk>class</jk>,
MyBean.<jk>class</jk>);
- *
- * <jv>client</jv>
- * .get(<jsf>URI</jsf>)
- * .run()
- * .cache()
- * .getBody().as(<jv>mutable</jv>, <jv>cm</jv>)
- * .getBody().pipeTo(<jv>outputStream</jv>)
- * .assertStatus().is(200);
- *
- * MyBean <jv>bean</jv> = <jv>mutable</jv>.get();
- * </p>
- *
- * <ul class='notes'>
- * <li>
- * If {@link #cache()} or {@link RestResponse#cacheBody()}
has been called, this method can be can be called multiple times and/or
combined with
- * other methods that retrieve the content of the
response. Otherwise a {@link RestCallException}
- * with an inner {@link IllegalStateException} will be
thrown.
- * <li>
- * The input stream is automatically closed after this
call.
- * </ul>
- *
- * @param <T> The class type of the object to create.
- * @param m The mutable to set the parsed value in.
- * @param type
- * The object type to create.
- * @return The response object (for method chaining).
- * @throws RestCallException
- * <ul>
- * <li>If the input contains a syntax error or is
malformed, or is not valid for the specified type.
- * <li>If a connection error occurred.
- * </ul>
- * @see BeanSession#getClassMeta(Class) for argument syntax for maps
and collections.
- */
- public <T> RestResponse as(Mutable<T> m, ClassMeta<T> type) throws
RestCallException {
- m.set(as(type));
- return response;
- }
-
- /**
* Same as {@link #as(Class)} but allows you to run the call
asynchronously.
*
* <ul class='notes'>
@@ -1009,30 +868,6 @@ public class ResponseBody implements HttpEntity {
}
/**
- * Same as {@link #asString()} but sets the value in a mutable for
fluent calls.
- *
- * <ul class='notes'>
- * <li>
- * If no charset was found on the
<code>Content-Type</code> response header, <js>"UTF-8"</js> is assumed.
- * <li>
- * This method automatically calls {@link #cache()} so
that the body can be retrieved multiple times.
- * <li>
- * The input stream is automatically closed after this
call.
- * </ul>
- *
- * @param m The mutable to set the value in.
- * @return The response object (for method chaining).
- * @throws RestCallException
- * <ul>
- * <li>If a connection error occurred.
- * </ul>
- */
- public RestResponse asString(Mutable<String> m) throws
RestCallException {
- m.set(asString());
- return response;
- }
-
- /**
* Same as {@link #asString()} but allows you to run the call
asynchronously.
*
* <ul class='notes'>
@@ -1062,32 +897,6 @@ public class ResponseBody implements HttpEntity {
}
/**
- * Same as {@link #asStringFuture()} but sets the value in a mutable
for fluent calls.
- *
- * <ul class='notes'>
- * <li>
- * If no charset was found on the
<code>Content-Type</code> response header, <js>"UTF-8"</js> is assumed.
- * <li>
- * If {@link #cache()} or {@link RestResponse#cacheBody()}
has been called, this method can be can be called multiple times and/or
combined with
- * other methods that retrieve the content of the
response. Otherwise a {@link RestCallException}
- * with an inner {@link IllegalStateException} will be
thrown.
- * <li>
- * The input stream is automatically closed after this
call.
- * </ul>
- *
- * @param m The mutable to set the value in.
- * @return The response object (for method chaining).
- * @throws RestCallException If the executor service was not defined.
- * @see
- * RestClientBuilder#executorService(ExecutorService, boolean) for
defining the executor service for creating
- * {@link Future Futures}.
- */
- public RestResponse asStringFuture(Mutable<Future<String>> m) throws
RestCallException {
- m.set(asStringFuture());
- return response;
- }
-
- /**
* Same as {@link #asString()} but truncates the string to the
specified length.
*
* <p>
@@ -1105,25 +914,6 @@ public class ResponseBody implements HttpEntity {
}
/**
- * Same as {@link #asAbbreviatedString(int)} but sets the value in a
mutable for fluent calls.
- *
- * <p>
- * If truncation occurs, the string will be suffixed with
<js>"..."</js>.
- *
- * @param m The mutable to set the value in.
- * @param length The max length of the returned string.
- * @return The response object (for method chaining).
- * @throws RestCallException
- * <ul>
- * <li>If a connection error occurred.
- * </ul>
- */
- public RestResponse asAbbreviatedString(Mutable<String> m, int length)
throws RestCallException {
- m.set(asAbbreviatedString(length));
- return response;
- }
-
- /**
* Parses the output from the body into the specified type and then
wraps that in a {@link PojoRest}.
*
* <p>
@@ -1142,23 +932,6 @@ public class ResponseBody implements HttpEntity {
}
/**
- * Same as {@link #asPojoRest(Class)} but sets the value in a mutable
for fluent calls.
- *
- * @param m The mutable to set the value in.
- * @param innerType The class type of the POJO being wrapped.
- * @return The response object (for method chaining).
- * @throws RestCallException
- * <ul>
- * <li>If the input contains a syntax error or is
malformed, or is not valid for the specified type.
- * <li>If a connection error occurred.
- * </ul>
- */
- public RestResponse asPojoRest(Mutable<PojoRest> m, Class<?> innerType)
throws RestCallException {
- m.set(asPojoRest(innerType));
- return response;
- }
-
- /**
* Converts the output from the connection into an {@link OMap} and
then wraps that in a {@link PojoRest}.
*
* <p>
@@ -1176,22 +949,6 @@ public class ResponseBody implements HttpEntity {
}
/**
- * Same as {@link #asPojoRest()} but sets the value in a mutable for
fluent calls.
- *
- * @param m The mutable to set the value in.
- * @return The response object (for method chaining).
- * @throws RestCallException
- * <ul>
- * <li>If the input contains a syntax error or is
malformed, or is not valid for the specified type.
- * <li>If a connection error occurred.
- * </ul>
- */
- public RestResponse asPojoRest(Mutable<PojoRest> m) throws
RestCallException {
- m.set(asPojoRest());
- return response;
- }
-
- /**
* Converts the contents of the response body to a string and then
matches the specified pattern against it.
*
* <h5 class='section'>Example:</h5>
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Body_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Body_Test.java
index 6d42d29..3952da5 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Body_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Body_Test.java
@@ -212,17 +212,9 @@ public class RestClient_Response_Body_Test {
List<Integer> x1 =
testClient().entity(stringEntity("[1,2]")).get().run().getBody().as(List.class,Integer.class);
assertObject(x1).asJson().is("[1,2]");
- Mutable<List<Integer>> x2 = mutable();
-
testClient().entity(stringEntity("[1,2]")).get().run().getBody().as(x2,List.class,Integer.class);
- assertObject(x2.get()).asJson().is("[1,2]");
-
ABean x3 =
testClient().entity(stringEntity("{f:1}")).get().run().getBody().as(ABean.class);
assertObject(x3).asJson().is("{f:1}");
- Mutable<ABean> x4 = mutable();
-
testClient().entity(stringEntity("{f:1}")).get().run().getBody().as(x4,ABean.class);
- assertObject(x4.get()).asJson().is("{f:1}");
-
HttpEntity x5 =
testClient().entity(stringEntity("{f:1}")).get().run().getBody().as(ResponseBody.class);
assertTrue(x5 instanceof ResponseBody);
@@ -234,10 +226,6 @@ public class RestClient_Response_Body_Test {
assertThrown(()->plainTestClient().entity(stringEntity("foo")).headers(header("Content-Type","foo")).get().run().getBody().as(A7c.class)).exists().contains("Unsupported
media-type","'foo'");
assertThrown(()->testClient().entity(stringEntity("")).get().run().getBody().as(A7c.class)).contains("foo");
- Mutable<ABean> x7 = mutable();
-
testClient().entity(stringEntity("{f:1}")).get().run().getBody().as(x7,cm(ABean.class));
- assertObject(x7.get()).asJson().is("{f:1}");
-
Future<ABean> x8 =
testClient().entity(stringEntity("{f:1}")).get().run().getBody().asFuture(ABean.class);
assertObject(x8.get()).asJson().is("{f:1}");
@@ -252,38 +240,18 @@ public class RestClient_Response_Body_Test {
assertThrown(()->testClient().entity(new
InputStreamEntity(badStream())).get().run().getBody().asString()).contains("foo");
- Mutable<String> x15 = mutable();
-
testClient().entity(stringEntity("{f:1}")).get().run().getBody().asString(x15);
- assertString(x15.get()).is("{f:1}");
-
Future<String> x16 =
testClient().entity(stringEntity("{f:1}")).get().run().getBody().asStringFuture();
assertString(x16.get()).is("{f:1}");
- Mutable<Future<String>> x17 = mutable();
-
testClient().entity(stringEntity("{f:1}")).get().run().getBody().asStringFuture(x17);
- assertString(x17.get().get()).is("{f:1}");
-
String x18 =
testClient().entity(stringEntity("12345")).get().run().getBody().asAbbreviatedString(4);
assertString(x18).is("1...");
- Mutable<String> x19 = mutable();
-
testClient().entity(stringEntity("12345")).get().run().getBody().asAbbreviatedString(x19,4);
- assertString(x19.get()).is("1...");
-
PojoRest x20 =
testClient().entity(stringEntity("{f:1}")).get().run().getBody().asPojoRest(ABean.class);
assertString(x20.get("f")).is("1");
- Mutable<PojoRest> x21 = mutable();
-
testClient().entity(stringEntity("{f:1}")).get().run().getBody().asPojoRest(x21,ABean.class);
- assertString(x21.get().get("f")).is("1");
-
PojoRest x22 =
testClient().entity(stringEntity("{f:1}")).get().run().getBody().asPojoRest();
assertString(x22.get("f")).is("1");
- Mutable<PojoRest> x23 = mutable();
-
testClient().entity(stringEntity("{f:1}")).get().run().getBody().asPojoRest(x23);
- assertString(x23.get().get("f")).is("1");
-
Matcher x24 =
testClient().entity(stringEntity("foo=123")).get().run().getBody().asMatcher(Pattern.compile("foo=(.*)"));
assertTrue(x24.matches());
assertString(x24.group(1)).is("123");
@@ -388,8 +356,4 @@ public class RestClient_Response_Body_Test {
}
};
}
-
- private static <T> Mutable<T> mutable() {
- return Mutable.create();
- }
}