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 06da0d1 RestClient tests.
06da0d1 is described below
commit 06da0d14d2b976f1e0d9d95c11c52cac06c6f0de
Author: JamesBognar <[email protected]>
AuthorDate: Tue Jun 30 11:19:11 2020 -0400
RestClient tests.
---
.../apache/juneau/http/header/ContentTypeTest.java | 38 +++++++++
.../java/org/apache/juneau/http/MediaType.java | 2 +-
.../java/org/apache/juneau/http/header/Accept.java | 2 +-
.../org/apache/juneau/http/header/BasicHeader.java | 12 ++-
...ion.java => BasicParameterizedArrayHeader.java} | 94 +++++++---------------
...position.java => BasicParameterizedHeader.java} | 94 +++++++---------------
.../juneau/http/header/ContentDisposition.java | 2 +-
.../org/apache/juneau/http/header/ContentType.java | 32 ++++----
.../rest/client2/RestClient_Headers_Test.java | 36 +++++++++
.../rest/client2/RestClient_Response_Test.java | 5 --
.../apache/juneau/rest/client2/RestResponse.java | 5 +-
.../java/org/apache/juneau/rest/RequestBody.java | 9 ++-
.../java/org/apache/juneau/rest/RestResponse.java | 9 ++-
13 files changed, 176 insertions(+), 164 deletions(-)
diff --git
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/http/header/ContentTypeTest.java
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/http/header/ContentTypeTest.java
new file mode 100644
index 0000000..0ec11b28
--- /dev/null
+++
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/http/header/ContentTypeTest.java
@@ -0,0 +1,38 @@
+//
***************************************************************************************************************************
+// * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file *
+// * distributed with this work for additional information regarding copyright
ownership. The ASF licenses this file *
+// * to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance *
+// * with the License. You may obtain a copy of the License at
*
+// *
*
+// * http://www.apache.org/licenses/LICENSE-2.0
*
+// *
*
+// * Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an *
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the *
+// * specific language governing permissions and limitations under the
License. *
+//
***************************************************************************************************************************
+package org.apache.juneau.http.header;
+
+import static org.junit.Assert.*;
+import static org.junit.runners.MethodSorters.*;
+
+import org.junit.*;
+
+@FixMethodOrder(NAME_ASCENDING)
+public class ContentTypeTest {
+
+ @Test
+ public void a01_basic() {
+ ContentType ct = ContentType.of("application/json");
+ assertEquals("application/json", ct.getValue());
+ }
+
+ @Test
+ public void a02_getParameter() {
+ ContentType ct = ContentType.of("application/json;charset=foo");
+ assertEquals("foo", ct.getParameter("charset"));
+ ct = ContentType.of(" application/json ; charset = foo ");
+ assertEquals("foo", ct.getParameter("charset"));
+
+ assertNull(ct.getParameter("x"));
+ }
+}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/MediaType.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/MediaType.java
index 563d0ab..8259f6e 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/MediaType.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/MediaType.java
@@ -123,7 +123,7 @@ public class MediaType implements Comparable<MediaType> {
*
* @param mt The media type string.
*/
- protected MediaType(String mt) {
+ public MediaType(String mt) {
Builder b = new Builder(mt);
this.mediaType = b.mediaType;
this.type = b.type;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/Accept.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/Accept.java
index f80f385..178be67 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/Accept.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/Accept.java
@@ -145,7 +145,7 @@ import org.apache.juneau.internal.*;
* </ul>
*/
@Header("Accept")
-public class Accept extends BasicStringHeader {
+public class Accept extends BasicParameterizedArrayHeader {
private static final long serialVersionUID = 1L;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/BasicHeader.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/BasicHeader.java
index f5fb62f..81ca646 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/BasicHeader.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/BasicHeader.java
@@ -37,6 +37,7 @@ public class BasicHeader implements Header, Cloneable,
Serializable {
private final String name;
private final Object value;
+ private HeaderElement[] elements;
/**
* Convenience creator.
@@ -149,11 +150,14 @@ public class BasicHeader implements Header, Cloneable,
Serializable {
@Override
public HeaderElement[] getElements() throws ParseException {
- if (getValue() != null) {
- // result intentionally not cached, it's probably not
used again
- return BasicHeaderValueParser.parseElements(getValue(),
null);
+ if (elements == null) {
+ String s = getValue();
+ HeaderElement[] x = s == null ? EMPTY_HEADER_ELEMENTS :
BasicHeaderValueParser.parseElements(s, null);
+ if (value instanceof Supplier)
+ return x;
+ elements = x;
}
- return EMPTY_HEADER_ELEMENTS;
+ return elements;
}
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentDisposition.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/BasicParameterizedArrayHeader.java
similarity index 53%
copy from
juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentDisposition.java
copy to
juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/BasicParameterizedArrayHeader.java
index d87270f..ff8bf12 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentDisposition.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/BasicParameterizedArrayHeader.java
@@ -12,69 +12,31 @@
//
***************************************************************************************************************************
package org.apache.juneau.http.header;
-import static org.apache.juneau.http.header.Constants.*;
-
import java.util.function.*;
-import org.apache.juneau.http.annotation.*;
-import org.apache.juneau.internal.*;
+import org.apache.http.*;
/**
- * Represents a parsed <l>Content-Disposition</l> HTTP request header.
+ * Category of headers that consist of multiple parameterized string values.
*
* <p>
- * In a regular HTTP response, the Content-Disposition response header is a
header indicating if the content is expected
- * to be displayed inline in the browser, that is, as a Web page or as part of
a Web page, or as an attachment, that is
- * downloaded and saved locally.
- *
* <h5 class='figure'>Example</h5>
* <p class='bcode w800'>
- * Content-Disposition: form-data; name="fieldName";
filename="filename.jpg"
- * </p>
- *
- * <h5 class='topic'>RFC2616 Specification</h5>
- *
- * The Expect request-header field is used to indicate that particular server
behaviors are required by the client.
- * <p class='bcode w800'>
- * content-disposition = "Content-Disposition" ":"
- * disposition-type *( ";" disposition-parm )
- * disposition-type = "attachment" | disp-extension-token
- * disposition-parm = filename-parm | disp-extension-parm
- * filename-parm = "filename" "=" quoted-string
- * disp-extension-token = token
- * disp-extension-parm = token "=" ( token | quoted-string )
+ * Accept: application/json;q=0.9,text/xml;q=0.1
* </p>
*
* <ul class='seealso'>
* <li class='extlink'>{@doc RFC2616}
* </ul>
- */
-@Header("Content-Disposition")
-public class ContentDisposition extends BasicStringHeader {
+*/
+public class BasicParameterizedArrayHeader extends BasicStringHeader {
private static final long serialVersionUID = 1L;
- private static final Cache<String,ContentDisposition> CACHE = new
Cache<>(NOCACHE, CACHE_MAX_SIZE);
-
- /**
- * Returns a parsed and cached header.
- *
- * @param value
- * The parameter value.
- * @return A cached {@link ContentDisposition} object.
- */
- public static ContentDisposition of(String value) {
- if (value == null)
- return null;
- ContentDisposition x = CACHE.get(value);
- if (x == null)
- x = CACHE.put(value, new ContentDisposition(value));
- return x;
- }
-
/**
* Convenience creator.
*
+ * @param name The parameter name.
* @param value
* The parameter value.
* <br>Can be any of the following:
@@ -82,12 +44,10 @@ public class ContentDisposition extends BasicStringHeader {
* <li>{@link String}
* <li>Anything else - Converted to <c>String</c> then
parsed.
* </ul>
- * @return A new {@link ContentDisposition} object.
+ * @return A new {@link BasicParameterizedArrayHeader} object.
*/
- public static ContentDisposition of(Object value) {
- if (value == null)
- return null;
- return new ContentDisposition(value);
+ public static BasicParameterizedArrayHeader of(String name, Object
value) {
+ return new BasicParameterizedArrayHeader(name, value);
}
/**
@@ -96,6 +56,7 @@ public class ContentDisposition extends BasicStringHeader {
* <p>
* Header value is re-evaluated on each call to {@link #getValue()}.
*
+ * @param name The parameter name.
* @param value
* The parameter value supplier.
* <br>Can be any of the following:
@@ -103,19 +64,17 @@ public class ContentDisposition extends BasicStringHeader {
* <li>{@link String}
* <li>Anything else - Converted to <c>String</c> then
parsed.
* </ul>
- * @return A new {@link ContentDisposition} object.
+ * @return A new {@link BasicParameterizedArrayHeader} object.
*/
- public static ContentDisposition of(Supplier<?> value) {
- if (value == null)
- return null;
- return new ContentDisposition(value);
+ public static BasicParameterizedArrayHeader of(String name, Supplier<?>
value) {
+ return new BasicParameterizedArrayHeader(name, value);
}
/**
- * Constructor.
+ * Constructor
*
+ * @param name The parameter name.
* @param value
- * The parameter value.
* <br>Can be any of the following:
* <ul>
* <li>{@link String}
@@ -123,17 +82,26 @@ public class ContentDisposition extends BasicStringHeader {
* <li>A {@link Supplier} of anything on this list.
* </ul>
*/
- public ContentDisposition(Object value) {
- super("Content-Disposition", value);
+ public BasicParameterizedArrayHeader(String name, Object value) {
+ super(name, value);
}
/**
- * Constructor.
+ * Returns a parameterized value of the header.
*
- * @param value
- * The parameter value.
+ * <p class='bcode w800'>
+ * ContentType ct =
ContentType.<jsm>of</jsm>(<js>"application/json;charset=foo"</js>);
+ * assertEquals(<js>"foo"</js>,
ct.getParameter(<js>"charset"</js>);
+ * </p>
+ *
+ * @param name The parameter name.
+ * @return The parameter value, or <jk>null</jk> if the parameter is
not present.
*/
- public ContentDisposition(String value) {
- super("Content-Disposition", value);
+ public String getParameter(String name) {
+ HeaderElement[] elements = getElements();
+ if (elements.length == 0)
+ return null;
+ NameValuePair p = elements[0].getParameterByName(name);
+ return p == null ? null : p.getValue();
}
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentDisposition.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/BasicParameterizedHeader.java
similarity index 53%
copy from
juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentDisposition.java
copy to
juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/BasicParameterizedHeader.java
index d87270f..5f74684 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentDisposition.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/BasicParameterizedHeader.java
@@ -12,69 +12,31 @@
//
***************************************************************************************************************************
package org.apache.juneau.http.header;
-import static org.apache.juneau.http.header.Constants.*;
-
import java.util.function.*;
-import org.apache.juneau.http.annotation.*;
-import org.apache.juneau.internal.*;
+import org.apache.http.*;
/**
- * Represents a parsed <l>Content-Disposition</l> HTTP request header.
+ * Category of headers that consist of a single parameterized string value.
*
* <p>
- * In a regular HTTP response, the Content-Disposition response header is a
header indicating if the content is expected
- * to be displayed inline in the browser, that is, as a Web page or as part of
a Web page, or as an attachment, that is
- * downloaded and saved locally.
- *
* <h5 class='figure'>Example</h5>
* <p class='bcode w800'>
- * Content-Disposition: form-data; name="fieldName";
filename="filename.jpg"
- * </p>
- *
- * <h5 class='topic'>RFC2616 Specification</h5>
- *
- * The Expect request-header field is used to indicate that particular server
behaviors are required by the client.
- * <p class='bcode w800'>
- * content-disposition = "Content-Disposition" ":"
- * disposition-type *( ";" disposition-parm )
- * disposition-type = "attachment" | disp-extension-token
- * disposition-parm = filename-parm | disp-extension-parm
- * filename-parm = "filename" "=" quoted-string
- * disp-extension-token = token
- * disp-extension-parm = token "=" ( token | quoted-string )
+ * Content-Type: application/json;charset=utf-8
* </p>
*
* <ul class='seealso'>
* <li class='extlink'>{@doc RFC2616}
* </ul>
- */
-@Header("Content-Disposition")
-public class ContentDisposition extends BasicStringHeader {
+*/
+public class BasicParameterizedHeader extends BasicStringHeader {
private static final long serialVersionUID = 1L;
- private static final Cache<String,ContentDisposition> CACHE = new
Cache<>(NOCACHE, CACHE_MAX_SIZE);
-
- /**
- * Returns a parsed and cached header.
- *
- * @param value
- * The parameter value.
- * @return A cached {@link ContentDisposition} object.
- */
- public static ContentDisposition of(String value) {
- if (value == null)
- return null;
- ContentDisposition x = CACHE.get(value);
- if (x == null)
- x = CACHE.put(value, new ContentDisposition(value));
- return x;
- }
-
/**
* Convenience creator.
*
+ * @param name The parameter name.
* @param value
* The parameter value.
* <br>Can be any of the following:
@@ -82,12 +44,10 @@ public class ContentDisposition extends BasicStringHeader {
* <li>{@link String}
* <li>Anything else - Converted to <c>String</c> then
parsed.
* </ul>
- * @return A new {@link ContentDisposition} object.
+ * @return A new {@link BasicParameterizedHeader} object.
*/
- public static ContentDisposition of(Object value) {
- if (value == null)
- return null;
- return new ContentDisposition(value);
+ public static BasicParameterizedHeader of(String name, Object value) {
+ return new BasicParameterizedHeader(name, value);
}
/**
@@ -96,6 +56,7 @@ public class ContentDisposition extends BasicStringHeader {
* <p>
* Header value is re-evaluated on each call to {@link #getValue()}.
*
+ * @param name The parameter name.
* @param value
* The parameter value supplier.
* <br>Can be any of the following:
@@ -103,19 +64,17 @@ public class ContentDisposition extends BasicStringHeader {
* <li>{@link String}
* <li>Anything else - Converted to <c>String</c> then
parsed.
* </ul>
- * @return A new {@link ContentDisposition} object.
+ * @return A new {@link BasicParameterizedHeader} object.
*/
- public static ContentDisposition of(Supplier<?> value) {
- if (value == null)
- return null;
- return new ContentDisposition(value);
+ public static BasicParameterizedHeader of(String name, Supplier<?>
value) {
+ return new BasicParameterizedHeader(name, value);
}
/**
- * Constructor.
+ * Constructor
*
+ * @param name The parameter name.
* @param value
- * The parameter value.
* <br>Can be any of the following:
* <ul>
* <li>{@link String}
@@ -123,17 +82,26 @@ public class ContentDisposition extends BasicStringHeader {
* <li>A {@link Supplier} of anything on this list.
* </ul>
*/
- public ContentDisposition(Object value) {
- super("Content-Disposition", value);
+ public BasicParameterizedHeader(String name, Object value) {
+ super(name, value);
}
/**
- * Constructor.
+ * Returns a parameterized value of the header.
*
- * @param value
- * The parameter value.
+ * <p class='bcode w800'>
+ * ContentType ct =
ContentType.<jsm>of</jsm>(<js>"application/json;charset=foo"</js>);
+ * assertEquals(<js>"foo"</js>,
ct.getParameter(<js>"charset"</js>);
+ * </p>
+ *
+ * @param name The parameter name.
+ * @return The parameter value, or <jk>null</jk> if the parameter is
not present.
*/
- public ContentDisposition(String value) {
- super("Content-Disposition", value);
+ public String getParameter(String name) {
+ HeaderElement[] elements = getElements();
+ if (elements.length == 0)
+ return null;
+ NameValuePair p = elements[0].getParameterByName(name);
+ return p == null ? null : p.getValue();
}
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentDisposition.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentDisposition.java
index d87270f..f20ea43 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentDisposition.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentDisposition.java
@@ -50,7 +50,7 @@ import org.apache.juneau.internal.*;
* </ul>
*/
@Header("Content-Disposition")
-public class ContentDisposition extends BasicStringHeader {
+public class ContentDisposition extends BasicParameterizedHeader {
private static final long serialVersionUID = 1L;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentType.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentType.java
index 7a7226a..7899685 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentType.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentType.java
@@ -14,7 +14,6 @@ package org.apache.juneau.http.header;
import static org.apache.juneau.http.header.Constants.*;
-import org.apache.http.*;
import org.apache.juneau.annotation.*;
import org.apache.juneau.http.*;
import org.apache.juneau.http.annotation.Header;
@@ -52,7 +51,9 @@ import org.apache.juneau.internal.*;
*/
@Header("Content-Type")
@BeanIgnore
-public class ContentType extends MediaType implements org.apache.http.Header {
+public class ContentType extends BasicParameterizedHeader {
+
+ private static final long serialVersionUID = 1L;
private static Cache<String,ContentType> CACHE = new Cache<>(NOCACHE,
CACHE_MAX_SIZE);
@@ -71,6 +72,7 @@ public class ContentType extends MediaType implements
org.apache.http.Header {
return ct;
}
+ private final MediaType mediaType;
/**
* Constructor.
@@ -78,7 +80,8 @@ public class ContentType extends MediaType implements
org.apache.http.Header {
* @param value The value for this header.
*/
public ContentType(String value) {
- super(value);
+ super("Content-Type", value);
+ this.mediaType = new MediaType(value);
}
/**
@@ -101,7 +104,7 @@ public class ContentType extends MediaType implements
org.apache.http.Header {
for (int i = 0; i < mediaTypes.length; i++) {
MediaType mt = mediaTypes[i];
- int matchQuant2 = mt.match(this, true);
+ int matchQuant2 = mt.match(mediaType, true);
if (matchQuant2 > matchQuant) {
matchQuant = matchQuant2;
matchIndex = i;
@@ -110,19 +113,12 @@ public class ContentType extends MediaType implements
org.apache.http.Header {
return matchIndex;
}
- @Override /* Header */
- public String getName() {
- return "Content-Type";
- }
-
-
- @Override /* Header */
- public String getValue() {
- return toString();
- }
-
- @Override /* Header */
- public HeaderElement[] getElements() throws ParseException {
- return null;
+ /**
+ * Returns this header as a {@link MediaType} object.
+ *
+ * @return This header as a {@link MediaType} object.
+ */
+ public MediaType asMediaType() {
+ return mediaType;
}
}
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 e2f2c3d..4764317 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
@@ -14,6 +14,7 @@ package org.apache.juneau.rest.client2;
import static org.apache.juneau.assertions.Assertions.*;
import static org.apache.juneau.httppart.HttpPartSchema.*;
+import static org.junit.Assert.*;
import static org.junit.runners.MethodSorters.*;
import static org.apache.juneau.AddFlag.*;
@@ -323,6 +324,33 @@ public class RestClient_Headers_Test {
}
//------------------------------------------------------------------------------------------------------------------
+ // Response methods.
+
//------------------------------------------------------------------------------------------------------------------
+
+ @Rest
+ public static class C extends BasicRest {
+ @RestMethod(path="/")
+ public String getHeader(org.apache.juneau.rest.RestRequest req,
org.apache.juneau.rest.RestResponse res) {
+ String n = req.getHeader("Check");
+ String v = req.getHeaders().getString(n);
+ res.setHeader(n,v);
+ return v;
+ }
+ }
+
+ @Test
+ public void c01_response_getStringHeader() throws Exception {
+ assertEquals("bar",
checkFooClient(C.class).build().get().json().header("Foo","bar").run().getStringHeader("Foo"));
+ assertEquals("bar",
checkFooClient(C.class).build().get().json().header("Foo","bar").run().getStringHeader("Foo","baz"));
+ assertEquals("baz",
checkFooClient(C.class).build().get().json().header("Foo","bar").run().getStringHeader("Bar","baz"));
+ }
+
+ @Test
+ public void c02_response_getCharacterEncoding() throws Exception {
+ assertEquals("iso-8859-1",
checkClient(C.class,"Content-Type").build().get().json().header("Content-Type","application/json;charset=iso-8859-1").run().getCharacterEncoding());
+ }
+
+
//------------------------------------------------------------------------------------------------------------------
// Helper methods.
//------------------------------------------------------------------------------------------------------------------
@@ -346,7 +374,15 @@ public class RestClient_Headers_Test {
return
MockRestClient.create(A.class).simpleJson().header("Check","Foo");
}
+ private static RestClientBuilder checkFooClient(Class<?> c) {
+ return
MockRestClient.create(c).simpleJson().header("Check","Foo");
+ }
+
private static RestClientBuilder checkClient(String headerToCheck) {
return
MockRestClient.create(A.class).simpleJson().header("Check",headerToCheck);
}
+
+ private static RestClientBuilder checkClient(Class<?> c, String
headerToCheck) {
+ return
MockRestClient.create(c).simpleJson().header("Check",headerToCheck);
+ }
}
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Response_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Response_Test.java
index 1547861..533d06a 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Response_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Response_Test.java
@@ -96,11 +96,6 @@ public class RestClient_Response_Test {
assertNull(m.get());
}
-
-
//------------------------------------------------------------------------------------------------------------------
- // Response headers.
-
//------------------------------------------------------------------------------------------------------------------
-
//------------------------------------------------------------------------------------------------------------------
// Helper methods.
//------------------------------------------------------------------------------------------------------------------
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponse.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponse.java
index 10b9435..433c3b0 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponse.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponse.java
@@ -30,6 +30,7 @@ import org.apache.juneau.assertions.*;
import org.apache.juneau.http.header.*;
import org.apache.juneau.httppart.*;
import org.apache.juneau.httppart.bean.*;
+import org.apache.juneau.internal.*;
import org.apache.juneau.utils.*;
/**
@@ -225,8 +226,8 @@ public class RestResponse implements HttpResponse {
* @throws RestCallException If REST call failed.
*/
public String getCharacterEncoding() throws RestCallException {
- Set<String> s = getContentType().getParameters().get("charset");
- return s == null || s.isEmpty() ? "utf-8" : s.iterator().next();
+ String s = getContentType().getParameter("charset");
+ return StringUtils.isEmpty(s) ? "utf-8" : s;
}
/**
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestBody.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestBody.java
index cb3d504..fba59e0 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestBody.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestBody.java
@@ -29,6 +29,7 @@ import org.apache.juneau.httppart.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.http.exception.*;
+import org.apache.juneau.http.header.*;
import org.apache.juneau.rest.util.*;
/**
@@ -348,10 +349,10 @@ public class RequestBody {
private MediaType getMediaType() {
if (mediaType != null)
return mediaType;
- MediaType mediaType = headers.getContentType();
- if (mediaType == null && body != null)
+ ContentType ct = headers.getContentType();
+ if (ct == null && body != null)
return MediaType.UON;
- return mediaType;
+ return ct == null ? null : ct.asMediaType();
}
/**
@@ -462,7 +463,7 @@ public class RequestBody {
throw new UnsupportedMediaType(
"Unsupported media-type in request header
''Content-Type'': ''{0}''\n\tSupported media-types: {1}",
- headers.getContentType(),
req.getParsers().getSupportedMediaTypes()
+ headers.getContentType().getValue(),
req.getParsers().getSupportedMediaTypes()
);
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
index 672482a..c715eb9 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
@@ -31,6 +31,7 @@ import org.apache.juneau.httppart.*;
import org.apache.juneau.httppart.bean.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.http.exception.*;
+import org.apache.juneau.http.header.*;
import org.apache.juneau.rest.util.*;
import org.apache.juneau.serializer.*;
@@ -547,10 +548,14 @@ public final class RestResponse extends
HttpServletResponseWrapper {
// Jetty doesn't set the content type correctly if set through
this method.
// Tomcat/WAS does.
- if (name.equalsIgnoreCase("Content-Type"))
+ if (name.equalsIgnoreCase("Content-Type")) {
super.setContentType(value);
- else
+ ContentType ct = ContentType.of(value);
+ if (ct != null && ct.getParameter("charset") != null)
+
super.setCharacterEncoding(ct.getParameter("charset"));
+ } else {
super.setHeader(name, value);
+ }
}
/**