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 5d439b9 RestClient tests.
5d439b9 is described below
commit 5d439b97d70382e237bd093f6606c711835da16b
Author: JamesBognar <[email protected]>
AuthorDate: Mon Jun 29 16:58:49 2020 -0400
RestClient tests.
---
.../rest/client2/Remote_BodyAnnotation_Test.java | 12 +-
.../rest/client2/Remote_CommonInterfaces_Test.java | 24 ++--
.../client2/Remote_FormDataAnnotation_Test.java | 68 +++++-----
.../rest/client2/Remote_HeaderAnnotation_Test.java | 60 ++++-----
.../rest/client2/Remote_PathAnnotation_Test.java | 52 ++++----
.../rest/client2/Remote_QueryAnnotation_Test.java | 68 +++++-----
.../Remote_RemoteMethodAnnotation_Test.java | 16 +--
.../client2/Remote_RequestAnnotation_Test.java | 20 +--
.../client2/Remote_ResponseAnnotation_Test.java | 4 +-
.../apache/juneau/rest/client2/Remote_Test.java | 20 +--
.../rest/client2/RestClient_BasicCalls_Test.java | 16 ++-
.../client2/RestClient_CallbackStrings_Test.java | 4 +-
.../rest/client2/RestClient_FormData_Test.java | 3 +
.../rest/client2/RestClient_Headers_Test.java | 34 +++++
.../juneau/rest/client2/RestClient_Query_Test.java | 5 +
.../juneau/rest/client2/RestClient_Test.java | 145 ++++++++++++++++++++-
.../juneau/rest/client2/RrpcInterfaceTest.java | 4 +-
.../org/apache/juneau/rest/client2/RestClient.java | 6 +-
.../apache/juneau/rest/client2/RestRequest.java | 98 +++++++-------
19 files changed, 425 insertions(+), 234 deletions(-)
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_BodyAnnotation_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_BodyAnnotation_Test.java
index 9ba9674..6e2a6ca 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_BodyAnnotation_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_BodyAnnotation_Test.java
@@ -55,9 +55,9 @@ public class Remote_BodyAnnotation_Test {
}
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Basic tests - JSON
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest(parsers=JsonParser.class)
public static class A {
@@ -151,9 +151,9 @@ public class Remote_BodyAnnotation_Test {
assertEquals("foo=bar",x.postX10(new
NameValuePairs().append("foo","bar")));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Basic tests - OpenAPI
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class B implements BasicOpenApiRest {
@@ -246,9 +246,9 @@ public class Remote_BodyAnnotation_Test {
assertEquals("foo=bar",x.postX10(new
NameValuePairs().append("foo","bar")));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Basic tests - OpenAPI, overridden Content-Type
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class C {
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_CommonInterfaces_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_CommonInterfaces_Test.java
index 3d63786..d678ea4 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_CommonInterfaces_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_CommonInterfaces_Test.java
@@ -37,9 +37,9 @@ import org.junit.*;
@FixMethodOrder(NAME_ASCENDING)
public class Remote_CommonInterfaces_Test {
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Simple tests, split annotations.
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote
public static interface A {
@@ -75,9 +75,9 @@ public class Remote_CommonInterfaces_Test {
assertEquals("foo",x.getX3("foo"));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Simple tests, combined annotations.
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote
@Rest
@@ -110,9 +110,9 @@ public class Remote_CommonInterfaces_Test {
assertEquals("foo",x.getX3("foo"));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Standard responses
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote
@Rest
@@ -197,9 +197,9 @@ public class Remote_CommonInterfaces_Test {
assertEquals("Use Proxy",x.useProxy().toString());
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// ReaderResource and StreamResource responses
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote
@Rest
@@ -234,9 +234,9 @@ public class Remote_CommonInterfaces_Test {
assertEquals("text/foo",rr.getContentType().toString());
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Predefined exceptions
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote
@Rest
@@ -866,9 +866,9 @@ public class Remote_CommonInterfaces_Test {
assertEquals("foo",IOUtils.read(x.inputStream()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Helper responses
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote
@Rest
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_FormDataAnnotation_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_FormDataAnnotation_Test.java
index 4731276..9607d3d 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_FormDataAnnotation_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_FormDataAnnotation_Test.java
@@ -61,9 +61,9 @@ public class Remote_FormDataAnnotation_Test {
}
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Basic tests
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class A {
@@ -134,9 +134,9 @@ public class Remote_FormDataAnnotation_Test {
assertEquals("{f:'1'}",x.postX25(Bean2.create()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @FormData(_default/allowEmptyValue)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class B {
@@ -167,9 +167,9 @@ public class Remote_FormDataAnnotation_Test {
assertEquals("{x:''}",x.postX4(""));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @FormData(collectionFormat)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class C {
@@ -220,9 +220,9 @@ public class Remote_FormDataAnnotation_Test {
assertEquals("x=%40%28foo%2Cbar%29",x.postX14("foo","bar"));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @FormData(maximum,exclusiveMaximum,minimum,exclusiveMinimum)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class D {
@@ -470,9 +470,9 @@ public class Remote_FormDataAnnotation_Test {
assertEquals("{}",x.postX43(null));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @FormData(maxItems,minItems,uniqueItems)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class E {
@@ -513,9 +513,9 @@ public class Remote_FormDataAnnotation_Test {
assertThrown(()->{x.postX6(new
String[]{"1","1"});}).contains("Duplicate items not allowed");
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @FormData(maxLength,minLength,enum,pattern)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class F {
@@ -562,9 +562,9 @@ public class Remote_FormDataAnnotation_Test {
assertEquals("{x:null}",x.postX6((String)null));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @FormData(multipleOf)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class G {
@@ -625,9 +625,9 @@ public class Remote_FormDataAnnotation_Test {
assertThrown(()->{x.postX14((byte)5);}).contains("Multiple-of
not met");
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @FormData(required)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class H {
@@ -653,9 +653,9 @@ public class Remote_FormDataAnnotation_Test {
assertThrown(()->{x.postX3(null);}).contains("Required value
not provided.");
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @FormData(skipIfEmpty)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class I {
@@ -680,9 +680,9 @@ public class Remote_FormDataAnnotation_Test {
assertEquals("{}",x.postX3(""));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @FormData(serializer)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class J {
@@ -703,9 +703,9 @@ public class Remote_FormDataAnnotation_Test {
assertEquals("{x:'xXx'}",x.postX1("X"));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @FormData
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest(parsers=UrlEncodingParser.class)
public static class K {
@@ -715,9 +715,9 @@ public class Remote_FormDataAnnotation_Test {
}
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @FormData, Simple values
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K1 {
@@ -777,9 +777,9 @@ public class Remote_FormDataAnnotation_Test {
assertEquals("{a:'xa1x',b:'xb1x',c:'xc1x',e:'xx',g:'xtruex',h:'x123x',i1:'xfoox'}",x2.postX2(new
K1a()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @FormData, Maps
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K2 {
@@ -815,9 +815,9 @@ public class Remote_FormDataAnnotation_Test {
assertEquals("{a:'x{a1:\\'v1\\',a2:123,a3:null,a4:\\'\\'}x',b1:'xtruex',b2:'x123x',b3:'xnullx',c1:'xv1x',c2:'x123x',c4:'xx'}",x2.postX2(new
K2a()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @FormData, NameValuePairs
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K3 {
@@ -861,9 +861,9 @@ public class Remote_FormDataAnnotation_Test {
assertEquals("{a1:'v1',a2:'123',a4:'',b1:'true',b2:'123',b3:'null',c1:'v1',c2:'123',c4:'',e1:'v1',e2:'123',e4:'',f1:'v1',f2:'123',f4:''}",x2.postX2(new
K3a()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @FormData,CharSequence
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K4 {
@@ -883,9 +883,9 @@ public class Remote_FormDataAnnotation_Test {
assertEquals("{baz:'qux',foo:'bar'}",x.post(new C04_Bean()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @FormData, Reader
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K5 {
@@ -905,9 +905,9 @@ public class Remote_FormDataAnnotation_Test {
assertEquals("{baz:'qux',foo:'bar'}",x.post(new K5a()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @FormData, Collections
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K6 {
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_HeaderAnnotation_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_HeaderAnnotation_Test.java
index dc9cdf1..e11dc4d 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_HeaderAnnotation_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_HeaderAnnotation_Test.java
@@ -49,9 +49,9 @@ public class Remote_HeaderAnnotation_Test {
}
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Basic tests
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class A {
@@ -110,9 +110,9 @@ public class Remote_HeaderAnnotation_Test {
assertEquals("{}",x.getX19(null));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Header(_default/allowEmptyValue)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class B {
@@ -144,9 +144,9 @@ public class Remote_HeaderAnnotation_Test {
assertEquals("{x:''}",x.getX4(""));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Header(collectionFormat)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class C {
@@ -180,9 +180,9 @@ public class Remote_HeaderAnnotation_Test {
assertEquals("{x:'@(foo,bar)'}",x.getX7("foo","bar"));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Header(maximum,exclusiveMaximum,minimum,exclusiveMinimum)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class D {
@@ -430,9 +430,9 @@ public class Remote_HeaderAnnotation_Test {
assertEquals("{}",x.getX42(null));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Header(maxItems,minItems,uniqueItems)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class E {
@@ -474,9 +474,9 @@ public class Remote_HeaderAnnotation_Test {
assertThrown(()->{x.getX6(new
String[]{"1","1"});}).contains("Duplicate items not allowed");
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Header(maxLength,minLength,enum)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class F {
@@ -524,9 +524,9 @@ public class Remote_HeaderAnnotation_Test {
assertEquals("{x:null}",x.getX6((String)null));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Header(multipleOf)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class G {
@@ -588,9 +588,9 @@ public class Remote_HeaderAnnotation_Test {
assertThrown(()->{x.getX14((byte)5);}).contains("Multiple-of
not met");
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Header(required)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class H {
@@ -617,9 +617,9 @@ public class Remote_HeaderAnnotation_Test {
assertThrown(()->{x.getX3(null);}).contains("Required value not
provided.");
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Header(skipIfEmpty)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class I {
@@ -645,9 +645,9 @@ public class Remote_HeaderAnnotation_Test {
assertEquals("{}",x.getX3(""));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Header(serializer)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class J {
@@ -669,9 +669,9 @@ public class Remote_HeaderAnnotation_Test {
assertEquals("{x:'xXx'}",x.getX1("X"));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @Header
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class K {
@@ -681,9 +681,9 @@ public class Remote_HeaderAnnotation_Test {
}
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @Header, Simple values
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K1 {
@@ -743,9 +743,9 @@ public class Remote_HeaderAnnotation_Test {
assertEquals("{a:'xa1x',b:'xb1x',c:'xc1x',e:'xx',g:'xtruex',h:'x123x',i1:'xfoox'}",x2.getX2(new
K1a()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @Header,Maps
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K2 {
@@ -781,9 +781,9 @@ public class Remote_HeaderAnnotation_Test {
assertEquals("{a:'x{a1:\\'v1\\',a2:123,a3:null,a4:\\'\\'}x',b1:'xtruex',b2:'x123x',b3:'xnullx',c1:'xv1x',c2:'x123x',c4:'xx'}",x2.getX2(new
K2a()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @Header, NameValuePairs
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K3 {
@@ -827,9 +827,9 @@ public class Remote_HeaderAnnotation_Test {
assertEquals("{a1:'v1',a2:'123',a4:'',b1:'true',b2:'123',b3:'null',c1:'v1',c2:'123',c4:'',e1:'v1',e2:'123',e4:'',f1:'v1',f2:'123',f4:''}",x2.getX2(new
K3a()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @Header, Collections
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K4 {
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_PathAnnotation_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_PathAnnotation_Test.java
index b2ef8bc..9de3180 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_PathAnnotation_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_PathAnnotation_Test.java
@@ -47,9 +47,9 @@ public class Remote_PathAnnotation_Test {
}
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Basic tests
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class A {
@@ -111,9 +111,9 @@ public class Remote_PathAnnotation_Test {
assertThrown(()->{x.getX21("foo");}).contains("Invalid value
type for path arg 'null': java.lang.String");
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Query(collectionFormat)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class B {
@@ -146,9 +146,9 @@ public class Remote_PathAnnotation_Test {
assertEquals("@(foo,bar)",x.getX7("foo","bar"));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Path(maximum,exclusiveMaximum,minimum,exclusiveMinimum)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class C {
@@ -378,9 +378,9 @@ public class Remote_PathAnnotation_Test {
assertThrown(()->{x.getX42((byte)10);}).contains("Maximum value
exceeded");
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Path(maxItems,minItems,uniqueItems)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class D {
@@ -422,9 +422,9 @@ public class Remote_PathAnnotation_Test {
assertThrown(()->{x.getX6(new
String[]{"1","1"});}).contains("Duplicate items not allowed");
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Path(maxLength,minLength,enum)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class E {
@@ -469,9 +469,9 @@ public class Remote_PathAnnotation_Test {
assertEquals("{x:null}",x.getX6((String)null));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Path(multipleOf)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class F {
@@ -533,9 +533,9 @@ public class Remote_PathAnnotation_Test {
assertThrown(()->{x.getX14((byte)5);}).contains("Multiple-of
not met");
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Path(required)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class G {
@@ -552,9 +552,9 @@ public class Remote_PathAnnotation_Test {
assertThrown(()->{x.getX1(null);}).contains("Required value not
provided.");
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Path(serializer)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class H {
@@ -576,9 +576,9 @@ public class Remote_PathAnnotation_Test {
assertEquals("{x:'xXx'}",x.getX1("X"));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequstBean @Path
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class K {
@@ -588,9 +588,9 @@ public class Remote_PathAnnotation_Test {
}
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequstBean @Path, Simple values
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K1 {
@@ -634,9 +634,9 @@ public class Remote_PathAnnotation_Test {
assertEquals("xa1x/xb1x/xc1x/xx/xtruex/x123x",x2.getX2(new
K1a()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequstBean @Path, Maps
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K2 {
@@ -672,9 +672,9 @@ public class Remote_PathAnnotation_Test {
assertEquals("xv1x/x123x/null/xx/xtruex/x123x/xnullx/xv1x/x123x/null/xx",x2.getX2(new
K2a()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequstBean @Path, NameValuePairs
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K3 {
@@ -718,9 +718,9 @@ public class Remote_PathAnnotation_Test {
assertEquals("v1/123/null//true/123/null/v1/123/null//v1/123/null//v1/123/null/",x2.getX2(new
K3a()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequstBean @Path, Collections
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K4 {
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_QueryAnnotation_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_QueryAnnotation_Test.java
index 139d6a5..03367a8 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_QueryAnnotation_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_QueryAnnotation_Test.java
@@ -50,9 +50,9 @@ public class Remote_QueryAnnotation_Test {
}
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Basic tests
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class A {
@@ -120,9 +120,9 @@ public class Remote_QueryAnnotation_Test {
assertEquals("{}",x.getX24(null));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Query(_default/allowEmptyValue)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class B {
@@ -153,9 +153,9 @@ public class Remote_QueryAnnotation_Test {
assertEquals("{x:''}",x.getX4(""));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Query(collectionFormat)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class C {
@@ -206,9 +206,9 @@ public class Remote_QueryAnnotation_Test {
assertEquals("x=%40%28foo%2Cbar%29",x.getX14("foo","bar"));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Query(maximum,exclusiveMaximum,minimum,exclusiveMinimum)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class D {
@@ -455,9 +455,9 @@ public class Remote_QueryAnnotation_Test {
assertEquals("{}",x.getX42(null));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Query(maxItems,minItems,uniqueItems)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class E {
@@ -498,9 +498,9 @@ public class Remote_QueryAnnotation_Test {
assertThrown(()->{x.getX6(new
String[]{"1","1"});}).contains("Duplicate items not allowed");
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Query(maxLength,minLength,enum)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class F {
@@ -547,9 +547,9 @@ public class Remote_QueryAnnotation_Test {
assertEquals("{x:null}",x.getX6((String)null));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Query(multipleOf)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class G {
@@ -610,9 +610,9 @@ public class Remote_QueryAnnotation_Test {
assertThrown(()->{x.getX14((byte)5);}).contains("Multiple-of
not met");
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Query(required)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class H {
@@ -638,9 +638,9 @@ public class Remote_QueryAnnotation_Test {
assertThrown(()->{x.getX3(null);}).contains("Required value not
provided.");
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Query(skipIfEmpty)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class I {
@@ -665,9 +665,9 @@ public class Remote_QueryAnnotation_Test {
assertEquals("{}",x.getX3(""));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Query(serializer)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class J {
@@ -688,9 +688,9 @@ public class Remote_QueryAnnotation_Test {
assertEquals("{x:'xXx'}",x.getX1("X"));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @Query - Return types
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class K {
@@ -700,9 +700,9 @@ public class Remote_QueryAnnotation_Test {
}
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @Query - Simple values
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K1 {
@@ -745,9 +745,9 @@ public class Remote_QueryAnnotation_Test {
assertEquals("{a:'xa1x',b:'xb1x',c:'xc1x',e:'xx',g:'xtruex',h:'x123x',i1:'xfoox'}",x2.getX2(new
K1b()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @Query - Maps
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K2 {
@@ -783,9 +783,9 @@ public class Remote_QueryAnnotation_Test {
assertEquals("{a:'x{a1:\\'v1\\',a2:123,a3:null,a4:\\'\\'}x',b1:'xtruex',b2:'x123x',b3:'xnullx',c1:'xv1x',c2:'x123x',c4:'xx'}",x2.getX2(new
K2a()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @Query - NameValuePairs
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K3 {
@@ -829,9 +829,9 @@ public class Remote_QueryAnnotation_Test {
assertEquals("{a1:'v1',a2:'123',a4:'',b1:'true',b2:'123',b3:'null',c1:'v1',c2:'123',c4:'',e1:'v1',e2:'123',e4:'',f1:'v1',f2:'123',f4:''}",x2.getX2(new
K3a()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @Query - CharSequence
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K4 {
@@ -851,9 +851,9 @@ public class Remote_QueryAnnotation_Test {
assertEquals("{baz:'qux',foo:'bar'}",x.get(new K4a()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @Query - Reader
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K5 {
@@ -873,9 +873,9 @@ public class Remote_QueryAnnotation_Test {
assertEquals("{baz:'qux',foo:'bar'}",x.get(new K5a()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RequestBean @Query - Collections
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Remote(path="/")
public static interface K6 {
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_RemoteMethodAnnotation_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_RemoteMethodAnnotation_Test.java
index f840a90..0d00ca6 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_RemoteMethodAnnotation_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_RemoteMethodAnnotation_Test.java
@@ -31,9 +31,9 @@ import org.junit.*;
@FixMethodOrder(NAME_ASCENDING)
public class Remote_RemoteMethodAnnotation_Test {
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Inferred methods/paths
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class A {
@@ -112,9 +112,9 @@ public class Remote_RemoteMethodAnnotation_Test {
assertEquals("baz",t.postX2().get());
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Return types
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class B {
@@ -163,9 +163,9 @@ public class Remote_RemoteMethodAnnotation_Test {
assertEquals("foo",IOUtils.read(x.x15().get()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Return types, JSON
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class C implements BasicSimpleJsonRest {
@@ -208,9 +208,9 @@ public class Remote_RemoteMethodAnnotation_Test {
assertEquals("'foo'",IOUtils.read(x.postX12("foo").get()));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Return types, part serialization
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class D implements BasicOpenApiRest {
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_RequestAnnotation_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_RequestAnnotation_Test.java
index a5bf61c..58ccca9 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_RequestAnnotation_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_RequestAnnotation_Test.java
@@ -33,9 +33,9 @@ import org.junit.*;
@FixMethodOrder(NAME_ASCENDING)
public class Remote_RequestAnnotation_Test {
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Basic tests
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class A {
@@ -82,9 +82,9 @@ public class Remote_RequestAnnotation_Test {
assertEquals("{body:'',header:null,query:null,path:'{x}'}",x.post(null));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Annotation on parent
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class B {
@@ -138,9 +138,9 @@ public class Remote_RequestAnnotation_Test {
assertEquals("{body:'',header:null,query:null,path:'{x}'}",x.post(null));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Annotation on interface
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class C {
@@ -194,9 +194,9 @@ public class Remote_RequestAnnotation_Test {
assertEquals("{body:'',header:null,query:null,path:'{x}'}",x.post(null));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Annotation on parameter
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class D {
@@ -242,9 +242,9 @@ public class Remote_RequestAnnotation_Test {
assertEquals("{body:'',header:null,query:null,path:'{x}'}",x.post(null));
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Request(partSerializer)
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class E {
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_ResponseAnnotation_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_ResponseAnnotation_Test.java
index e103a54..4d49c15 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_ResponseAnnotation_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_ResponseAnnotation_Test.java
@@ -29,9 +29,9 @@ import org.junit.*;
@FixMethodOrder(NAME_ASCENDING)
public class Remote_ResponseAnnotation_Test {
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Basic tests
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class A {
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_Test.java
index b825f04..20ad62c 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_Test.java
@@ -29,9 +29,9 @@ import org.junit.*;
@FixMethodOrder(NAME_ASCENDING)
public class Remote_Test {
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @Remote(path), relative paths
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class A {
@@ -169,9 +169,9 @@ public class Remote_Test {
assertEquals("foo",x.x3b());
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// @RemoteResource(path), absolute paths
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class B {
@@ -226,9 +226,9 @@ public class Remote_Test {
assertEquals("foo",x.x1b());
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Other tests
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest(path="/C1")
public static class C implements BasicSimpleJsonRest {
@@ -323,9 +323,9 @@ public class Remote_Test {
assertThrown(()->{x.x3().get();}).contains("foo");
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Status return type
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class D1 implements BasicSimpleJsonRest {
@@ -395,9 +395,9 @@ public class Remote_Test {
assertNull(x.x1a());
}
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// RRPC interfaces
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class E implements BasicSimpleJsonRest {
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_BasicCalls_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_BasicCalls_Test.java
index 06cd048..2e3ce4c 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_BasicCalls_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_BasicCalls_Test.java
@@ -12,6 +12,7 @@
//
***************************************************************************************************************************
package org.apache.juneau.rest.client2;
+import static org.apache.juneau.assertions.Assertions.*;
import static org.junit.runners.MethodSorters.*;
import java.io.*;
@@ -29,6 +30,7 @@ import org.apache.juneau.marshall.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.rest.mock2.*;
+import org.apache.juneau.testutils.*;
import org.junit.*;
@FixMethodOrder(NAME_ASCENDING)
@@ -104,6 +106,8 @@ public class RestClient_BasicCalls_Test {
@Test
public void a02_get() throws Exception {
client().build().get("/bean").run().assertBody().is("{f:1}");
+
+
assertThrown(()->{client().build().get("/bean").body(bean).run();}).contains("Method
does not support content entity.");
}
@Test
@@ -125,6 +129,8 @@ public class RestClient_BasicCalls_Test {
public void a04_put() throws Exception {
client().build().put("/bean",bean).run().assertBody().is("{f:1}");
client().build().put("/bean").body(bean).run().assertBody().is("{f:1}");
+
client().build().put("/bean",TestSupplier.of(bean)).run().assertBody().is("{f:1}");
+
client().build().put("/bean").body(TestSupplier.of(bean)).run().assertBody().is("{f:1}");
}
@Test
@@ -158,7 +164,9 @@ public class RestClient_BasicCalls_Test {
new StringReader("{f:1}"),
new ByteArrayInputStream("{f:1}".getBytes()),
ReaderResource.create().contents("{f:1}").build(),
+ ReaderResource.create().contents("{f:1}"),
StreamResource.create().contents("{f:1}").build(),
+ StreamResource.create().contents("{f:1}"),
bean,
new StringEntity("{f:1}"),
pairs("f",1)
@@ -275,6 +283,10 @@ public class RestClient_BasicCalls_Test {
@Test
public void a18_formPost() throws Exception {
client().build().formPost("/bean",bean).accept("application/json+simple").run().assertBody().is("{f:1}");
+
+
client().build().formPost("/bean",bean).body(bean).accept("application/json+simple").run().assertBody().is("{f:1}");
+
client().build().post("/bean").urlEnc().formDatas(bean).body(bean).accept("application/json+simple").run().assertBody().is("{f:1}");
+
client().build().post("/bean").urlEnc().body(bean).formDatas(bean).accept("application/json+simple").run().assertBody().is("{f:1}");
}
@Test
@@ -428,9 +440,9 @@ public class RestClient_BasicCalls_Test {
}
}
-
//------------------------------------------------------------------------------------------------------------------
+
//-----------------------------------------------------------------------------------------------------------------
// Helper methods.
-
//------------------------------------------------------------------------------------------------------------------
+
//-----------------------------------------------------------------------------------------------------------------
private static NameValuePair pair(String name, Object val) {
return BasicNameValuePair.of(name, val);
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_CallbackStrings_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_CallbackStrings_Test.java
index f048b99..3b90e00 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_CallbackStrings_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_CallbackStrings_Test.java
@@ -27,9 +27,9 @@ import org.junit.*;
@FixMethodOrder(NAME_ASCENDING)
public class RestClient_CallbackStrings_Test {
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Basic tests
-
//=================================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@Rest
public static class A {
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_FormData_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_FormData_Test.java
index 3dbeb72..6ff81ff 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_FormData_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_FormData_Test.java
@@ -53,6 +53,9 @@ public class RestClient_FormData_Test {
public void a01_formData_String_Object() throws Exception {
client().formData("foo","bar").formData("foo",new
StringBuilder("baz")).build().post("/formData").run().assertBody().is("foo=bar&foo=baz");
client().build().post("/formData").formData("foo","bar").formData("foo",new
StringBuilder("baz")).run().assertBody().is("foo=bar&foo=baz");
+
client().build().post("/formData").formData(null,"bar").run().assertBody().is("");
+
client().build().post("/formData").formData("foo",null).run().assertBody().is("");
+
client().build().post("/formData").formData(null,null).run().assertBody().is("");
}
@Test
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Headers_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Headers_Test.java
index b198e72..752f2ae 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Headers_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Headers_Test.java
@@ -226,6 +226,40 @@ public class RestClient_Headers_Test {
checkClient("Upgrade").upgrade("foo").build().get("/headers").run().assertBody().is("['foo']");
checkClient("Via").via("foo").build().get("/headers").run().assertBody().is("['foo']");
checkClient("Warning").warning("foo").build().get("/headers").run().assertBody().is("['foo']");
+
+
checkClient("Accept").build().get("/headers").accept("text/plain").run().assertBody().is("['text/plain']");
+
checkClient("Accept-Charset").build().get("/headers").acceptCharset("UTF-8").run().assertBody().is("['UTF-8']");
+
checkClient("Accept-Encoding").build().get("/headers").acceptEncoding("identity").run().assertBody().is("['identity']");
+
checkClient("Accept-Language").build().get("/headers").acceptLanguage("en").run().assertBody().is("['en']");
+
checkClient("Authorization").build().get("/headers").authorization("foo").run().assertBody().is("['foo']");
+
checkClient("Cache-Control").build().get("/headers").cacheControl("none").run().assertBody().is("['none']");
+
checkClient("X-Client-Version").build().get("/headers").clientVersion("1").run().assertBody().is("['1']");
+
checkClient("Connection").build().get("/headers").connection("foo").run().assertBody().is("['foo']");
+
checkClient("Content-Length").build().get("/headers").contentLength("123").run().assertBody().is("['123']");
+
checkClient("Content-Type").build().get("/headers").contentType("foo").run().assertBody().is("['foo']");
+
checkClient("Content-Encoding").build().get("/headers").contentEncoding("identity").run().assertBody().is("['identity']");
+
checkClient("Date").build().get("/headers").date("123").run().assertBody().is("['123']");
+
checkClient("Expect").build().get("/headers").expect("foo").run().assertBody().is("['foo']");
+
checkClient("Forwarded").build().get("/headers").forwarded("foo").run().assertBody().is("['foo']");
+
checkClient("From").build().get("/headers").from("foo").run().assertBody().is("['foo']");
+
checkClient("Host").build().get("/headers").hostHeader("foo").run().assertBody().is("['foo']");
+
checkClient("If-Match").build().get("/headers").ifMatch("foo").run().assertBody().is("['foo']");
+
checkClient("If-Modified-Since").build().get("/headers").ifModifiedSince("foo").run().assertBody().is("['foo']");
+
checkClient("If-None-Match").build().get("/headers").ifNoneMatch("foo").run().assertBody().is("['foo']");
+
checkClient("If-Range").build().get("/headers").ifRange("foo").run().assertBody().is("['foo']");
+
checkClient("If-Unmodified-Since").build().get("/headers").ifUnmodifiedSince("foo").run().assertBody().is("['foo']");
+
checkClient("Max-Forwards").build().get("/headers").maxForwards("10").run().assertBody().is("['10']");
+
checkClient("No-Trace").build().get("/headers").noTrace().run().assertBody().is("['true']");
+
checkClient("Origin").build().get("/headers").origin("foo").run().assertBody().is("['foo']");
+
checkClient("Pragma").build().get("/headers").pragma("foo").run().assertBody().is("['foo']");
+
checkClient("Proxy-Authorization").build().get("/headers").proxyAuthorization("foo").run().assertBody().is("['foo']");
+
checkClient("Range").build().get("/headers").range("foo").run().assertBody().is("['foo']");
+
checkClient("Referer").build().get("/headers").referer("foo").run().assertBody().is("['foo']");
+
checkClient("TE").build().get("/headers").te("foo").run().assertBody().is("['foo']");
+ checkClient("User-Agent").build().get("/headers").userAgent(new
StringBuilder("foo")).run().assertBody().is("['foo']");
+
checkClient("Upgrade").build().get("/headers").upgrade("foo").run().assertBody().is("['foo']");
+
checkClient("Via").build().get("/headers").via("foo").run().assertBody().is("['foo']");
+
checkClient("Warning").build().get("/headers").warning("foo").run().assertBody().is("['foo']");
}
@Test
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Query_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Query_Test.java
index 94366f6..c0ba379 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Query_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Query_Test.java
@@ -131,6 +131,10 @@ public class RestClient_Query_Test {
client().query(pair("foo","bar")).build().get("/query").query(pair("foo","baz")).run().assertBody().contains("foo=bar&foo=baz");
}
+ public static class A10 {
+ public String foo="bar";
+ }
+
@Test
public void a10_queries_Objects() throws Exception {
client().queries(pair("foo","bar")).build().get("/query").run().assertBody().is("foo=bar");
@@ -147,6 +151,7 @@ public class RestClient_Query_Test {
client().build().get("/query").queries(pairs("foo","bar","foo","baz")).run().assertBody().is("foo=bar&foo=baz");
client().build().get("/query").queries(pair("foo","bar"),pair("foo","baz")).run().assertBody().is("foo=bar&foo=baz");
client().build().get("/query").queries((Object)new
NameValuePair[]{pair("foo","bar")}).run().assertBody().is("foo=bar");
+ client().build().get("/query").queries(new
A10()).run().assertBody().is("foo=bar");
client().queries((Object)null).build().get("/query").queries((Object)null).run().assertBody().is("");
assertThrown(()->{client().queries("baz");}).contains("Invalid
type");
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Test.java
index 56c9e00..4e1e6bc 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Test.java
@@ -26,12 +26,15 @@ import org.apache.http.HttpResponse;
import org.apache.http.auth.*;
import org.apache.http.client.config.*;
import org.apache.http.client.methods.*;
+import org.apache.http.concurrent.*;
import org.apache.http.impl.client.*;
+import org.apache.http.params.*;
import org.apache.http.protocol.*;
import org.apache.juneau.*;
import org.apache.juneau.collections.*;
import org.apache.juneau.http.*;
import org.apache.juneau.http.exception.*;
+import org.apache.juneau.http.header.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.reflect.*;
import org.apache.juneau.rest.*;
@@ -118,6 +121,10 @@ public class RestClient_Test {
assertThrown(()->{rc.request(HttpMethod.GET,"/bean",null);}).contains("RestClient.close()
has already been called");
}
+ @Test
+ public void a06_request_runCalledTwice() throws Exception {
+ assertThrown(()->{RestRequest r =
client().build().get("/echo"); r.run(); r.run();}).is("run() already called.");
+ }
//------------------------------------------------------------------------------------------------------------------
// Logging
@@ -293,7 +300,9 @@ public class RestClient_Test {
@Test
public void c14_httpClient_requestConfig() throws Exception {
-
client().build().get("/bean").requestConfig(RequestConfig.custom().setMaxRedirects(1).build()).run().assertBody().is("{f:1}");
+ RestRequest req =
client().build().get("/bean").config(RequestConfig.custom().setMaxRedirects(1).build());
+ req.run().assertBody().is("{f:1}");
+ assertEquals(1, req.getConfig().getMaxRedirects());
}
@Test
@@ -311,7 +320,7 @@ public class RestClient_Test {
//------------------------------------------------------------------------------------------------------------------
@Rest
- public static class E extends BasicRest {
+ public static class D extends BasicRest {
@RestMethod
public String
getEcho(@org.apache.juneau.http.annotation.Header("Authorization") String auth,
org.apache.juneau.rest.RestResponse res) throws IOException {
if (auth == null) {
@@ -325,7 +334,133 @@ public class RestClient_Test {
@Test
public void d01_basicAuth() throws RestCallException {
-
client(E.class).basicAuth(AuthScope.ANY_HOST,AuthScope.ANY_PORT,"user","pw").build().get("/echo").run().assertBody().contains("OK");
+
client(D.class).basicAuth(AuthScope.ANY_HOST,AuthScope.ANY_PORT,"user","pw").build().get("/echo").run().assertBody().contains("OK");
+ }
+
+
//------------------------------------------------------------------------------------------------------------------
+ // Other.
+
//------------------------------------------------------------------------------------------------------------------
+
+ @Test
+ public void e01_other_completeFuture() throws Exception {
+
client().build().get("/bean").completeFuture().get().assertStatus().is(200);
+ }
+
+ public static class E2 implements Cancellable {
+ @Override
+ public boolean cancel() {
+ return false;
+ }
+ }
+
+ @Test
+ public void e02_httpRequestBase_setCancellable() throws Exception {
+ client().build().get("/bean").cancellable(new
E2()).run().assertStatus().is(200);
+ }
+
+ @Test
+ public void e03_httpRequestBase_protocolVersion() throws Exception {
+ client().build().get("/bean").protocolVersion(new
ProtocolVersion("http", 2, 0)).run().assertStatus().is(200);
+ ProtocolVersion x =
client().build().get("/bean").protocolVersion(new ProtocolVersion("http", 2,
0)).getProtocolVersion();
+ assertEquals(2,x.getMajor());
+ }
+
+ @Test
+ public void e04_httpRequestBase_completed() throws Exception {
+
client().build().get("/bean").completed().run().assertStatus().is(200);
+ }
+
+ @Test
+ public void e05_httpUriRequest_abort() throws Exception {
+ RestRequest x = client().build().get("/bean");
+ x.abort();
+ assertTrue(x.isAborted());
+ }
+
+ @Test
+ public void e06_httpMessage_getRequestLine() throws Exception {
+ RestRequest x = client().build().get("/bean");
+ assertEquals("GET",x.getRequestLine().getMethod());
+ }
+
+ @Test
+ public void e07_httpMessage_containsHeader() throws Exception {
+ RestRequest x = client().build().get("/bean").header("Foo",
"bar");
+ assertTrue(x.containsHeader("Foo"));
+ }
+
+ @Test
+ public void e08_httpMessage_getFirstHeader_getLastHeader() throws
Exception {
+ RestRequest x =
client().build().get("/bean").header("Foo","bar").header("Foo","baz");
+ assertEquals("bar",x.getFirstHeader("Foo").getValue());
+ assertEquals("baz",x.getLastHeader("Foo").getValue());
+ }
+
+ @Test
+ public void e09_httpMessage_addHeader() throws Exception {
+ RestRequest x = client().build().get("/bean");
+ x.addHeader(header("Foo","bar"));
+ x.addHeader("Foo","baz");
+ assertEquals("bar",x.getFirstHeader("Foo").getValue());
+ assertEquals("baz",x.getLastHeader("Foo").getValue());
+ }
+
+ @Test
+ public void e10_httpMessage_setHeader() throws Exception {
+ RestRequest x = client().build().get("/bean");
+ x.setHeader(header("Foo","bar"));
+ x.setHeader(header("Foo","baz"));
+ assertEquals("baz",x.getFirstHeader("Foo").getValue());
+ assertEquals("baz",x.getLastHeader("Foo").getValue());
+ x.setHeader("Foo","qux");
+ assertEquals("qux",x.getFirstHeader("Foo").getValue());
+ assertEquals("qux",x.getLastHeader("Foo").getValue());
+ }
+
+ @Test
+ public void e11_httpMessage_setHeaders() throws Exception {
+ RestRequest x = client().build().get("/bean");
+ x.setHeaders(new Header[]{header("Foo","bar")});
+ assertEquals("bar",x.getFirstHeader("Foo").getValue());
+ }
+
+ @Test
+ public void e12_httpMessage_removeHeaders() throws Exception {
+ RestRequest x = client().build().get("/bean");
+ x.setHeaders(new Header[]{header("Foo","bar")});
+ x.removeHeaders("Foo");
+ assertNull(x.getFirstHeader("Foo"));
+ }
+
+ @Test
+ public void e13_httpMessage_removeHeader() throws Exception {
+ RestRequest x = client().build().get("/bean");
+ x.setHeaders(new Header[]{header("Foo","bar")});
+ x.removeHeader(header("Foo","bar"));
+ //assertNull(x.getFirstHeader("Foo")); // Bug in HttpClient
API?
+ }
+
+ @Test
+ public void e14_httpMessage_headerIterator() throws Exception {
+ RestRequest x = client().build().get("/bean");
+ x.setHeaders(new Header[]{header("Foo","bar")});
+ assertEquals("Foo: bar", x.headerIterator().next().toString());
+ assertEquals("Foo: bar",
x.headerIterator("Foo").next().toString());
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void e15_httpMessage_getParams() throws Exception {
+ HttpParams p = new BasicHttpParams();
+ RestRequest x = client().build().get("/bean");
+ x.setParams(p);
+ assertEquals(p, x.getParams());
+ }
+
+ @Test
+ public void e16_toMap() throws Exception {
+ assertNotNull(client().build().toString());
+ assertNotNull(client().build().get("/bean").toString());
}
//------------------------------------------------------------------------------------------------------------------
@@ -339,4 +474,8 @@ public class RestClient_Test {
private static RestClientBuilder client(Class<?> c) {
return MockRestClient.create(c).simpleJson();
}
+
+ private static Header header(String name, Object val) {
+ return BasicStringHeader.of(name, val);
+ }
}
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RrpcInterfaceTest.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RrpcInterfaceTest.java
index 122eb50..79a60ff 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RrpcInterfaceTest.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RrpcInterfaceTest.java
@@ -237,9 +237,9 @@ public class RrpcInterfaceTest {
public static class InterfaceProxyResource extends BasicRestServletJena
{
private static final long serialVersionUID = 1L;
-
//====================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
// Test that Q-values are being resolved correctly.
-
//====================================================================================================
+
//-----------------------------------------------------------------------------------------------------------------
@RestMethod(name=RRPC,path="/proxy/*")
public InterfaceProxy getProxy() {
return new InterfaceProxy() {
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
index 7616709..abbfa3a 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
@@ -340,7 +340,7 @@ import org.apache.http.client.CookieStore;
* <li class='jm'>{@link RestRequest#expect(Object) expect(Object)}
* <li class='jm'>{@link RestRequest#forwarded(Object)
forwarded(Object)}
* <li class='jm'>{@link RestRequest#from(Object) from(Object)}
- * <li class='jm'>{@link RestRequest#host(Object) host(Object)}
+ * <li class='jm'>{@link RestRequest#hostHeader(Object)
host(Object)}
* <li class='jm'>{@link RestRequest#ifMatch(Object)
ifMatch(Object)}
* <li class='jm'>{@link RestRequest#ifModifiedSince(Object)
ifModifiedSince(Object)}
* <li class='jm'>{@link RestRequest#ifNoneMatch(Object)
ifNoneMatch(Object)}
@@ -1254,7 +1254,7 @@ public class RestClient extends BeanContext implements
HttpClient, Closeable, Re
* <li class='jm'>{@link
org.apache.juneau.rest.client2.RestRequest#expect(Object) expect(Object)}
* <li class='jm'>{@link
org.apache.juneau.rest.client2.RestRequest#forwarded(Object) forwarded(Object)}
* <li class='jm'>{@link
org.apache.juneau.rest.client2.RestRequest#from(Object) from(Object)}
- * <li class='jm'>{@link
org.apache.juneau.rest.client2.RestRequest#host(Object) host(Object)}
+ * <li class='jm'>{@link
org.apache.juneau.rest.client2.RestRequest#hostHeader(Object)
hostHeader(Object)}
* <li class='jm'>{@link
org.apache.juneau.rest.client2.RestRequest#ifMatch(Object) ifMatch(Object)}
* <li class='jm'>{@link
org.apache.juneau.rest.client2.RestRequest#ifModifiedSince(Object)
ifModifiedSince(Object)}
* <li class='jm'>{@link
org.apache.juneau.rest.client2.RestRequest#ifNoneMatch(Object)
ifNoneMatch(Object)}
@@ -1918,7 +1918,7 @@ public class RestClient extends BeanContext implements
HttpClient, Closeable, Re
}
private static final
- Predicate<Integer> ERROR_CODES_DEFAULT = x -> x>=400;
+ Predicate<Integer> ERROR_CODES_DEFAULT = x -> x<=0 || x>=400;
private static final
BiPredicate<RestRequest,RestResponse>
LOG_REQUESTS_PREDICATE_DEFAULT = (req,res) -> true;
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequest.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequest.java
index 4ee63a1..11eb536 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequest.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequest.java
@@ -687,20 +687,6 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
}
/**
- * Set configuration settings on this request.
- *
- * <p>
- * Use {@link RequestConfig#custom()} to create configuration
parameters for the request.
- *
- * @param config The new configuration settings for this request.
- * @return This object (for method chaining).
- */
- public RestRequest requestConfig(RequestConfig config) {
- setConfig(config);
- return this;
- }
-
- /**
* Sets <c>Debug: value</c> header on this request.
*
* @return This object (for method chaining).
@@ -872,7 +858,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* @param name The parameter name.
* @param value The parameter value.
* <ul>
- * <li>Value can be any POJO.
+ * <li>Value can be any POJO or POJO {@link Supplier}.
* <li>Value converted to a string using the configured
part serializer.
* </ul>
* @return This object (for method chaining).
@@ -920,7 +906,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* @param name The parameter name.
* @param value The parameter value.
* <ul>
- * <li>Value can be any POJO.
+ * <li>Value can be any POJO or POJO {@link Supplier}.
* <li>Value converted to a string using the configured
part serializer.
* </ul>
* @param schema The part schema. Can be <jk>null</jk>.
@@ -1090,7 +1076,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* @param name The parameter name.
* @param value The parameter value.
* <ul>
- * <li>Value can be any POJO.
+ * <li>Value can be any POJO or POJO {@link Supplier}.
* <li>Value converted to a string using the configured
part serializer.
* </ul>
* @param schema The schema object that defines the format of the
output.
@@ -1120,7 +1106,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* @param name The parameter name.
* @param value The parameter value.
* <ul>
- * <li>Value can be any POJO.
+ * <li>Value can be any POJO or POJO {@link Supplier}.
* <li>Value converted to a string using the configured
part serializer.
* </ul>
* @return This object (for method chaining).
@@ -1171,7 +1157,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* @param name The parameter name.
* @param value The parameter value.
* <ul>
- * <li>Value can be any POJO.
+ * <li>Value can be any POJO or POJO {@link Supplier}.
* <li>Value converted to a string using the configured
part serializer.
* </ul>
* @param schema The HTTP part schema. Can be <jk>null</jk>.
@@ -1206,7 +1192,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* @param name The parameter name.
* @param value The parameter value.
* <ul>
- * <li>Value can be any POJO.
+ * <li>Value can be any POJO or POJO {@link Supplier}.
* <li>Value converted to a string using the configured
part serializer.
* </ul>
* @return This object (for method chaining).
@@ -1471,7 +1457,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* @param name The parameter name.
* @param value The parameter value.
* <ul>
- * <li>Value can be any POJO.
+ * <li>Value can be any POJO or POJO {@link Supplier}.
* <li>Value converted to a string using the configured
part serializer.
* </ul>
* @param schema The schema object that defines the format of the
output.
@@ -1501,7 +1487,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* @param name The parameter name.
* @param value The parameter value.
* <ul>
- * <li>Value can be any POJO.
+ * <li>Value can be any POJO or POJO {@link Supplier}.
* <li>Value converted to a string using the configured
part serializer.
* </ul>
* @return This object (for method chaining).
@@ -1552,7 +1538,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* @param name The parameter name.
* @param value The parameter value.
* <ul>
- * <li>Value can be any POJO.
+ * <li>Value can be any POJO or POJO {@link Supplier}.
* <li>Value converted to a string using the configured
part serializer.
* </ul>
* @param schema The HTTP part schema. Can be <jk>null</jk>.
@@ -1587,7 +1573,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* @param name The parameter name.
* @param value The parameter value.
* <ul>
- * <li>Value can be any POJO.
+ * <li>Value can be any POJO or POJO {@link Supplier}.
* <li>Value converted to a string using the configured
part serializer.
* </ul>
* @return This object (for method chaining).
@@ -1813,6 +1799,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
}
private RestRequest innerFormData(EnumSet<AddFlag> flags,
List<NameValuePair> params) {
+ input = null;
flags = AddFlag.orDefault(flags);
params.removeIf(x -> x.getValue() == null);
if (flags.contains(SKIP_IF_EMPTY))
@@ -1860,6 +1847,8 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* {@link HttpEntity} - Bypass Juneau
serialization and pass HttpEntity directly to HttpClient.
* <li class='jc'>
* {@link NameValuePairs} - Converted to a
URL-encoded FORM post.
+ * <li>
+ * A {@link Supplier} of anything on this list.
* </ul>
* @return This object (for method chaining).
* @throws RestCallException If a retry was attempted, but the entity
was not repeatable.
@@ -1925,6 +1914,8 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* {@link HttpEntity} - Bypass Juneau
serialization and pass HttpEntity directly to HttpClient.
* <li class='jc'>
* {@link NameValuePairs} - Converted to a
URL-encoded FORM post.
+ * <li>
+ * A {@link Supplier} of anything on this list.
* </ul>
* @param schema The schema object that defines the format of the
output.
* <ul>
@@ -1971,7 +1962,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* @param name The header name.
* @param value The header value.
* <ul>
- * <li>Value can be any POJO.
+ * <li>Value can be any POJO or POJO {@link Supplier}.
* <li>Value converted to a string using the configured
part serializer.
* </ul>
* @param schema The schema object that defines the format of the
output.
@@ -2001,7 +1992,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* @param name The header name.
* @param value The header value.
* <ul>
- * <li>Value can be any POJO.
+ * <li>Value can be any POJO or POJO {@link Supplier}.
* <li>Value converted to a string using the configured
part serializer.
* </ul>
* @return This object (for method chaining).
@@ -2032,7 +2023,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* @param name The header name.
* @param value The header value.
* <ul>
- * <li>Value can be any POJO.
+ * <li>Value can be any POJO or POJO {@link Supplier}.
* <li>Value converted to a string using the configured
part serializer.
* </ul>
* @param schema The HTTP part schema. Can be <jk>null</jk>.
@@ -2067,7 +2058,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* @param name The header name.
* @param value The header value.
* <ul>
- * <li>Value can be any POJO.
+ * <li>Value can be any POJO or POJO {@link Supplier}.
* <li>Value converted to a string using the configured
part serializer.
* </ul>
* @return This object (for method chaining).
@@ -2516,7 +2507,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* @return This object (for method chaining).
* @throws RestCallException Invalid input.
*/
- public RestRequest host(Object value) throws RestCallException {
+ public RestRequest hostHeader(Object value) throws RestCallException {
return header("Host", value);
}
@@ -2605,6 +2596,21 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
}
/**
+ * When called, <c>No-Trace: true</c> is added to requests.
+ *
+ * <p>
+ * This gives the opportunity for the servlet to not log errors on
invalid requests.
+ * This is useful for testing purposes when you don't want your log
file to show lots of errors that are simply the
+ * results of testing.
+ *
+ * @return This object (for method chaining).
+ * @throws RestCallException Invalid input.
+ */
+ public RestRequest noTrace() throws RestCallException {
+ return header("No-Trace", true);
+ }
+
+ /**
* Sets the value for the <c>Origin</c> request header.
*
* <p>
@@ -2785,7 +2791,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
*/
public RestResponse run() throws RestCallException {
if (response != null)
- return response;
+ throw new RestCallException("run() already called.");
try {
HttpEntityEnclosingRequestBase request2 = request
instanceof HttpEntityEnclosingRequestBase ?
(HttpEntityEnclosingRequestBase)request : null;
@@ -2811,9 +2817,6 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
if (hasInput || formData != null) {
- if (hasInput && formData != null && input !=
null)
- throw new RestCallException("Both input
and form-data found on same request.");
-
if (request2 == null)
throw new RestCallException(0, "Method
does not support content entity.", getMethod(), getURI(), null);
@@ -2854,7 +2857,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
else {
if (input2 == null)
input2 = "";
- entity = new
StringEntity(getBeanContext().getClassMetaForObject(input2).toString(input2),
getRequestContentType(TEXT_PLAIN));
+ entity = new
StringEntity(BeanContext.DEFAULT.getClassMetaForObject(input2).toString(input2),
getRequestContentType(TEXT_PLAIN));
}
request2.setEntity(entity);
@@ -2876,9 +2879,6 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
rci.onConnect(this, response);
client.onConnect(this, response);
- if (response.getStatusCode() == 0)
- throw new RestCallException("HttpClient
returned a null response");
-
String method = getMethod();
int sc = response.getStatusCode();
@@ -3059,7 +3059,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* @param value The new value.
* @return This object (for method chaining).
*/
- public RestRequest setConfig(RequestConfig value) {
+ public RestRequest config(RequestConfig value) {
request.setConfig(value);
return this;
}
@@ -3070,7 +3070,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* @param cancellable The cancellable object.
* @return This object (for method chaining).
*/
- public RestRequest setCancellable(Cancellable cancellable) {
+ public RestRequest cancellable(Cancellable cancellable) {
request.setCancellable(cancellable);
return this;
}
@@ -3079,16 +3079,21 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* Sets the protocol version for this request.
*
* @param version The protocol version for this request.
+ * @return This object (for method chaining).
*/
- public void setProtocolVersion(ProtocolVersion version) {
+ public RestRequest protocolVersion(ProtocolVersion version) {
request.setProtocolVersion(version);
+ return this;
}
/**
- * Used in combination with {@link #setCancellable(Cancellable)}.
+ * Used in combination with {@link #cancellable(Cancellable)}.
+ *
+ * @return This object (for method chaining).
*/
- public void completed() {
+ public RestRequest completed() {
request.completed();
+ return this;
}
//
-----------------------------------------------------------------------------------------------------------------
@@ -3371,13 +3376,6 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
// Utility methods
//
-----------------------------------------------------------------------------------------------------------------
- private BeanContext getBeanContext() {
- BeanContext bc = serializer;
- if (bc == null)
- bc = BeanContext.DEFAULT;
- return bc;
- }
-
private ContentType getRequestContentType(ContentType def) {
Header h = request.getFirstHeader("Content-Type");
if (h != null) {
@@ -3407,7 +3405,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
}
private static String className(Object value) {
- return value == null ? null : value.getClass().getName();
+ return value.getClass().getName();
}
private static boolean isNameValuePairArray(Object o) {