juneau-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamesbog...@apache.org
Subject incubator-juneau git commit: Testcases.
Date Fri, 12 May 2017 14:26:13 GMT
Repository: incubator-juneau
Updated Branches:
  refs/heads/master 98a53eb31 -> b983a7f62


Testcases.

Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/b983a7f6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/b983a7f6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/b983a7f6

Branch: refs/heads/master
Commit: b983a7f620ff957a4980cfa507d82e513ce28e6b
Parents: 98a53eb
Author: JamesBognar <jamesbognar@apache.org>
Authored: Fri May 12 10:26:09 2017 -0400
Committer: JamesBognar <jamesbognar@apache.org>
Committed: Fri May 12 10:26:09 2017 -0400

----------------------------------------------------------------------
 juneau-core/src/main/javadoc/overview.html      |   2 +
 .../org/apache/juneau/rest/client/RestCall.java |  15 +-
 .../juneau/rest/test/HeadersResource.java       | 129 +++++++++++++-
 .../apache/juneau/rest/test/ParamsResource.java | 125 ++++++++++++-
 .../juneau/rest/test/ParamsResource.properties  |  15 ++
 .../rest/test/ParamsResource_ja_JP.properties   |  15 ++
 .../apache/juneau/rest/test/HeadersTest.java    | 175 ++++++++++++++++++-
 .../org/apache/juneau/rest/test/ParamsTest.java | 140 +++++++++++++++
 .../org/apache/juneau/rest/test/_TestSuite.java |   1 +
 .../org/apache/juneau/rest/RestCallHandler.java |   3 +
 .../apache/juneau/rest/RestParamDefaults.java   |  12 +-
 .../org/apache/juneau/rest/RestResponse.java    |  19 +-
 12 files changed, 625 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b983a7f6/juneau-core/src/main/javadoc/overview.html
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/javadoc/overview.html b/juneau-core/src/main/javadoc/overview.html
index f0bd247..f47b431 100644
--- a/juneau-core/src/main/javadoc/overview.html
+++ b/juneau-core/src/main/javadoc/overview.html
@@ -6083,6 +6083,8 @@
 				</p>
 			<li>A new annotation {@link org.apache.juneau.rest.annotation.RestResource#paramResolvers()
@RestResource.paramResolvers()}
 				that allows you to define your own custom Java method parameter resolvers.
+			<li>Fixed bug where Writer returned by {@link org.apache.juneau.rest.RestResponse#getWriter()}
was not being flushed automatically
+				at the end of the HTTP call.
 		</ul>
 
 		<h6 class='topic'>org.apache.juneau.rest.client</h6>

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b983a7f6/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestCall.java
----------------------------------------------------------------------
diff --git a/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestCall.java
b/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestCall.java
index 7bc9449..5cdcd84 100644
--- a/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestCall.java
+++ b/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestCall.java
@@ -739,7 +739,7 @@ public final class RestCall {
 	 * @return This object (for method chaining).
 	 */
 	public RestCall maxForwards(Object value) {
-		return header("If-Unmodified-Since", value);
+		return header("Max-Forwards", value);
 	}
 
 	/**
@@ -751,7 +751,7 @@ public final class RestCall {
 	 * @return This object (for method chaining).
 	 */
 	public RestCall origin(Object value) {
-		return header("If-Unmodified-Since", value);
+		return header("Origin", value);
 	}
 
 	/**
@@ -1821,4 +1821,15 @@ public final class RestCall {
 		interceptor(new RestCallLogger(level, log));
 		return this;
 	}
+
+	/**
+	 * Sets <code>Debug: value</code> header on this request.
+	 *
+	 * @param value The debug value.
+	 * @return This object (for method chaining).
+	 */
+	public RestCall debug(boolean value) {
+		header("Debug", value);
+		return this;
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b983a7f6/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/HeadersResource.java
----------------------------------------------------------------------
diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/HeadersResource.java
b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/HeadersResource.java
index e5a6265..0a03469 100644
--- a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/HeadersResource.java
+++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/HeadersResource.java
@@ -27,9 +27,10 @@ import org.apache.juneau.rest.annotation.*;
 	path="/testHeaders",
 	serializers=HeadersResource.PlainTextAnythingSerializer.class,
 	parsers=HeadersResource.PlainTextAnythingParser.class,
-	encoders=HeadersResource.IdentityAnythingEncoder.class
+	encoders=HeadersResource.IdentityAnythingEncoder.class,
+	paramResolvers=HeadersResource.CustomHeaderParam.class
 )
-public class HeadersResource extends RestServletDefault {
+public class HeadersResource extends RestServlet {
 	private static final long serialVersionUID = 1L;
 
 	//====================================================================================================
@@ -39,17 +40,135 @@ public class HeadersResource extends RestServletDefault {
 	public String accept(Accept accept) {
 		return accept.toString();
 	}
-
+	@RestMethod(name="GET", path="/acceptCharset")
+	public String acceptCharset(AcceptCharset acceptCharset) {
+		return acceptCharset.toString();
+	}
 	@RestMethod(name="GET", path="/acceptEncoding")
 	public String acceptEncoding(AcceptEncoding acceptEncoding) {
-		System.err.println(acceptEncoding);
 		return acceptEncoding.toString();
 	}
-
+	@RestMethod(name="GET", path="/acceptLanguage")
+	public String acceptLanguage(AcceptLanguage acceptLanguage) {
+		return acceptLanguage.toString();
+	}
+	@RestMethod(name="GET", path="/authorization")
+	public String authorization(Authorization authorization) {
+		return authorization.toString();
+	}
+	@RestMethod(name="GET", path="/cacheControl")
+	public String cacheControl(CacheControl cacheControl) {
+		return cacheControl.toString();
+	}
+	@RestMethod(name="GET", path="/connection")
+	public String connection(Connection connection) {
+		return connection.toString();
+	}
+	@RestMethod(name="GET", path="/contentLength")
+	public String contentLength(ContentLength contentLength) {
+		return contentLength.toString();
+	}
 	@RestMethod(name="GET", path="/contentType")
 	public String contentType(ContentType contentType) {
 		return contentType.toString();
 	}
+	@RestMethod(name="GET", path="/date")
+	public String date(org.apache.juneau.http.Date date) {
+		return date.toString();
+	}
+	@RestMethod(name="GET", path="/expect")
+	public String expect(Expect expect) {
+		return expect.toString();
+	}
+	@RestMethod(name="GET", path="/from")
+	public String from(From from) {
+		return from.toString();
+	}
+	@RestMethod(name="GET", path="/host")
+	public String host(Host host) {
+		return host.toString();
+	}
+	@RestMethod(name="GET", path="/ifMatch")
+	public String IfMatch(IfMatch ifMatch) {
+		return ifMatch.toString();
+	}
+	@RestMethod(name="GET", path="/ifModifiedSince")
+	public String ifModifiedSince(IfModifiedSince ifModifiedSince) {
+		return ifModifiedSince.toString();
+	}
+	@RestMethod(name="GET", path="/ifNoneMatch")
+	public String ifNoneMatch(IfNoneMatch ifNoneMatch) {
+		return ifNoneMatch.toString();
+	}
+	@RestMethod(name="GET", path="/ifRange")
+	public String ifRange(IfRange ifRange) {
+		return ifRange.toString();
+	}
+	@RestMethod(name="GET", path="/ifUnmodifiedSince")
+	public String ifUnmodifiedSince(IfUnmodifiedSince ifUnmodifiedSince) {
+		return ifUnmodifiedSince.toString();
+	}
+	@RestMethod(name="GET", path="/maxForwards")
+	public String maxForwards(MaxForwards maxForwards) {
+		return maxForwards.toString();
+	}
+	@RestMethod(name="GET", path="/pragma")
+	public String pragma(Pragma pragma) {
+		return pragma.toString();
+	}
+	@RestMethod(name="GET", path="/proxyAuthorization")
+	public String proxyAuthorization(ProxyAuthorization proxyAuthorization) {
+		return proxyAuthorization.toString();
+	}
+	@RestMethod(name="GET", path="/range")
+	public String range(Range range) {
+		return range.toString();
+	}
+	@RestMethod(name="GET", path="/referer")
+	public String referer(Referer referer) {
+		return referer.toString();
+	}
+	@RestMethod(name="GET", path="/te")
+	public String te(TE te) {
+		return te.toString();
+	}
+	@RestMethod(name="GET", path="/upgrade")
+	public String upgrade(Upgrade upgrade) {
+		return upgrade.toString();
+	}
+	@RestMethod(name="GET", path="/userAgent")
+	public String userAgent(UserAgent userAgent) {
+		return userAgent.toString();
+	}
+	@RestMethod(name="GET", path="/warning")
+	public String warning(Warning warning) {
+		return warning.toString();
+	}
+	@RestMethod(name="GET", path="/customHeader")
+	public String customHeader(CustomHeader customHeader) {
+		return customHeader.toString();
+	}
+
+	public static class CustomHeaderParam extends RestParam {
+		public CustomHeaderParam() {
+			super(RestParamType.HEADER, "Custom", CustomHeader.class);
+		}
+		@Override
+		public Object resolve(RestRequest req, RestResponse res) throws Exception {
+			return new CustomHeader(req.getHeader("Custom"));
+		}
+	}
+
+	public static class CustomHeader {
+		public String value;
+		public CustomHeader(String value) {
+			this.value = value;
+		}
+		@Override
+		public String toString() {
+			return value;
+		}
+	}
 
 	@Produces("*/*")
 	public static class PlainTextAnythingSerializer extends PlainTextSerializer {

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b983a7f6/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java
----------------------------------------------------------------------
diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java
b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java
index cfd7f15..706b97f 100644
--- a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java
+++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java
@@ -14,18 +14,27 @@ package org.apache.juneau.rest.test;
 
 import static org.apache.juneau.rest.RestContext.*;
 
+import java.io.*;
 import java.util.*;
+import java.util.logging.*;
 
+import javax.servlet.*;
 import javax.servlet.http.*;
 
 import org.apache.juneau.*;
+import org.apache.juneau.dto.swagger.*;
 import org.apache.juneau.examples.addressbook.*;
+import org.apache.juneau.http.*;
+import org.apache.juneau.ini.*;
+import org.apache.juneau.internal.*;
 import org.apache.juneau.json.*;
+import org.apache.juneau.parser.*;
 import org.apache.juneau.plaintext.*;
 import org.apache.juneau.rest.*;
 import org.apache.juneau.rest.annotation.*;
 import org.apache.juneau.transforms.*;
 import org.apache.juneau.urlencoding.*;
+import org.apache.juneau.utils.*;
 
 /**
  * JUnit automated testcase resource.
@@ -36,7 +45,8 @@ import org.apache.juneau.urlencoding.*;
 	properties={
 		@Property(name=REST_allowMethodParam, value="*")
 	},
-	pojoSwaps={CalendarSwap.DateMedium.class}
+	pojoSwaps={CalendarSwap.DateMedium.class},
+	messages="ParamsResource"
 )
 public class ParamsResource extends RestServletDefault {
 	private static final long serialVersionUID = 1L;
@@ -292,4 +302,117 @@ public class ParamsResource extends RestServletDefault {
 	public DTO2s.C testFormPostsWithMultiParamsUsingAnnotation(@Body DTO2s.C content) throws
Exception {
 		return content;
 	}
+
+	//====================================================================================================
+	// Test other available object types as parameters.
+	//====================================================================================================
+
+	@RestMethod(name="GET", path="/otherObjects/ResourceBundle")
+	public String testOtherResourceBundle(ResourceBundle t) {
+		if (t != null)
+			return t.getString("foo");
+		return null;
+	}
+
+	@RestMethod(name="GET", path="/otherObjects/MessageBundle")
+	public String testOtherMessages(MessageBundle t) {
+		if (t != null)
+			return t.getString("foo");
+		return null;
+	}
+
+	@RestMethod(name="POST", path="/otherObjects/InputStream")
+	public String testOtherInputStream(InputStream t) throws IOException {
+		return IOUtils.read(t);
+	}
+
+	@RestMethod(name="POST", path="/otherObjects/ServletInputStream")
+	public String testOtherServletInputStream(ServletInputStream t) throws IOException {
+		return IOUtils.read(t);
+	}
+
+	@RestMethod(name="POST", path="/otherObjects/Reader")
+	public String testOtherReader(Reader t) throws IOException {
+		return IOUtils.read(t);
+	}
+
+	@RestMethod(name="GET", path="/otherObjects/OutputStream")
+	public void testOtherOutputStream(OutputStream t) throws IOException {
+		t.write("OK".getBytes());
+	}
+
+	@RestMethod(name="GET", path="/otherObjects/ServletOutputStream")
+	public void testOtherServletOutputStream(ServletOutputStream t) throws IOException {
+		t.write("OK".getBytes());
+	}
+
+	@RestMethod(name="GET", path="/otherObjects/Writer")
+	public void testOtherWriter(Writer t) throws IOException {
+		t.write("OK");
+	}
+
+	@RestMethod(name="GET", path="/otherObjects/RequestHeaders")
+	public boolean testOtherRequestHeaders(RequestHeaders t) {
+		return t != null;
+	}
+
+	@RestMethod(name="GET", path="/otherObjects/RequestQuery")
+	public boolean testOtherRequestQueryParams(RequestQuery t) {
+		return t != null;
+	}
+
+	@RestMethod(name="GET", path="/otherObjects/RequestFormData")
+	public boolean testOtherRequestFormData(RequestFormData t) {
+		return t != null;
+	}
+
+	@RestMethod(name="GET", path="/otherObjects/HttpMethod")
+	public String testOtherHttpMethod(HttpMethod t) {
+		return t.toString();
+	}
+
+	@RestMethod(name="GET", path="/otherObjects/Logger")
+	public boolean testOtherLogger(Logger t) {
+		return t != null;
+	}
+
+	@RestMethod(name="GET", path="/otherObjects/JuneauLogger")
+	public boolean testOtherJuneauLogger(JuneauLogger t) {
+		return t != null;
+	}
+
+	@RestMethod(name="GET", path="/otherObjects/RestContext")
+	public boolean testOtherRestContext(RestContext t) {
+		return t != null;
+	}
+
+	@RestMethod(name="GET", path="/otherObjects/Parser")
+	public String testOtherParser(Parser t) {
+		return t.getClass().getName();
+	}
+
+	@RestMethod(name="GET", path="/otherObjects/Locale")
+	public String testOtherLocale(Locale t) {
+		return t.toString();
+	}
+
+	@RestMethod(name="GET", path="/otherObjects/Swagger")
+	public boolean testOtherSwagger(Swagger t) {
+		return t != null;
+	}
+
+	@RestMethod(name="GET", path="/otherObjects/RequestPathMatch")
+	public boolean testOtherRequestPathMatch(RequestPathMatch t) {
+		return t != null;
+	}
+
+	@RestMethod(name="GET", path="/otherObjects/RequestBody")
+	public boolean testOtherRequestBody(RequestBody t) {
+		return t != null;
+	}
+
+	@RestMethod(name="GET", path="/otherObjects/ConfigFile")
+	public boolean testOtherConfigFile(ConfigFile t) {
+		return t != null;
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b983a7f6/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/ParamsResource.properties
----------------------------------------------------------------------
diff --git a/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/ParamsResource.properties
b/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/ParamsResource.properties
new file mode 100644
index 0000000..73add61
--- /dev/null
+++ b/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/ParamsResource.properties
@@ -0,0 +1,15 @@
+# ***************************************************************************************************************************
+# * 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.          
                                   *
+# *                                                                                     
                                   *
+# ***************************************************************************************************************************
+
+foo = bar
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b983a7f6/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/ParamsResource_ja_JP.properties
----------------------------------------------------------------------
diff --git a/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/ParamsResource_ja_JP.properties
b/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/ParamsResource_ja_JP.properties
new file mode 100644
index 0000000..336741e
--- /dev/null
+++ b/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/ParamsResource_ja_JP.properties
@@ -0,0 +1,15 @@
+# ***************************************************************************************************************************
+# * 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.          
                                   *
+# *                                                                                     
                                   *
+# ***************************************************************************************************************************
+
+foo = baz
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b983a7f6/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/HeadersTest.java
----------------------------------------------------------------------
diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/HeadersTest.java b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/HeadersTest.java
index 1a96e47..a834210 100644
--- a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/HeadersTest.java
+++ b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/HeadersTest.java
@@ -19,6 +19,8 @@ import org.junit.*;
 
 public class HeadersTest extends RestTestcase {
 
+	RestClient client = TestMicroservice.DEFAULT_CLIENT;
+
 	private static String URL = "/testHeaders";
 
 	//====================================================================================================
@@ -26,9 +28,7 @@ public class HeadersTest extends RestTestcase {
 	//====================================================================================================
 
 	@Test
-	public void testAccept() throws Exception {
-		RestClient client = TestMicroservice.DEFAULT_CLIENT;
-
+	public void accept() throws Exception {
 		assertEquals("text/foo", client.doGet(URL + "/accept").accept("text/foo").getResponseAsString());
 		assertEquals("text/foo+bar", client.doGet(URL + "/accept").accept("text/foo+bar").getResponseAsString());
 		assertEquals("text/*", client.doGet(URL + "/accept").accept("text/*").getResponseAsString());
@@ -37,20 +37,177 @@ public class HeadersTest extends RestTestcase {
 		assertEquals("text/foo", client.doGet(URL + "/accept").accept("text/foo;q=1.0").getResponseAsString());
 		assertEquals("text/foo;q=0.9", client.doGet(URL + "/accept").accept("text/foo;q=0.9").getResponseAsString());
 		assertEquals("text/foo;x=X;q=0.9;y=Y", client.doGet(URL + "/accept").accept("text/foo;x=X;q=0.9;y=Y").getResponseAsString());
+
+		assertEquals("text/foo", client.doGet(URL + "/accept").query("Accept", "text/foo").getResponseAsString());
 	}
 
 	@Test
-	public void testAcceptEncoding() throws Exception {
-		RestClient client = TestMicroservice.DEFAULT_CLIENT;
+	public void acceptCharset() throws Exception {
+		assertEquals("UTF-8", client.doGet(URL + "/acceptCharset").acceptCharset("UTF-8").getResponseAsString());
+		assertEquals("UTF-8", client.doGet(URL + "/acceptCharset").query("Accept-Charset", "UTF-8").getResponseAsString());
+	}
+
+	@Test
+	public void acceptEncoding() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/acceptEncoding").acceptEncoding("foo").getResponseAsString());
+		assertEquals("*", client.doGet(URL + "/acceptEncoding").acceptEncoding("*").getResponseAsString());
+		assertEquals("*", client.doGet(URL + "/acceptEncoding").query("Accept-Encoding", "*").getResponseAsString());
+	}
+
+	@Test
+	public void acceptLanguage() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/acceptLanguage").acceptLanguage("foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/acceptLanguage").query("Accept-Language", "foo").getResponseAsString());
+	}
+
+	@Test
+	public void authorization() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/authorization").authorization("foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/authorization").query("Authorization", "foo").getResponseAsString());
+	}
 
-		assertEquals("foo", client.doGet(URL + "/acceptEncoding").accept("text/plain").acceptEncoding("foo").getResponseAsString());
-		assertEquals("*", client.doGet(URL + "/acceptEncoding").accept("text/plain").acceptEncoding("*").getResponseAsString());
+	@Test
+	public void cacheControl() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/cacheControl").cacheControl("foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/cacheControl").query("Cache-Control", "foo").getResponseAsString());
 	}
 
 	@Test
-	public void testContentType() throws Exception {
+	public void connection() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/connection").connection("foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/connection").query("Connection", "foo").getResponseAsString());
+	}
+
+	@Test
+	public void contentLength() throws Exception {
+		assertEquals("0", client.doGet(URL + "/contentLength").contentLength(0).getResponseAsString());
+		assertEquals("0", client.doGet(URL + "/contentLength").query("Content-Length", 0).getResponseAsString());
+	}
+
+	@Test
+	public void contentType() throws Exception {
+		assertEquals("text/foo", client.doGet(URL + "/contentType").contentType("text/foo").getResponseAsString());
+		assertEquals("text/foo", client.doGet(URL + "/contentType").query("Content-Type", "text/foo").getResponseAsString());
+	}
+
+	@Test
+	public void date() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/date").date("foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/date").query("Date", "foo").getResponseAsString());
+	}
+
+	@Test
+	public void expect() throws Exception {
+		assertEquals("100-continue", client.doGet(URL + "/expect").expect("100-continue").getResponseAsString());
+		assertEquals("100-continue", client.doGet(URL + "/expect").query("Expect", "100-continue").getResponseAsString());
+	}
+
+	@Test
+	public void from() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/from").from("foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/from").query("From", "foo").getResponseAsString());
+	}
+
+	@Test
+	public void host() throws Exception {
+		assertTrue(client.doGet(URL + "/host").host("localhost").getResponseAsString().startsWith("localhost"));
+		assertTrue(client.doGet(URL + "/host").query("Host", "localhost").getResponseAsString().startsWith("localhost"));
+	}
+
+	@Test
+	public void ifMatch() throws Exception {
 		RestClient client = TestMicroservice.DEFAULT_CLIENT;
+		assertEquals("\"foo\"", client.doGet(URL + "/ifMatch").ifMatch("foo").getResponseAsString());
+		assertEquals("\"foo\"", client.doGet(URL + "/ifMatch").ifMatch("\"foo\"").getResponseAsString());
+		assertEquals("W/\"foo\"", client.doGet(URL + "/ifMatch").ifMatch("W/\"foo\"").getResponseAsString());
+		assertEquals("W/\"foo\", \"bar\"", client.doGet(URL + "/ifMatch").ifMatch("W/\"foo\",\"bar\"").getResponseAsString());
+		assertEquals("\"foo\"", client.doGet(URL + "/ifMatch").query("If-Match", "foo").getResponseAsString());
+	}
+
+	@Test
+	public void ifModifiedSince() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/ifModifiedSince").ifModifiedSince("foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/ifModifiedSince").query("If-Modified-Since", "foo").getResponseAsString());
+	}
+
+	@Test
+	public void ifNoneMatch() throws Exception {
+		assertEquals("\"foo\"", client.doGet(URL + "/ifNoneMatch").ifNoneMatch("foo").getResponseAsString());
+		assertEquals("\"foo\"", client.doGet(URL + "/ifNoneMatch").ifNoneMatch("\"foo\"").getResponseAsString());
+		assertEquals("W/\"foo\"", client.doGet(URL + "/ifNoneMatch").ifNoneMatch("W/\"foo\"").getResponseAsString());
+		assertEquals("W/\"foo\", \"bar\"", client.doGet(URL + "/ifNoneMatch").ifNoneMatch("W/\"foo\",\"bar\"").getResponseAsString());
+		assertEquals("\"foo\"", client.doGet(URL + "/ifNoneMatch").query("If-None-Match", "foo").getResponseAsString());
+	}
+
+	@Test
+	public void ifRange() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/ifRange").ifRange("foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/ifRange").query("If-Range", "foo").getResponseAsString());
+	}
+
+	@Test
+	public void ifUnmodifiedSince() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/ifUnmodifiedSince").ifUnmodifiedSince("foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/ifUnmodifiedSince").query("If-Unmodified-Since",
"foo").getResponseAsString());
+	}
+
+	@Test
+	public void maxForwards() throws Exception {
+		assertEquals("123", client.doGet(URL + "/maxForwards").maxForwards(123).getResponseAsString());
+		assertEquals("123", client.doGet(URL + "/maxForwards").query("Max-Forwards", 123).getResponseAsString());
+	}
+
+	@Test
+	public void pragma() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/pragma").pragma("foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/pragma").query("Pragma", "foo").getResponseAsString());
+	}
+
+	@Test
+	public void proxyAuthorization() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/proxyAuthorization").proxyAuthorization("foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/proxyAuthorization").query("Proxy-Authorization",
"foo").getResponseAsString());
+	}
 
-		assertEquals("text/foo", client.doGet(URL + "/contentType").accept("text/plain").contentType("text/foo").getResponseAsString());
+	@Test
+	public void range() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/range").range("foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/range").query("Range", "foo").getResponseAsString());
+	}
+
+	@Test
+	public void referer() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/referer").referer("foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/referer").query("Referer", "foo").getResponseAsString());
+	}
+
+	@Test
+	public void te() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/te").te("foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/te").query("TE", "foo").getResponseAsString());
+	}
+
+	@Test
+	public void upgrade() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/upgrade").upgrade("foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/upgrade").query("Upgrade", "foo").getResponseAsString());
+	}
+
+	@Test
+	public void userAgent() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/userAgent").userAgent("foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/userAgent").query("User-Agent", "foo").getResponseAsString());
+	}
+
+	@Test
+	public void warning() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/warning").warning("foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/warning").query("Warning", "foo").getResponseAsString());
+	}
+
+	@Test
+	public void customHeader() throws Exception {
+		assertEquals("foo", client.doGet(URL + "/customHeader").header("Custom", "foo").getResponseAsString());
+		assertEquals("foo", client.doGet(URL + "/customHeader").query("Custom", "foo").getResponseAsString());
 	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b983a7f6/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/ParamsTest.java
----------------------------------------------------------------------
diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/ParamsTest.java b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/ParamsTest.java
index 77bc2c0..f59295d 100644
--- a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/ParamsTest.java
+++ b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/ParamsTest.java
@@ -16,6 +16,7 @@ import static javax.servlet.http.HttpServletResponse.*;
 import static org.apache.juneau.rest.test.TestUtils.*;
 import static org.junit.Assert.*;
 
+import java.io.*;
 import java.util.*;
 
 import org.apache.http.*;
@@ -31,6 +32,8 @@ public class ParamsTest extends RestTestcase {
 	private static String URL = "/testParams";
 	private static boolean debug = false;
 
+	private static RestClient CLIENT = TestMicroservice.DEFAULT_CLIENT;
+
 	//====================================================================================================
 	// Basic tests
 	//====================================================================================================
@@ -712,4 +715,141 @@ public class ParamsTest extends RestTestcase {
 
 		client.closeQuietly();
 	}
+
+
+	//====================================================================================================
+	// Test other available object types as parameters.
+	//====================================================================================================
+
+	@Test
+	public void testOtherResourceBundle() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/ResourceBundle").acceptLanguage("en-US").getResponseAsString();
+		assertEquals("\"bar\"", r);
+		r = CLIENT.doGet(URL + "/otherObjects/ResourceBundle").acceptLanguage("ja-JP").getResponseAsString();
+		assertEquals("\"baz\"", r);
+	}
+
+	@Test
+	public void testOtherMessages() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/MessageBundle").acceptLanguage("en-US").getResponseAsString();
+		assertEquals("\"bar\"", r);
+		r = CLIENT.doGet(URL + "/otherObjects/MessageBundle").acceptLanguage("ja-JP").getResponseAsString();
+		assertEquals("\"baz\"", r);
+	}
+
+	@Test
+	public void testOtherInputStream() throws IOException {
+		String r = CLIENT.doPost(URL + "/otherObjects/InputStream").input(new StringReader("foo")).getResponseAsString();
+		assertEquals("\"foo\"", r);
+	}
+
+	@Test
+	public void testOtherServletInputStream() throws Exception {
+		String r = CLIENT.doPost(URL + "/otherObjects/ServletInputStream").input(new StringReader("foo")).getResponseAsString();
+		assertEquals("\"foo\"", r);
+	}
+
+	@Test
+	public void testOtherReader() throws Exception {
+		String r = CLIENT.doPost(URL + "/otherObjects/Reader").input(new StringReader("foo")).getResponseAsString();
+		assertEquals("\"foo\"", r);
+	}
+
+	@Test
+	public void testOtherOutputStream() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/OutputStream").getResponseAsString();
+		assertEquals("OK", r);
+	}
+
+	@Test
+	public void testOtherServletOutputStream() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/ServletOutputStream").getResponseAsString();
+		assertEquals("OK", r);
+	}
+
+	@Test
+	public void testOtherWriter() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/Writer").getResponseAsString();
+		assertEquals("OK", r);
+	}
+
+	@Test
+	public void testOtherRequestHeaders() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/RequestHeaders").getResponseAsString();
+		assertEquals("true", r);
+	}
+
+	@Test
+	public void testOtherRequestQuery() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/RequestQuery").getResponseAsString();
+		assertEquals("true", r);
+	}
+
+	@Test
+	public void testOtherRequestFormData() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/RequestFormData").getResponseAsString();
+		assertEquals("true", r);
+	}
+
+	@Test
+	public void testOtherHttpMethod() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/HttpMethod").getResponseAsString();
+		assertEquals("\"GET\"", r);
+	}
+
+	@Test
+	public void testOtherLogger() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/Logger").getResponseAsString();
+		assertEquals("true", r);
+	}
+
+	@Test
+	public void testOtherJuneauLogger() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/JuneauLogger").getResponseAsString();
+		assertEquals("true", r);
+	}
+
+	@Test
+	public void testOtherRestContext() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/RestContext").getResponseAsString();
+		assertEquals("true", r);
+	}
+
+	@Test
+	public void testOtherParser() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/Parser").getResponseAsString();
+		assertEquals("\"org.apache.juneau.json.JsonParser\"", r);
+	}
+
+	@Test
+	public void testOtherLocale() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/Locale").acceptLanguage("en-US").getResponseAsString();
+		assertEquals("\"en_US\"", r);
+		r = CLIENT.doGet(URL + "/otherObjects/Locale").acceptLanguage("ja-JP").getResponseAsString();
+		assertEquals("\"ja_JP\"", r);
+	}
+
+	@Test
+	public void testOtherSwagger() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/Swagger").getResponseAsString();
+		assertEquals("true", r);
+	}
+
+	@Test
+	public void testOtherRequestPathMatch() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/RequestPathMatch").getResponseAsString();
+		assertEquals("true", r);
+	}
+
+	@Test
+	public void testOtherRequestBody() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/RequestBody").getResponseAsString();
+		assertEquals("true", r);
+	}
+
+	@Test
+	public void testOtherConfigFile() throws Exception {
+		String r = CLIENT.doGet(URL + "/otherObjects/ConfigFile").getResponseAsString();
+		assertEquals("true", r);
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b983a7f6/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
----------------------------------------------------------------------
diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
index 985c115..dfb0c54 100644
--- a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
+++ b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
@@ -37,6 +37,7 @@ import org.junit.runners.Suite.*;
 	FormDataTest.class,
 	GroupsTest.class,
 	GzipTest.class,
+	HeadersTest.class,
 	InheritanceTest.class,
 	InterfaceProxyTest.class,
 	JacocoDummyTest.class,

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b983a7f6/juneau-rest/src/main/java/org/apache/juneau/rest/RestCallHandler.java
----------------------------------------------------------------------
diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestCallHandler.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestCallHandler.java
index 676e9ae..99a051c 100644
--- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestCallHandler.java
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestCallHandler.java
@@ -176,6 +176,9 @@ public class RestCallHandler {
 
 			onSuccess(req, res, System.currentTimeMillis() - startTime);
 
+			// Make sure our writer in RestResponse gets written.
+			res.flushBuffer();
+
 		} catch (RestException e) {
 			handleError(r1, r2, e);
 		} catch (Throwable e) {

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b983a7f6/juneau-rest/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
----------------------------------------------------------------------
diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestParamDefaults.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
index 18d0e2f..d75e613 100644
--- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
@@ -96,7 +96,7 @@ class RestParamDefaults {
 			ServletOutputStreamObject.class,
 			WriterObject.class,
 			RequestHeadersObject.class,
-			RequestQueryParamsObject.class,
+			RequestQueryObject.class,
 			RequestFormDataObject.class,
 			HttpMethodObject.class,
 			LoggerObject.class,
@@ -105,7 +105,7 @@ class RestParamDefaults {
 			ParserObject.class,
 			LocaleObject.class,
 			SwaggerObject.class,
-			RequestPathParamsObject.class,
+			RequestPathMatchObject.class,
 			RequestBodyObject.class,
 			ConfigFileObject.class,
 		};
@@ -794,9 +794,9 @@ class RestParamDefaults {
 		}
 	}
 
-	static final class RequestQueryParamsObject extends RestParam {
+	static final class RequestQueryObject extends RestParam {
 
-		protected RequestQueryParamsObject() {
+		protected RequestQueryObject() {
 			super(OTHER, null, RequestQuery.class);
 		}
 
@@ -902,9 +902,9 @@ class RestParamDefaults {
 		}
 	}
 
-	static final class RequestPathParamsObject extends RestParam {
+	static final class RequestPathMatchObject extends RestParam {
 
-		protected RequestPathParamsObject() {
+		protected RequestPathMatchObject() {
 			super(OTHER, null, RequestPathMatch.class);
 		}
 

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b983a7f6/juneau-rest/src/main/java/org/apache/juneau/rest/RestResponse.java
----------------------------------------------------------------------
diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestResponse.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestResponse.java
index 2bde785..524c8f3 100644
--- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestResponse.java
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestResponse.java
@@ -61,6 +61,7 @@ public final class RestResponse extends HttpServletResponseWrapper {
 	UrlEncodingSerializer urlEncodingSerializer;         // The serializer used to convert arguments
passed into Redirect objects.
 	private EncoderGroup encoders;
 	private ServletOutputStream os;
+	private PrintWriter w;
 
 	/**
 	 * Constructor.
@@ -361,14 +362,17 @@ public final class RestResponse extends HttpServletResponseWrapper {
 	}
 
 	private PrintWriter getWriter(boolean raw) throws IOException {
+		if (w != null)
+			return w;
+
 		// If plain text requested, override it now.
-		if (request.isPlainText()) {
+		if (request.isPlainText()) 
 			setHeader("Content-Type", "text/plain");
-		}
 
 		try {
 			OutputStream out = (raw ? getOutputStream() : getNegotiatedOutputStream());
-			return new PrintWriter(new OutputStreamWriter(out, getCharacterEncoding()));
+			w = new PrintWriter(new OutputStreamWriter(out, getCharacterEncoding()));
+			return w;
 		} catch (UnsupportedEncodingException e) {
 			String ce = getCharacterEncoding();
 			setCharacterEncoding("UTF-8");
@@ -477,4 +481,13 @@ public final class RestResponse extends HttpServletResponseWrapper {
 		properties.put(HtmlDocSerializerContext.HTMLDOC_links, links);
 		return this;
 	}
+
+	@Override /* ServletResponse */
+	public void flushBuffer() throws IOException {
+		if (w != null)
+			w.flush();
+		if (os != null)
+			os.flush();
+		super.flushBuffer();
+	}
 }
\ No newline at end of file



Mime
View raw message