You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2021/11/08 20:54:13 UTC
[juneau] branch master updated: Javadocs and Rest Server API
improvements.
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 93472f7 Javadocs and Rest Server API improvements.
93472f7 is described below
commit 93472f759a7d2bfb5fcdbfec922881b06c337442
Author: JamesBognar <ja...@salesforce.com>
AuthorDate: Mon Nov 8 15:52:50 2021 -0500
Javadocs and Rest Server API improvements.
---
.../java/org/apache/juneau/http/HttpParts.java | 30 +-
.../01.RestmRequestHeaders.html | 58 --
.../02.RestmRequestAttributes.html | 46 --
.../03.RestmRequestQuery.html | 63 ---
.../04.RestmRequestFormData.html | 58 --
.../05.RestmRequestPathMatch.html | 55 --
.../06.RestmReaderResource.html | 42 --
.../07.RestmStreamResource.html | 38 --
.../08.RestmMatchers.html | 70 ---
.../09.RestmPredefinedResponses.html | 126 -----
.../10.RestmPredefinedHelperBeans.html | 226 --------
juneau-doc/src/main/javadoc/overview.html | 630 +--------------------
juneau-doc/src/main/javadoc/resources/docs.txt | 9 -
.../org/apache/juneau/rest/RequestAttribute.java | 2 +-
.../org/apache/juneau/rest/RequestAttributes.java | 70 ++-
.../java/org/apache/juneau/rest/RequestBody.java | 32 +-
.../org/apache/juneau/rest/RequestFormParam.java | 111 ----
.../org/apache/juneau/rest/RequestFormParams.java | 157 ++---
.../java/org/apache/juneau/rest/RequestHeader.java | 47 --
.../org/apache/juneau/rest/RequestHeaders.java | 140 ++---
.../org/apache/juneau/rest/RequestHttpPart.java | 183 +++++-
.../org/apache/juneau/rest/RequestPathParam.java | 103 ----
.../org/apache/juneau/rest/RequestPathParams.java | 129 ++---
.../org/apache/juneau/rest/RequestQueryParam.java | 112 ----
.../org/apache/juneau/rest/RequestQueryParams.java | 158 +++---
.../java/org/apache/juneau/rest/RestOpInvoker.java | 2 +-
.../java/org/apache/juneau/rest/RestRequest.java | 24 +-
.../org/apache/juneau/rest/args/AttributeArg.java | 4 +-
.../java/org/apache/juneau/rest/args/BodyArg.java | 4 +-
.../org/apache/juneau/rest/args/FormDataArg.java | 8 +-
.../org/apache/juneau/rest/args/HeaderArg.java | 6 +-
.../java/org/apache/juneau/rest/args/PathArg.java | 4 +-
.../java/org/apache/juneau/rest/args/QueryArg.java | 8 +-
.../assertions/FluentRequestBodyAssertion.java | 20 +-
.../FluentRequestFormParamAssertion.java | 16 +-
.../assertions/FluentRequestHeaderAssertion.java | 14 +-
.../FluentRequestQueryParamAssertion.java | 14 +-
.../apache/juneau/rest/widget/MenuItemWidget.java | 2 +-
.../juneau/rest/annotation/FormData_Test.java | 8 +-
.../apache/juneau/rest/annotation/Query_Test.java | 18 +-
.../juneau/rest/annotation/RestHook_Test.java | 2 +-
.../rest/annotation/RestOp_ReqHeaders_Test.java | 36 +-
.../annotation/Rest_AllowedHeaderParams_Test.java | 6 +-
43 files changed, 687 insertions(+), 2204 deletions(-)
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/HttpParts.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/HttpParts.java
index 5e1e261..3081674 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/HttpParts.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/HttpParts.java
@@ -487,15 +487,37 @@ public class HttpParts {
*/
public static Optional<String> getName(HttpPartType partType, ClassMeta<?> type) {
switch(partType) {
- case FORMDATA: return type.getProperty("HttpPartName.FormData", FORMDATA_NAME_FUNCTION);
- case HEADER: return type.getProperty("HttpPartName.Header", HEADER_NAME_FUNCTION);
- case PATH: return type.getProperty("HttpPartName.Path", PATH_NAME_FUNCTION);
- case QUERY: return type.getProperty("HttpPartName.Query", QUERY_NAME_FUNCTION);
+ case FORMDATA: return type.getProperty("HttpPart.formData.name", FORMDATA_NAME_FUNCTION);
+ case HEADER: return type.getProperty("HttpPart.header.name", HEADER_NAME_FUNCTION);
+ case PATH: return type.getProperty("HttpPart.path.name", PATH_NAME_FUNCTION);
+ case QUERY: return type.getProperty("HttpPart.query.name", QUERY_NAME_FUNCTION);
default: return Optional.empty();
}
}
/**
+ * Returns <jk>true</jk> if the specified type is a part type.
+ *
+ * <p>
+ * A part type extends from either {@link org.apache.http.Header} or {@link org.apache.http.NameValuePair}
+ * or is annotated with {@link org.apache.juneau.http.annotation.Header}, {@link org.apache.juneau.http.annotation.Query},
+ * {@link org.apache.juneau.http.annotation.FormData}, or {@link org.apache.juneau.http.annotation.Path}.
+ *
+ * @param partType The part type.
+ * @param type The type to check.
+ * @return <jk>true</jk> if the specified type is a part type.
+ */
+ public static boolean isHttpPart(HttpPartType partType, ClassMeta<?> type) {
+ switch(partType) {
+ case PATH:
+ case QUERY:
+ case FORMDATA: return type.getProperty("HttpPart.isNameValuePair", x->x.isChildOf(NameValuePair.class)).orElse(false);
+ case HEADER: return type.getProperty("HttpPart.isHeader", x->x.isChildOf(org.apache.http.Header.class)).orElse(false);
+ default: return false;
+ }
+ }
+
+ /**
* Returns the constructor for the specified type.
*
* <p>
diff --git a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/01.RestmRequestHeaders.html b/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/01.RestmRequestHeaders.html
deleted file mode 100644
index ca529e6..0000000
--- a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/01.RestmRequestHeaders.html
+++ /dev/null
@@ -1,58 +0,0 @@
-<!--
-/***************************************************************************************************************************
- * 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.
- ***************************************************************************************************************************/
- -->
-
-{title:'RequestHeaders', flags:'todo'}
-
-<p>
- The {@link oajr.RequestHeaders} object is the API for accessing the headers of an HTTP request.
- It can be accessed by passing it as a parameter on your REST Java method:
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestHeaders <jv>headers</jv>) {...}
-</p>
-<h5 class='figure'>Example:</h5>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestHeaders <jv>headers</jv>) {
-
- <jc>// Add a default value.</jc>
- <jv>headers</jv>.addDefault(<js>"ETag"</js>, <jsf>DEFAULT_UUID</jsf>);
-
- <jc>// Get a header value as a POJO.</jc>
- UUID <jv>etag</jv> = <jv>headers</jv>.get(<js>"ETag"</js>, UUID.<jk>class</jk>);
-
- <jc>// Get a standard header.</jc>
- CacheControl <jv>cacheControl</jv> = <jv>headers</jv>.getCacheControl().orElse(<jk>null</jk>);
- }
-</p>
-<p>
- Some important methods on this class are:
-</p>
-<ul class='javatree'>
- <li class='jc'><c>{@link oajr.RequestHeaders} <jk>extends</jk> TreeMap<String,String[]></c>
- <ul>
- <li class='jm'>{@del RequestHeaders#get(String,Class)} - Get header value converted to a POJO.
- <li class='jm'>{@del RequestHeaders#get(String,Type,Type...)} - Get header value converted to a map or collection of POJOs.
- <li class='jm'>{@del RequestHeaders#getString(String,String)} - Get header value as a simple string.
- <li class='jm'>{@del RequestHeaders#getInt(String,int)} - Get header value as an integer.
- <li class='jm'>{@del RequestHeaders#getBoolean(String,boolean)} - Get header value as a boolean.
- <li class='jm'>{@del RequestHeaders#addDefault(String,Object)} - Programmatically set a default value for a header.
- </ul>
-</ul>
-
-<ul class='seealso'>
- <li class='ja'>{@link oaj.http.annotation.Header}
-</ul>
diff --git a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/02.RestmRequestAttributes.html b/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/02.RestmRequestAttributes.html
deleted file mode 100644
index d778eed..0000000
--- a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/02.RestmRequestAttributes.html
+++ /dev/null
@@ -1,46 +0,0 @@
-<!--
-/***************************************************************************************************************************
- * 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.
- ***************************************************************************************************************************/
- -->
-
-{title:'RequestAttributes', created:'8.1.0', flags:'todo'}
-
-<p>
- The {@link oajr.RequestAttributes} object is the API for accessing the standard servlet attributes on an HTTP request
- (i.e. {@link javax.servlet.ServletRequest#getAttribute(String)}.
- It wraps the request attributes in a {@link java.util.Map} interface and provides several convenience methods.
-</p>
-<p>
- The <c>RequestAttributes</c> object extends from {@link oaj.collections.OMap} so all the convenience methods defined on
- that API are also available when working with request attributes:
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestAttributes <jv>attributes</jv>) {...}
-</p>
-<h5 class='figure'>Example:</h5>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestAttributes <jv>attributes</jv>) {
-
- <jc>// Add a default value.</jc>
- <jv>attributes</jv>.putIfNotExists(<js>"Foo"</js>, 123);
-
- <jc>// Get an attribute value as a POJO.</jc>
- UUID <jv>etag</jv> = <jv>attributes</jv>.get(<js>"ETag"</js>, UUID.<jk>class</jk>);
- }
-</p>
-<p>
- Modifications made to request attributes through the <c>RequestAttributes</c> bean are automatically reflected in
- the underlying servlet request attributes making it possible to mix the usage of both APIs.
-</p>
diff --git a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/03.RestmRequestQuery.html b/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/03.RestmRequestQuery.html
deleted file mode 100644
index 7fed766..0000000
--- a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/03.RestmRequestQuery.html
+++ /dev/null
@@ -1,63 +0,0 @@
-<!--
-/***************************************************************************************************************************
- * 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.
- ***************************************************************************************************************************/
- -->
-
-{title:'RequestQuery', flags:'todo'}
-
-<p>
- The {@link oajr.RequestQuery} object is the API for accessing the GET query parameters of an HTTP request.
- It can be accessed by passing it as a parameter on your REST Java method:
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestQuery <jv>query</jv>) {...}
-</p>
-<h5 class='figure'>Example:</h5>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestQuery <jv>query</jv>) {
-
- <jc>// Get query parameters converted to various types.</jc>
- <jk>int</jk> <jv>p1</jv> = <jv>query</jv>.get(<js>"p1"</js>, 0, <jk>int</jk>.<jk>class</jk>);
- String <jv>p2</jv> = <jv>query</jv>.get(<js>"p2"</js>, String.<jk>class</jk>);
- UUID <jv>p3</jv> = <jv>query</jv>.get(<js>"p3"</js>, UUID.<jk>class</jk>);
- }
-</p>
-<p>
- An important distinction between the behavior of this object and <l>HttpServletRequest.getParameter(String)</l> is
- that the former will NOT load the body of the request on FORM POSTS and will only look at parameters
- found in the query string.
- This can be useful in cases where you're mixing GET parameters and FORM POSTS and you don't want to
- inadvertently read the body of the request to get a query parameter.
-</p>
-<p>
- Some important methods on this class are:
-</p>
-<ul class='javatree'>
- <li class='jc'><c>{@link oajr.RequestQuery} <jk>extends</jk> LinkedHashMap<String,String[]></c>
- <ul>
- <li class='jm'>{@del RequestQuery#get(String,Class)} - Get query parameter value converted to a POJO.
- <li class='jm'>{@del RequestQuery#get(String,Type,Type...)} - Get query parameter value converted to a map or collection of POJOs.
- <li class='jm'>{@del RequestQuery#getString(String,String)} - Get query parameter value as a simple string.
- <li class='jm'>{@del RequestQuery#getInt(String,int)} - Get query parameter value as an integer.
- <li class='jm'>{@del RequestQuery#getBoolean(String,boolean)} - Get query parameter value as a boolean.
- <li class='jm'>{@del RequestQuery#addDefault(String,Object)} - Programmatically set a default value for a query parameter.
- <li class='jm'>{@del RequestQuery#getSearchArgs()} - Returns query parameter search arguments.
- </ul>
-</ul>
-
-<ul class='seealso'>
- <li class='ja'>{@link oaj.http.annotation.Query}
- <li class='ja'>{@link oaj.http.annotation.HasQuery}
-</ul>
diff --git a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/04.RestmRequestFormData.html b/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/04.RestmRequestFormData.html
deleted file mode 100644
index 901381f..0000000
--- a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/04.RestmRequestFormData.html
+++ /dev/null
@@ -1,58 +0,0 @@
-<!--
-/***************************************************************************************************************************
- * 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.
- ***************************************************************************************************************************/
- -->
-
-{title:'RequestFormData', flags:'todo'}
-
-<p>
- The {@link oajr.RequestFormData} object is the API for accessing the HTTP request body as form data.
- It can be accessed by passing it as a parameter on your REST Java method:
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestFormData <jv>formData</jv>) {...}
-</p>
-<h5 class='figure'>Example:</h5>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestFormData <jv>formData</jv>) {
-
- <jc>// Get query parameters converted to various types.</jc>
- <jk>int</jk> <jv>p1</jv> = <jv>formData</jv>.get(<js>"p1"</js>, 0, <jk>int</jk>.<jk>class</jk>);
- String <jv>p2</jv> = <jv>formData<jv>.get(<js>"p2"</js>, String.<jk>class</jk>);
- UUID <jv>p3</jv> = <jv>formData</jv>.get(<js>"p3"</js>, UUID.<jk>class</jk>);
- }
-</p>
-<p>
- Note that this object does NOT take GET parameters into account and only returns values found in the body of the request.
-</p>
-<p>
- Some important methods on this class are:
-</p>
-<ul class='javatree'>
- <li class='jc'><c>{@link oajr.RequestFormData} <jk>extends</jk> LinkedHashMap<String,String[]></c>
- <ul>
- <li class='jm'>{@del RequestFormData#get(String,Class)} - Get form-data parameter values converted to a POJO.
- <li class='jm'>{@del RequestFormData#get(String,Type,Type...)} - Get form-data parameter value converted to a map or collection of POJOs.
- <li class='jm'>{@del RequestFormData#getString(String,String)} - Get form-data parameter value as a simple string.
- <li class='jm'>{@del RequestFormData#getInt(String,int)} - Get form-data parameter value as an integer.
- <li class='jm'>{@del RequestFormData#getBoolean(String,boolean)} - Get form-data parameter value as a boolean.
- <li class='jm'>{@del RequestFormData#addDefault(String,Object)} - Programmatically set a default value for a form-data parameter.
- </ul>
-</ul>
-
-<ul class='seealso'>
- <li class='ja'>{@link oaj.http.annotation.FormData}
- <li class='ja'>{@link oaj.http.annotation.HasFormData}
-</ul>
diff --git a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/05.RestmRequestPathMatch.html b/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/05.RestmRequestPathMatch.html
deleted file mode 100644
index 17cc27b..0000000
--- a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/05.RestmRequestPathMatch.html
+++ /dev/null
@@ -1,55 +0,0 @@
-<!--
-/***************************************************************************************************************************
- * 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.
- ***************************************************************************************************************************/
- -->
-
-{title:'RequestPathMatch', flags:'todo'}
-
-<p>
- The {@link oajr.RequestPath} object is the API for accessing the matched variables
- and remainder on the URL path.
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestPathMatch <jv>path</jv>) {...}
-</p>
-<h5 class='figure'>Example:</h5>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(..., path=<js>"/{foo}/{bar}/{baz}/*"</js>)
- <jk>public void</jk> doGet(RequestPathMatch <jv>pathMatch</jv>) {
- <jc>// Example URL: /123/qux/true/quux</jc>
-
- <jk>int</jk> <jv>foo</jv> = <jv>pathMatch</jv>.getInt(<js>"foo"</js>); <jc>// =123</jc>
- String <jv>bar</jv> = <jv>pathMatch</jv>.getString(<js>"bar"</js>); <jc>// =qux</jc>
- <jk>boolean</jk> <jv>baz</jv> = <jv>pathMatch</jv>.getBoolean(<js>"baz"</js>); <jc>// =true</jc>
- String <jv>remainder</jv> = <jv>pathMatch</jv>.getRemainder(); <jc>// =quux</jc>
- }
-</p>
-<p>
- Some important methods on this class are:
-</p>
-<ul class='javatree'>
- <li class='jc'><c>{@link oajr.RequestPath} <jk>extends</jk> TreeMap<String,String></c>
- <ul>
- <li class='jm'>{@del RequestPath#get(String,Class)} - Get path match variable converted to a POJO.
- <li class='jm'>{@del RequestPath.get(String,Type,Type...)} - Get path match variable converted to a map or collection of POJOs.
- <li class='jm'>{@del RequestPath#getString(String)} - Get patch match variable as a simple string.
- <li class='jm'>{@del RequestPath#getInt(String)} - Get path match variable as an integer.
- <li class='jm'>{@del RequestPath#getBoolean(String)} - Get path match variable as a boolean.
- <li class='jm'>{@del RequestPath#getRemainder()} - Get the path match remainder.
- </ul>
-</ul>
-
-<ul class='seealso'>
- <li class='ja'>{@link oaj.http.annotation.Path}
-</ul>
diff --git a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/06.RestmReaderResource.html b/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/06.RestmReaderResource.html
deleted file mode 100644
index ba90afb..0000000
--- a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/06.RestmReaderResource.html
+++ /dev/null
@@ -1,42 +0,0 @@
-<!--
-/***************************************************************************************************************************
- * 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.
- ***************************************************************************************************************************/
- -->
-
-{title:'ReaderResource', flags:'todo'}
-
-<p>
- The {@del ReaderResource} class is a convenience object for defining thread-safe
- reusable character-based responses.
- In essence, it's a container for character data with optional response headers and support for
- resolving SVL variables.
-</p>
-
-<p>
- The class is annotated with {@link oaj.http.annotation.Response @Response}
- which allows it to be returned as responses by REST methods.
-</p>
-<h5 class='figure'>Example:</h5>
-<p class='bpcode w800'>
- <ja>@RestGet</ja>
- <jk>public</jk> Object sayHello(RestRequest <jv>req</jv>) {
-
- <jc>// Return a reader resource loaded from a file with support for request-time SVL variables.</jc>
- <jk>return</jk> ReaderResource.<jsm>create</jsm>()
- .contents(<jk>new</jk> File(<js>"helloWorld.txt"</js>))
- .varResolver(<jv>req</jv>.getVarResolver())
- .header(<js>"Cache-Control"</js>, <js>"no-cache"</js>)
- .mediaType(<jsf>TEXT_PLAIN</jsf>)
- .build();
- }
-</p>
diff --git a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/07.RestmStreamResource.html b/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/07.RestmStreamResource.html
deleted file mode 100644
index c6a42e2..0000000
--- a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/07.RestmStreamResource.html
+++ /dev/null
@@ -1,38 +0,0 @@
-<!--
-/***************************************************************************************************************************
- * 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.
- ***************************************************************************************************************************/
- -->
-
-{title:'StreamResource', flags:'todo'}
-
-<p>
- The {@del oaj.http.StreamResource} class is the binary equivalent to the {@del ReaderResource} object.
- In essence, it's a container for binary data with optional response headers.
-</p>
-<p>
- The class is annotated with {@link oaj.http.annotation.Response @Response}
- which allows it to be returned as responses by REST methods.
-</p>
-<h5 class='figure'>Example:</h5>
-<p class='bpcode w800'>
- <ja>@RestGet</ja>(...)
- <jk>public</jk> Object showPicture(RestRequest <jv>req</jv>) {
-
- <jc>// Return a stream resource loaded from a file.</jc>
- <jk>return</jk> StreamResource.<jsm>create</jsm>()
- .contents(<jk>new</jk> File(<js>"mypicture.png"</js>))
- .header(<js>"Cache-Control"</js>, <js>"no-cache"</js>)
- .mediaType(<jsf>IMAGE_PNG</jsf>)
- .build();
- }
-</p>
diff --git a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/08.RestmMatchers.html b/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/08.RestmMatchers.html
deleted file mode 100644
index c67eab9..0000000
--- a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/08.RestmMatchers.html
+++ /dev/null
@@ -1,70 +0,0 @@
-<!--
-/***************************************************************************************************************************
- * 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.
- ***************************************************************************************************************************/
- -->
-
-{title:'@RestOp(matchers)', flags:'todo'}
-
-<p>
- {@link oajr.RestMatcher RestMatchers} are used to allow multiple Java methods to be
- tied to the same HTTP method and path, but differentiated by some request attribute such as a specific
- header value.
-</p>
-<h5 class='figure'>Example:</h5>
-<p class='bpcode w800'>
- <jc>// GET method that gets invoked for administrators</jc>
- <ja>@RestGet</ja>(path=<js>"/*"</js>, matchers=IsAdminMatcher.<jk>class</jk>)
- <jk>public</jk> Object doGetForAdmin() {
- ...
- }
-
- <jc>// GET method that gets invoked for everyone else</jc>
- <ja>@RestGet</ja>(<js>"/*"</js>)
- <jk>public</jk> Object doGetForEveryoneElse() {
- ...
- }
-</p>
-<p>
- The interface for matchers is simple:
-</p>
-<p class='bpcode w800'>
- <jk>public class</jk> IsAdminMatcher <jk>extends</jk> RestMatcher {
-
- <ja>@Override</ja> <jc>/* RestMatcher */</jc>
- <jk>public boolean</jk> matches(RestRequest <jv>req</jv>) {
- <jk>return</jk> <jv>req</jv>.isUserInRole(<js>"ADMINS_GROUP"</js>);
- }
- }
-</p>
-
-<ul class='notes'>
- <li>
- If no methods are found with a matching matcher, a <l>412 Precondition Failed</l> status is returned.
- <li>
- If multiple matchers are specified on the same method, ONLY ONE matcher needs to match for the
- method to be invoked.
- <li>
- Note that you CANNOT define identical paths on different methods UNLESS you use matchers.
- <br>That includes paths that are only different in variable names (e.g. <l>"/foo/{bar}"</l> and
- <l>"/foo/{baz}"</l>).
- <br>If you try to do so, a <l>ServletException</l> will be thrown on startup.
- <li>
- Methods with matchers take precedence over methods without.
- <br>Otherwise, methods are attempted in the order they appear in the class.
-</ul>
-
-<ul class='seealso'>
- <li class='ja'>{@link oajr.annotation.RestOp#matchers RestOp(matchers)}
- <li class='jc'>{@link oajr.matchers.MultipartFormDataMatcher}
- <li class='jc'>{@link oajr.matchers.UrlEncodedFormMatcher}
-</ul>
diff --git a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/09.RestmPredefinedResponses.html b/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/09.RestmPredefinedResponses.html
deleted file mode 100644
index 3f5f83d..0000000
--- a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/09.RestmPredefinedResponses.html
+++ /dev/null
@@ -1,126 +0,0 @@
-<!--
-/***************************************************************************************************************************
- * 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.
- ***************************************************************************************************************************/
- -->
-
-{title:'Predefined Responses', flags:'todo'}
-
-<p>
- Predefined response beans are provided for all standard HTTP responses.
- These can be used as-is or extended to provide customized HTTP responses.
-</p>
-<h5 class='figure'>Examples:</h5>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(<js>"/pets"</js>)
- <jk>public</jk> Ok addPet(<ja>@Body</ja> Pet <jv>pet</jv>) {
- <jsm>addPet</jsm>(<jv>pet</jv>);
-
- <jc>// Predefined "200 OK" response bean.</jc>
- <jk>return new</jk> Ok(); <jc>// Could also use Ok.OK instance</jc>
- }
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(<js>"/pets"</js>)
- <jk>public</jk> SeeOther addPet(<ja>@Body</ja> Pet <jv>pet</jv>) {
- <jsm>addPet</jsm>(<jv>pet</jv>);
-
- <jc>// Predefined "302 See Other" response bean with redirect to /pets.</jc>
- <jk>return new</jk> SeeOther(<js>"servlet:/pets"</js>);
- }
-</p>
-<ul class='javatree'>
- <li class='jp'>{@link oaj.http.response}
- <ul>
- <li class='jc'>{@link oaj.http.response.Accepted}
- <li class='jc'>{@link oaj.http.response.AlreadyReported}
- <li class='jc'>{@link oaj.http.response.Continue}
- <li class='jc'>{@link oaj.http.response.Created}
- <li class='jc'>{@link oaj.http.response.EarlyHints}
- <li class='jc'>{@link oaj.http.response.Found}
- <li class='jc'>{@link oaj.http.response.IMUsed}
- <li class='jc'>{@link oaj.http.response.MovedPermanently}
- <li class='jc'>{@link oaj.http.response.MultipleChoices}
- <li class='jc'>{@link oaj.http.response.MultiStatus}
- <li class='jc'>{@link oaj.http.response.NoContent}
- <li class='jc'>{@link oaj.http.response.NonAuthoritiveInformation}
- <li class='jc'>{@link oaj.http.response.NotModified}
- <li class='jc'>{@link oaj.http.response.Ok}
- <li class='jc'>{@link oaj.http.response.PartialContent}
- <li class='jc'>{@link oaj.http.response.PermanentRedirect}
- <li class='jc'>{@link oaj.http.response.Processing}
- <li class='jc'>{@link oaj.http.response.ResetContent}
- <li class='jc'>{@link oaj.http.response.SeeOther}
- <li class='jc'>{@link oaj.http.response.SwitchingProtocols}
- <li class='jc'>{@link oaj.http.response.TemporaryRedirect}
- <li class='jc'>{@link oaj.http.response.UseProxy}
- </ul>
-</ul>
-<p>
- These predefined response beans are an example of {@link oaj.http.annotation.Response @Response}-annotated
- objects that are describe in detail later.
- Without going into details, this is how the {@link oaj.http.response.SeeOther} is defined:
-</p>
-<p class='bpcode w800'>
- <ja>@Response</ja>(
- code=303 <jc>// Set automatically on response</jc>,
- description=<js>"See Other"</js> <jc>// Used in generated Swagger</jc>
- )
- <jk>public class</jk> SeeOther {
-
- <jk>private final</jk> String <jf>message</jf>;
- <jk>private final</jk> URI <jf>location</jf>;
-
- <jc>// Constructors omitted.</jc>
-
- <jc>// Used to populate Location response header.</jc>
- <ja>@ResponseHeader</ja>(name=<js>"Location"</js>)
- <jk>public</jk> URI getLocation() {
- <jk>return</jk> <jf>location</jf>;
- }
-
- <jc>// Used during serialization.</jc>
- <ja>@ResponseBody</ja>
- <jk>public</jk> String toString() {
- <jk>return</jk> <jf>message</jf>;
- }
- }
-</p>
-<p>
- The {@link oajr.helper.SeeOtherRoot} class shows how these predefined beans can be extended.
-</p>
-<p class='bpcode w800'>
- <ja>@Response</ja>(
- description=<js>"Redirect to servlet root"</js> <jc>// Override description in generated Swagger.</jc>
- )
- <jk>public class</jk> SeeOtherServletRoot <jk>extends</jk> SeeOther {
-
- <jk>public</jk> SeeOtherServletRoot() {
- <jk>super</jk>(URI.<jsm>create</jsm>(<js>"servlet:/"</js>));
- }
- }
-</p>
-<p>
- Note that the runtime behavior of the following code is identical to the example above.
- However, the important distinction is that in the previous example, the 302 response would show in
- the generated Swagger (since we can see the response through reflection), whereas it will NOT show up
- in the following example (since all we see is an Object response).
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(<js>"/pets"</js>)
- <jk>public</jk> Object addPet(<ja>@Body</ja> Pet <jv>pet</jv>) {
- <jsm>addPet</jsm>(<jv>pet</jv>);
-
- <jc>// Note the Object return type.</jc>
- <jk>return new</jk> SeeOther(<js>"servlet:/pets"</js>);
- }
-</p>
diff --git a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/10.RestmPredefinedHelperBeans.html b/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/10.RestmPredefinedHelperBeans.html
deleted file mode 100644
index 74dbe55..0000000
--- a/juneau-doc/docs/Topics/06.juneau-rest-server/03.RestOpAnnotatedMethods/10.RestmPredefinedHelperBeans.html
+++ /dev/null
@@ -1,226 +0,0 @@
-<!--
-/***************************************************************************************************************************
- * 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.
- ***************************************************************************************************************************/
- -->
-
-{title:'Predefined Helper Beans', flags:'todo'}
-
-<p>
- The {@link oajr.helper} package contains several predefined beans to help when constructing
- REST interfaces.
-</p>
-<ul class='javatree'>
- <li class='jp'>{@link oajr.helper}
- <ul>
- <li class='jc'>{@link oajr.helper.BeanDescription}
- <li class='jc'>{@link oajr.helper.ChildResourceDescriptions}
- <li class='jc'>{@link oajr.helper.ResourceDescription}
- <li class='jc'>{@link oajr.helper.ResourceDescriptions}
- <li class='jc'>{@link oajr.helper.SeeOtherRoot}
- </ul>
-</ul>
-
-<h5 class='topic'>ResourceDescription, ResourceDescrptions</h5>
-<p>
- The {@link oajr.helper.ResourceDescription} class is a bean with name/description
- properties for labeling and linking to child resources.
- The following examples is pulled from the REST examples:
-</p>
-<p class='bpcode w800'>
- <ja>@Resource</ja>
- <jk>public class</jk> PredefinedLabelsResource {
-
- <ja>@RestGet</ja>(<js>"/"</js>)
- <jk>public</jk> ResourceDescription[] getChildMethods() {
- <jk>return new</jk> ResourceDescription[] {
- <jk>new</jk> ResourceDescription(<js>"beanDescription"</js>, <js>"BeanDescription"</js>),
- <jk>new</jk> ResourceDescription(<js>"htmlLinks"</js>, <js>"HtmlLink"</js>)
- };
- }
- }
-</p>
-<p>
- It get rendered as a table of name/description columns with links to child methods:
-</p>
-<img class='bordered' src='doc-files/juneau-rest-server.PredefinedLabelBeans.1.png' style='width:240px'/>
-<p>
- The internals of the class show it simply has two bean properties with a link annotation
- defined on the name property:
-</p>
-<p class='bpcode w800'>
- <jk>public class</jk> ResourceDescription {
-
- <jc>// Renders as hyperlink when serialized as HTML.</jc>
- <ja>@Html</ja>(link=<js>"servlet:/{name}"</js>)
- <jk>public</jk> String getName() {...}
-
- <jk>public</jk> String getDescription() {...}
- }
-</p>
-<p>
- {@link oajr.helper.ResourceDescriptions} is a convenience class for doing the same.
- The example above can also be written as follows (which you'll notice is more concise):
-</p>
-<p class='bpcode w800'>
- <ja>@Resource</ja>
- <jk>public class</jk> PredefinedLabelsResource {
-
- <ja>@RestGet</ja>(<js>"/"</js>)
- <jk>public</jk> ResourceDescriptions getChildMethods() {
- <jk>return new</jk> ResourceDescriptions()
- .append(<js>"beanDescription"</js>, <js>"BeanDescription"</js>)
- .append(<js>"htmlLinks"</js>, <js>"HtmlLink"</js>);
- }
- }
-</p>
-<h5 class='topic'>@HtmlLink, LinkString</h5>
-<p>
- The {@link oaj.html.annotation.HtmlLink @HtmlLink} annotation can also be useful
- for rendering custom hyperlinks:
-</p>
-<p class='bpcode w800'>
- <ja>@RestGet</ja>
- <jk>public</jk> MyLink[] htmlLinks() {
- <jk>return new</jk> MyLink[] {
- <jk>new</jk> MyLink(<js>"apache"</js>, <js>"http://apache.org"</js>),
- <jk>new</jk> MyLink(<js>"juneau"</js>, <js>"http://juneau.apache.org"</js>)
- };
- }
-</p>
-<p class='bpcode w800'>
- <ja>@HtmlLink</ja>(nameProperty=<js>"name"</js>, hrefProperty=<js>"href"</js>)
- <jk>public class</jk> MyLink {
-
- <jc>// Simple bean properties.</jc>
- <jk>public</jk> String <jf>name</jf>, <jf>href</jf>;
-
- <jk>public</jk> MyLink(String <jv>name</jv>, String <jv>href</jv>) {
- <jk>this</jk>.<jf>name</jf> = <jv>name</jv>;
- <jk>this</jk>.<jf>href</jf> = <jv>href</jv>;
- }
- }
-</p>
-<p>
- The {@link oaj.dto.LinkString LinkString} bean is a predefined <ja>@HtmlLink</ja> bean provided
- to simplify specifying actions.
- The following is equivalent to above.
-</p>
-<p class='bpcode w800'>
- <ja>@RestGet</ja>
- <jk>public</jk> LinkString[] htmlLinks() {
- <jk>return new</jk> LinkString[] {
- <jk>new</jk> LinkString(<js>"apache"</js>, <js>"http://apache.org"</js>),
- <jk>new</jk> LinkString(<js>"juneau"</js>, <js>"http://juneau.apache.org"</js>)
- };
- }
-</p>
-<p>
- Both examples render the following consisting of a list of hyperlinks:
-</p>
-<img class='bordered' src='doc-files/juneau-rest-server.PredefinedLabelBeans.3.png' style='width:92px'/>
-<p>
- In all other languages, it gets serialized as a simple bean with two properties.
-</p>
-
-<h5 class='topic'>BeanDescription</h5>
-<p>
- The {@link oajr.helper.BeanDescription} class provides a simple view
- of a bean and it's properties.
-</p>
-<p class='bpcode w800'>
- <ja>@RestGet</ja>(<js>"/beanDescription"</js>)
- <jk>public</jk> BeanDescription getBeanDescription() {
- <jk>return new</jk> BeanDescription(Person.<jk>class</jk>);
- }
-</p>
-<p>
- This example renders the following:
-</p>
-<img class='bordered' src='doc-files/juneau-rest-server.PredefinedLabelBeans.2.png' style='width:584px'/>
-
-<h5 class='topic'>ChildResourceDescriptions</h5>
-<p>
- The {@link oajr.helper.ChildResourceDescriptions} is a convenience bean for generating
- a table of child resources.
-</p>
-<p>
- The {@link oajr.BasicRestServletGroup} class uses this to generate router pages:
-</p>
-<p class='bpcode w800'>
- <ja>@Rest</ja>
- <jk>public abstract class</jk> BasicRestServletGroup <jk>extends</jk> BasicRestServlet {
-
- <ja>@RestGet</ja>(path=<js>"/"</js>, summary=<js>"Navigation page"</js>)
- <jk>public</jk> ChildResourceDescriptions getChildren(RestRequest <jv>req</jv>) <jk>throws</jk> Exception {
- <jk>return new</jk> ChildResourceDescriptions(<jv>req</jv>);
- }
- }
-</p>
-<p>
- Note that all it requires is a {@link oajr.RestRequest} object and it will generate a router
- page using reflection against the resource class.
-</p>
-<p>
- For example, the <c>RootResources</c> page in the REST examples renders the child resources attached to the root resource:
-</p>
-<img class='bordered' src='doc-files/juneau-rest-server.PredefinedLabelBeans.4.png' style='width:800px'/>
-<p>
- The <c>RootResources</c> page consists of the following and extends from the {@link oajr.BasicRestServletGroup} class:
-</p>
-<p class='bpcode w800'>
- <ja>@Rest</ja>(
- ...
- children={
- HelloWorldResource.<jk>class</jk>,
- PetStoreResource.<jk>class</jk>,
- DtoExamples.<jk>class</jk>,
- PhotosResource.<jk>class</jk>,
- SqlQueryResource.<jk>class</jk>,
- ConfigResource.<jk>class</jk>,
- LogsResource.<jk>class</jk>,
- DebugResource.<jk>class</jk>,
- ShutdownResource.<jk>class</jk>
- }
- )
- <jk>public class</jk> RootResources <jk>extends</jk> BasicRestServletJenaGroup {}
-</p>
-
-<h5 class='topic'>SeeOtherRoot</h5>
-<p>
- The {@link oajr.helper.SeeOtherRoot} class can be used to redirect to the root URI
- of a resource class.
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(<js>"/pets"</js>)
- <jk>public</jk> SeeOtherRoot addPet(<ja>@Body</ja> Pet <jv>pet</jv>) {
- <jsm>addPet</jsm>(<jv>pet</jv>);
-
- <jc>// Redirects to the servlet root URL.</jc>
- <jk>return</jk> SeeOtherRoot.<jsf>INSTANCE</jsf>;
- }
-</p>
-<p>
- The runtime behavior is the same as the following:
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(<js>"/pets"</js>)
- <jk>public</jk> SeeOther addPet(<ja>@Body</ja> Pet <jv>pet</jv>) {
- <jsm>addPet</jsm>(<jv>pet</jv>);
-
- <jc>// Redirects to the servlet root URL.</jc>
- <jk>return new</jk> SeeOther(URI.<jsm>create</jsm>(<js>"servlet:/"</js>));
- }
-</p>
-<p>
- One distinction is that the former defines the description <js>"Redirect to servlet root"</js> in the generated Swagger documentation.
-</p>
diff --git a/juneau-doc/src/main/javadoc/overview.html b/juneau-doc/src/main/javadoc/overview.html
index 4b44c82..6bcf3c5 100644
--- a/juneau-doc/src/main/javadoc/overview.html
+++ b/juneau-doc/src/main/javadoc/overview.html
@@ -349,16 +349,7 @@
</ol>
<li><p><a class='doclink' href='#juneau-rest-server.RestOpAnnotatedMethods'>@RestOp-Annotated Methods</a><span class='update'>updated: <b>9.0.0</b></span></p>
<ol>
- <li><p><a class='doclink' href='#juneau-rest-server.RestOpAnnotatedMethods.RestmRequestHeaders'>RequestHeaders</a><span class='update'><b><red>todo</red></b></span></p>
- <li><p><a class='doclink' href='#juneau-rest-server.RestOpAnnotatedMethods.RestmRequestAttributes'>RequestAttributes</a><span class='update'>created: 8.1.0, <b><red>todo</red></b></span></p>
- <li><p><a class='doclink' href='#juneau-rest-server.RestOpAnnotatedMethods.RestmRequestQuery'>RequestQuery</a><span class='update'><b><red>todo</red></b></span></p>
- <li><p><a class='doclink' href='#juneau-rest-server.RestOpAnnotatedMethods.RestmRequestFormData'>RequestFormData</a><span class='update'><b><red>todo</red></b></span></p>
- <li><p><a class='doclink' href='#juneau-rest-server.RestOpAnnotatedMethods.RestmRequestPathMatch'>RequestPathMatch</a><span class='update'><b><red>todo</red></b></span></p>
- <li><p><a class='doclink' href='#juneau-rest-server.RestOpAnnotatedMethods.RestmReaderResource'>ReaderResource</a><span class='update'><b><red>todo</red></b></span></p>
- <li><p><a class='doclink' href='#juneau-rest-server.RestOpAnnotatedMethods.RestmStreamResource'>StreamResource</a><span class='update'><b><red>todo</red></b></span></p>
<li><p><a class='doclink' href='#juneau-rest-server.RestOpAnnotatedMethods.RestmMatchers'>@RestOp(matchers)</a><span class='update'><b><red>todo</red></b></span></p>
- <li><p><a class='doclink' href='#juneau-rest-server.RestOpAnnotatedMethods.RestmPredefinedResponses'>Predefined Responses</a><span class='update'><b><red>todo</red></b></span></p>
- <li><p><a class='doclink' href='#juneau-rest-server.RestOpAnnotatedMethods.RestmPredefinedHelperBeans'>Predefined Helper Beans</a><span class='update'><b><red>todo</red></b></span></p>
</ol>
<li><p><a class='doclink' href='#juneau-rest-server.RestRpc'>REST/RPC</a><span class='update'>updated: 8.0.0, <b><red>todo</red></b></span></p>
<li><p><a class='doclink' href='#juneau-rest-server.RestOpenApiSchemaPartParsing'>OpenAPI Schema Part Parsing</a><span class='update'><b><red>todo</red></b></span></p>
@@ -15484,298 +15475,15 @@
<li class='jc'>{@link org.apache.juneau.rest.RequestBody}
<li class='jc'>{@link org.apache.juneau.rest.RequestHeaders}
<li class='jc'>{@link org.apache.juneau.rest.RequestQueryParams}
- <li class='jc'>{@link org.apache.juneau.rest.RequestFormDataParams}
+ <li class='jc'>{@link org.apache.juneau.rest.RequestFormParams}
<li class='jc'>{@link org.apache.juneau.rest.RequestPathParams}
<li class='jc'>{@link org.apache.juneau.rest.RequestAttributes}
</ul>
<!-- ==================================================================================================== -->
-<h4 class='topic' onclick='toggle(this)'><a href='#juneau-rest-server.RestOpAnnotatedMethods.RestmRequestHeaders' id='juneau-rest-server.RestOpAnnotatedMethods.RestmRequestHeaders'>6.3.1 - RequestHeaders</a><span class='update'><b><red>todo</red></b></span></h4>
-<div class='topic'><!-- START: 6.3.1 - juneau-rest-server.RestOpAnnotatedMethods.RestmRequestHeaders -->
-<p>
- The {@link org.apache.juneau.rest.RequestHeaders} object is the API for accessing the headers of an HTTP request.
- It can be accessed by passing it as a parameter on your REST Java method:
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestHeaders <jv>headers</jv>) {...}
-</p>
-<h5 class='figure'>Example:</h5>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestHeaders <jv>headers</jv>) {
-
- <jc>// Add a default value.</jc>
- <jv>headers</jv>.addDefault(<js>"ETag"</js>, <jsf>DEFAULT_UUID</jsf>);
-
- <jc>// Get a header value as a POJO.</jc>
- UUID <jv>etag</jv> = <jv>headers</jv>.get(<js>"ETag"</js>, UUID.<jk>class</jk>);
-
- <jc>// Get a standard header.</jc>
- CacheControl <jv>cacheControl</jv> = <jv>headers</jv>.getCacheControl().orElse(<jk>null</jk>);
- }
-</p>
-<p>
- Some important methods on this class are:
-</p>
-<ul class='javatree'>
- <li class='jc'><c>{@link org.apache.juneau.rest.RequestHeaders} <jk>extends</jk> TreeMap<String,String[]></c>
- <ul>
- <li class='jm'>{@del RequestHeaders#get(String,Class)} - Get header value converted to a POJO.
- <li class='jm'>{@del RequestHeaders#get(String,Type,Type...)} - Get header value converted to a map or collection of POJOs.
- <li class='jm'>{@del RequestHeaders#getString(String,String)} - Get header value as a simple string.
- <li class='jm'>{@del RequestHeaders#getInt(String,int)} - Get header value as an integer.
- <li class='jm'>{@del RequestHeaders#getBoolean(String,boolean)} - Get header value as a boolean.
- <li class='jm'>{@del RequestHeaders#addDefault(String,Object)} - Programmatically set a default value for a header.
- </ul>
-</ul>
-
-<ul class='seealso'>
- <li class='ja'>{@link org.apache.juneau.http.annotation.Header}
-</ul>
-</div><!-- END: 6.3.1 - juneau-rest-server.RestOpAnnotatedMethods.RestmRequestHeaders -->
-
-<!-- ==================================================================================================== -->
-
-<h4 class='topic' onclick='toggle(this)'><a href='#juneau-rest-server.RestOpAnnotatedMethods.RestmRequestAttributes' id='juneau-rest-server.RestOpAnnotatedMethods.RestmRequestAttributes'>6.3.2 - RequestAttributes</a><span class='update'>created: 8.1.0, <b><red>todo</red></b></span></h4>
-<div class='topic'><!-- START: 6.3.2 - juneau-rest-server.RestOpAnnotatedMethods.RestmRequestAttributes -->
-<p>
- The {@link org.apache.juneau.rest.RequestAttributes} object is the API for accessing the standard servlet attributes on an HTTP request
- (i.e. {@link javax.servlet.ServletRequest#getAttribute(String)}.
- It wraps the request attributes in a {@link java.util.Map} interface and provides several convenience methods.
-</p>
-<p>
- The <c>RequestAttributes</c> object extends from {@link org.apache.juneau.collections.OMap} so all the convenience methods defined on
- that API are also available when working with request attributes:
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestAttributes <jv>attributes</jv>) {...}
-</p>
-<h5 class='figure'>Example:</h5>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestAttributes <jv>attributes</jv>) {
-
- <jc>// Add a default value.</jc>
- <jv>attributes</jv>.putIfNotExists(<js>"Foo"</js>, 123);
-
- <jc>// Get an attribute value as a POJO.</jc>
- UUID <jv>etag</jv> = <jv>attributes</jv>.get(<js>"ETag"</js>, UUID.<jk>class</jk>);
- }
-</p>
-<p>
- Modifications made to request attributes through the <c>RequestAttributes</c> bean are automatically reflected in
- the underlying servlet request attributes making it possible to mix the usage of both APIs.
-</p>
-</div><!-- END: 6.3.2 - juneau-rest-server.RestOpAnnotatedMethods.RestmRequestAttributes -->
-
-<!-- ==================================================================================================== -->
-
-<h4 class='topic' onclick='toggle(this)'><a href='#juneau-rest-server.RestOpAnnotatedMethods.RestmRequestQuery' id='juneau-rest-server.RestOpAnnotatedMethods.RestmRequestQuery'>6.3.3 - RequestQuery</a><span class='update'><b><red>todo</red></b></span></h4>
-<div class='topic'><!-- START: 6.3.3 - juneau-rest-server.RestOpAnnotatedMethods.RestmRequestQuery -->
-<p>
- The {@link org.apache.juneau.rest.RequestQuery} object is the API for accessing the GET query parameters of an HTTP request.
- It can be accessed by passing it as a parameter on your REST Java method:
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestQuery <jv>query</jv>) {...}
-</p>
-<h5 class='figure'>Example:</h5>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestQuery <jv>query</jv>) {
-
- <jc>// Get query parameters converted to various types.</jc>
- <jk>int</jk> <jv>p1</jv> = <jv>query</jv>.get(<js>"p1"</js>, 0, <jk>int</jk>.<jk>class</jk>);
- String <jv>p2</jv> = <jv>query</jv>.get(<js>"p2"</js>, String.<jk>class</jk>);
- UUID <jv>p3</jv> = <jv>query</jv>.get(<js>"p3"</js>, UUID.<jk>class</jk>);
- }
-</p>
-<p>
- An important distinction between the behavior of this object and <l>HttpServletRequest.getParameter(String)</l> is
- that the former will NOT load the body of the request on FORM POSTS and will only look at parameters
- found in the query string.
- This can be useful in cases where you're mixing GET parameters and FORM POSTS and you don't want to
- inadvertently read the body of the request to get a query parameter.
-</p>
-<p>
- Some important methods on this class are:
-</p>
-<ul class='javatree'>
- <li class='jc'><c>{@link org.apache.juneau.rest.RequestQuery} <jk>extends</jk> LinkedHashMap<String,String[]></c>
- <ul>
- <li class='jm'>{@del RequestQuery#get(String,Class)} - Get query parameter value converted to a POJO.
- <li class='jm'>{@del RequestQuery#get(String,Type,Type...)} - Get query parameter value converted to a map or collection of POJOs.
- <li class='jm'>{@del RequestQuery#getString(String,String)} - Get query parameter value as a simple string.
- <li class='jm'>{@del RequestQuery#getInt(String,int)} - Get query parameter value as an integer.
- <li class='jm'>{@del RequestQuery#getBoolean(String,boolean)} - Get query parameter value as a boolean.
- <li class='jm'>{@del RequestQuery#addDefault(String,Object)} - Programmatically set a default value for a query parameter.
- <li class='jm'>{@del RequestQuery#getSearchArgs()} - Returns query parameter search arguments.
- </ul>
-</ul>
-
-<ul class='seealso'>
- <li class='ja'>{@link org.apache.juneau.http.annotation.Query}
- <li class='ja'>{@link org.apache.juneau.http.annotation.HasQuery}
-</ul>
-</div><!-- END: 6.3.3 - juneau-rest-server.RestOpAnnotatedMethods.RestmRequestQuery -->
-
-<!-- ==================================================================================================== -->
-
-<h4 class='topic' onclick='toggle(this)'><a href='#juneau-rest-server.RestOpAnnotatedMethods.RestmRequestFormData' id='juneau-rest-server.RestOpAnnotatedMethods.RestmRequestFormData'>6.3.4 - RequestFormData</a><span class='update'><b><red>todo</red></b></span></h4>
-<div class='topic'><!-- START: 6.3.4 - juneau-rest-server.RestOpAnnotatedMethods.RestmRequestFormData -->
-<p>
- The {@link org.apache.juneau.rest.RequestFormData} object is the API for accessing the HTTP request body as form data.
- It can be accessed by passing it as a parameter on your REST Java method:
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestFormData <jv>formData</jv>) {...}
-</p>
-<h5 class='figure'>Example:</h5>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestFormData <jv>formData</jv>) {
-
- <jc>// Get query parameters converted to various types.</jc>
- <jk>int</jk> <jv>p1</jv> = <jv>formData</jv>.get(<js>"p1"</js>, 0, <jk>int</jk>.<jk>class</jk>);
- String <jv>p2</jv> = <jv>formData<jv>.get(<js>"p2"</js>, String.<jk>class</jk>);
- UUID <jv>p3</jv> = <jv>formData</jv>.get(<js>"p3"</js>, UUID.<jk>class</jk>);
- }
-</p>
-<p>
- Note that this object does NOT take GET parameters into account and only returns values found in the body of the request.
-</p>
-<p>
- Some important methods on this class are:
-</p>
-<ul class='javatree'>
- <li class='jc'><c>{@link org.apache.juneau.rest.RequestFormData} <jk>extends</jk> LinkedHashMap<String,String[]></c>
- <ul>
- <li class='jm'>{@del RequestFormData#get(String,Class)} - Get form-data parameter values converted to a POJO.
- <li class='jm'>{@del RequestFormData#get(String,Type,Type...)} - Get form-data parameter value converted to a map or collection of POJOs.
- <li class='jm'>{@del RequestFormData#getString(String,String)} - Get form-data parameter value as a simple string.
- <li class='jm'>{@del RequestFormData#getInt(String,int)} - Get form-data parameter value as an integer.
- <li class='jm'>{@del RequestFormData#getBoolean(String,boolean)} - Get form-data parameter value as a boolean.
- <li class='jm'>{@del RequestFormData#addDefault(String,Object)} - Programmatically set a default value for a form-data parameter.
- </ul>
-</ul>
-
-<ul class='seealso'>
- <li class='ja'>{@link org.apache.juneau.http.annotation.FormData}
- <li class='ja'>{@link org.apache.juneau.http.annotation.HasFormData}
-</ul>
-</div><!-- END: 6.3.4 - juneau-rest-server.RestOpAnnotatedMethods.RestmRequestFormData -->
-
-<!-- ==================================================================================================== -->
-
-<h4 class='topic' onclick='toggle(this)'><a href='#juneau-rest-server.RestOpAnnotatedMethods.RestmRequestPathMatch' id='juneau-rest-server.RestOpAnnotatedMethods.RestmRequestPathMatch'>6.3.5 - RequestPathMatch</a><span class='update'><b><red>todo</red></b></span></h4>
-<div class='topic'><!-- START: 6.3.5 - juneau-rest-server.RestOpAnnotatedMethods.RestmRequestPathMatch -->
-<p>
- The {@link org.apache.juneau.rest.RequestPath} object is the API for accessing the matched variables
- and remainder on the URL path.
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(...)
- <jk>public</jk> Object myMethod(RequestPathMatch <jv>path</jv>) {...}
-</p>
-<h5 class='figure'>Example:</h5>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(..., path=<js>"/{foo}/{bar}/{baz}/*"</js>)
- <jk>public void</jk> doGet(RequestPathMatch <jv>pathMatch</jv>) {
- <jc>// Example URL: /123/qux/true/quux</jc>
-
- <jk>int</jk> <jv>foo</jv> = <jv>pathMatch</jv>.getInt(<js>"foo"</js>); <jc>// =123</jc>
- String <jv>bar</jv> = <jv>pathMatch</jv>.getString(<js>"bar"</js>); <jc>// =qux</jc>
- <jk>boolean</jk> <jv>baz</jv> = <jv>pathMatch</jv>.getBoolean(<js>"baz"</js>); <jc>// =true</jc>
- String <jv>remainder</jv> = <jv>pathMatch</jv>.getRemainder(); <jc>// =quux</jc>
- }
-</p>
-<p>
- Some important methods on this class are:
-</p>
-<ul class='javatree'>
- <li class='jc'><c>{@link org.apache.juneau.rest.RequestPath} <jk>extends</jk> TreeMap<String,String></c>
- <ul>
- <li class='jm'>{@del RequestPath#get(String,Class)} - Get path match variable converted to a POJO.
- <li class='jm'>{@del RequestPath.get(String,Type,Type...)} - Get path match variable converted to a map or collection of POJOs.
- <li class='jm'>{@del RequestPath#getString(String)} - Get patch match variable as a simple string.
- <li class='jm'>{@del RequestPath#getInt(String)} - Get path match variable as an integer.
- <li class='jm'>{@del RequestPath#getBoolean(String)} - Get path match variable as a boolean.
- <li class='jm'>{@del RequestPath#getRemainder()} - Get the path match remainder.
- </ul>
-</ul>
-
-<ul class='seealso'>
- <li class='ja'>{@link org.apache.juneau.http.annotation.Path}
-</ul>
-</div><!-- END: 6.3.5 - juneau-rest-server.RestOpAnnotatedMethods.RestmRequestPathMatch -->
-
-<!-- ==================================================================================================== -->
-
-<h4 class='topic' onclick='toggle(this)'><a href='#juneau-rest-server.RestOpAnnotatedMethods.RestmReaderResource' id='juneau-rest-server.RestOpAnnotatedMethods.RestmReaderResource'>6.3.6 - ReaderResource</a><span class='update'><b><red>todo</red></b></span></h4>
-<div class='topic'><!-- START: 6.3.6 - juneau-rest-server.RestOpAnnotatedMethods.RestmReaderResource -->
-<p>
- The {@del ReaderResource} class is a convenience object for defining thread-safe
- reusable character-based responses.
- In essence, it's a container for character data with optional response headers and support for
- resolving SVL variables.
-</p>
-
-<p>
- The class is annotated with {@link org.apache.juneau.http.annotation.Response @Response}
- which allows it to be returned as responses by REST methods.
-</p>
-<h5 class='figure'>Example:</h5>
-<p class='bpcode w800'>
- <ja>@RestGet</ja>
- <jk>public</jk> Object sayHello(RestRequest <jv>req</jv>) {
-
- <jc>// Return a reader resource loaded from a file with support for request-time SVL variables.</jc>
- <jk>return</jk> ReaderResource.<jsm>create</jsm>()
- .contents(<jk>new</jk> File(<js>"helloWorld.txt"</js>))
- .varResolver(<jv>req</jv>.getVarResolver())
- .header(<js>"Cache-Control"</js>, <js>"no-cache"</js>)
- .mediaType(<jsf>TEXT_PLAIN</jsf>)
- .build();
- }
-</p>
-</div><!-- END: 6.3.6 - juneau-rest-server.RestOpAnnotatedMethods.RestmReaderResource -->
-
-<!-- ==================================================================================================== -->
-
-<h4 class='topic' onclick='toggle(this)'><a href='#juneau-rest-server.RestOpAnnotatedMethods.RestmStreamResource' id='juneau-rest-server.RestOpAnnotatedMethods.RestmStreamResource'>6.3.7 - StreamResource</a><span class='update'><b><red>todo</red></b></span></h4>
-<div class='topic'><!-- START: 6.3.7 - juneau-rest-server.RestOpAnnotatedMethods.RestmStreamResource -->
-<p>
- The {@del org.apache.juneau.http.StreamResource} class is the binary equivalent to the {@del ReaderResource} object.
- In essence, it's a container for binary data with optional response headers.
-</p>
-<p>
- The class is annotated with {@link org.apache.juneau.http.annotation.Response @Response}
- which allows it to be returned as responses by REST methods.
-</p>
-<h5 class='figure'>Example:</h5>
-<p class='bpcode w800'>
- <ja>@RestGet</ja>(...)
- <jk>public</jk> Object showPicture(RestRequest <jv>req</jv>) {
-
- <jc>// Return a stream resource loaded from a file.</jc>
- <jk>return</jk> StreamResource.<jsm>create</jsm>()
- .contents(<jk>new</jk> File(<js>"mypicture.png"</js>))
- .header(<js>"Cache-Control"</js>, <js>"no-cache"</js>)
- .mediaType(<jsf>IMAGE_PNG</jsf>)
- .build();
- }
-</p>
-</div><!-- END: 6.3.7 - juneau-rest-server.RestOpAnnotatedMethods.RestmStreamResource -->
-
-<!-- ==================================================================================================== -->
-
-<h4 class='topic' onclick='toggle(this)'><a href='#juneau-rest-server.RestOpAnnotatedMethods.RestmMatchers' id='juneau-rest-server.RestOpAnnotatedMethods.RestmMatchers'>6.3.8 - @RestOp(matchers)</a><span class='update'><b><red>todo</red></b></span></h4>
-<div class='topic'><!-- START: 6.3.8 - juneau-rest-server.RestOpAnnotatedMethods.RestmMatchers -->
+<h4 class='topic' onclick='toggle(this)'><a href='#juneau-rest-server.RestOpAnnotatedMethods.RestmMatchers' id='juneau-rest-server.RestOpAnnotatedMethods.RestmMatchers'>6.3.1 - @RestOp(matchers)</a><span class='update'><b><red>todo</red></b></span></h4>
+<div class='topic'><!-- START: 6.3.1 - juneau-rest-server.RestOpAnnotatedMethods.RestmMatchers -->
<p>
{@link org.apache.juneau.rest.RestMatcher RestMatchers} are used to allow multiple Java methods to be
tied to the same HTTP method and path, but differentiated by some request attribute such as a specific
@@ -15829,337 +15537,7 @@
<li class='jc'>{@link org.apache.juneau.rest.matchers.MultipartFormDataMatcher}
<li class='jc'>{@link org.apache.juneau.rest.matchers.UrlEncodedFormMatcher}
</ul>
-</div><!-- END: 6.3.8 - juneau-rest-server.RestOpAnnotatedMethods.RestmMatchers -->
-
-<!-- ==================================================================================================== -->
-
-<h4 class='topic' onclick='toggle(this)'><a href='#juneau-rest-server.RestOpAnnotatedMethods.RestmPredefinedResponses' id='juneau-rest-server.RestOpAnnotatedMethods.RestmPredefinedResponses'>6.3.9 - Predefined Responses</a><span class='update'><b><red>todo</red></b></span></h4>
-<div class='topic'><!-- START: 6.3.9 - juneau-rest-server.RestOpAnnotatedMethods.RestmPredefinedResponses -->
-<p>
- Predefined response beans are provided for all standard HTTP responses.
- These can be used as-is or extended to provide customized HTTP responses.
-</p>
-<h5 class='figure'>Examples:</h5>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(<js>"/pets"</js>)
- <jk>public</jk> Ok addPet(<ja>@Body</ja> Pet <jv>pet</jv>) {
- <jsm>addPet</jsm>(<jv>pet</jv>);
-
- <jc>// Predefined "200 OK" response bean.</jc>
- <jk>return new</jk> Ok(); <jc>// Could also use Ok.OK instance</jc>
- }
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(<js>"/pets"</js>)
- <jk>public</jk> SeeOther addPet(<ja>@Body</ja> Pet <jv>pet</jv>) {
- <jsm>addPet</jsm>(<jv>pet</jv>);
-
- <jc>// Predefined "302 See Other" response bean with redirect to /pets.</jc>
- <jk>return new</jk> SeeOther(<js>"servlet:/pets"</js>);
- }
-</p>
-<ul class='javatree'>
- <li class='jp'>{@link org.apache.juneau.http.response}
- <ul>
- <li class='jc'>{@link org.apache.juneau.http.response.Accepted}
- <li class='jc'>{@link org.apache.juneau.http.response.AlreadyReported}
- <li class='jc'>{@link org.apache.juneau.http.response.Continue}
- <li class='jc'>{@link org.apache.juneau.http.response.Created}
- <li class='jc'>{@link org.apache.juneau.http.response.EarlyHints}
- <li class='jc'>{@link org.apache.juneau.http.response.Found}
- <li class='jc'>{@link org.apache.juneau.http.response.IMUsed}
- <li class='jc'>{@link org.apache.juneau.http.response.MovedPermanently}
- <li class='jc'>{@link org.apache.juneau.http.response.MultipleChoices}
- <li class='jc'>{@link org.apache.juneau.http.response.MultiStatus}
- <li class='jc'>{@link org.apache.juneau.http.response.NoContent}
- <li class='jc'>{@link org.apache.juneau.http.response.NonAuthoritiveInformation}
- <li class='jc'>{@link org.apache.juneau.http.response.NotModified}
- <li class='jc'>{@link org.apache.juneau.http.response.Ok}
- <li class='jc'>{@link org.apache.juneau.http.response.PartialContent}
- <li class='jc'>{@link org.apache.juneau.http.response.PermanentRedirect}
- <li class='jc'>{@link org.apache.juneau.http.response.Processing}
- <li class='jc'>{@link org.apache.juneau.http.response.ResetContent}
- <li class='jc'>{@link org.apache.juneau.http.response.SeeOther}
- <li class='jc'>{@link org.apache.juneau.http.response.SwitchingProtocols}
- <li class='jc'>{@link org.apache.juneau.http.response.TemporaryRedirect}
- <li class='jc'>{@link org.apache.juneau.http.response.UseProxy}
- </ul>
-</ul>
-<p>
- These predefined response beans are an example of {@link org.apache.juneau.http.annotation.Response @Response}-annotated
- objects that are describe in detail later.
- Without going into details, this is how the {@link org.apache.juneau.http.response.SeeOther} is defined:
-</p>
-<p class='bpcode w800'>
- <ja>@Response</ja>(
- code=303 <jc>// Set automatically on response</jc>,
- description=<js>"See Other"</js> <jc>// Used in generated Swagger</jc>
- )
- <jk>public class</jk> SeeOther {
-
- <jk>private final</jk> String <jf>message</jf>;
- <jk>private final</jk> URI <jf>location</jf>;
-
- <jc>// Constructors omitted.</jc>
-
- <jc>// Used to populate Location response header.</jc>
- <ja>@ResponseHeader</ja>(name=<js>"Location"</js>)
- <jk>public</jk> URI getLocation() {
- <jk>return</jk> <jf>location</jf>;
- }
-
- <jc>// Used during serialization.</jc>
- <ja>@ResponseBody</ja>
- <jk>public</jk> String toString() {
- <jk>return</jk> <jf>message</jf>;
- }
- }
-</p>
-<p>
- The {@link org.apache.juneau.rest.helper.SeeOtherRoot} class shows how these predefined beans can be extended.
-</p>
-<p class='bpcode w800'>
- <ja>@Response</ja>(
- description=<js>"Redirect to servlet root"</js> <jc>// Override description in generated Swagger.</jc>
- )
- <jk>public class</jk> SeeOtherServletRoot <jk>extends</jk> SeeOther {
-
- <jk>public</jk> SeeOtherServletRoot() {
- <jk>super</jk>(URI.<jsm>create</jsm>(<js>"servlet:/"</js>));
- }
- }
-</p>
-<p>
- Note that the runtime behavior of the following code is identical to the example above.
- However, the important distinction is that in the previous example, the 302 response would show in
- the generated Swagger (since we can see the response through reflection), whereas it will NOT show up
- in the following example (since all we see is an Object response).
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(<js>"/pets"</js>)
- <jk>public</jk> Object addPet(<ja>@Body</ja> Pet <jv>pet</jv>) {
- <jsm>addPet</jsm>(<jv>pet</jv>);
-
- <jc>// Note the Object return type.</jc>
- <jk>return new</jk> SeeOther(<js>"servlet:/pets"</js>);
- }
-</p>
-</div><!-- END: 6.3.9 - juneau-rest-server.RestOpAnnotatedMethods.RestmPredefinedResponses -->
-
-<!-- ==================================================================================================== -->
-
-<h4 class='topic' onclick='toggle(this)'><a href='#juneau-rest-server.RestOpAnnotatedMethods.RestmPredefinedHelperBeans' id='juneau-rest-server.RestOpAnnotatedMethods.RestmPredefinedHelperBeans'>6.3.10 - Predefined Helper Beans</a><span class='update'><b><red>todo</red></b></span></h4>
-<div class='topic'><!-- START: 6.3.10 - juneau-rest-server.RestOpAnnotatedMethods.RestmPredefinedHelperBeans -->
-<p>
- The {@link org.apache.juneau.rest.helper} package contains several predefined beans to help when constructing
- REST interfaces.
-</p>
-<ul class='javatree'>
- <li class='jp'>{@link org.apache.juneau.rest.helper}
- <ul>
- <li class='jc'>{@link org.apache.juneau.rest.helper.BeanDescription}
- <li class='jc'>{@link org.apache.juneau.rest.helper.ChildResourceDescriptions}
- <li class='jc'>{@link org.apache.juneau.rest.helper.ResourceDescription}
- <li class='jc'>{@link org.apache.juneau.rest.helper.ResourceDescriptions}
- <li class='jc'>{@link org.apache.juneau.rest.helper.SeeOtherRoot}
- </ul>
-</ul>
-
-<h5 class='topic'>ResourceDescription, ResourceDescrptions</h5>
-<p>
- The {@link org.apache.juneau.rest.helper.ResourceDescription} class is a bean with name/description
- properties for labeling and linking to child resources.
- The following examples is pulled from the REST examples:
-</p>
-<p class='bpcode w800'>
- <ja>@Resource</ja>
- <jk>public class</jk> PredefinedLabelsResource {
-
- <ja>@RestGet</ja>(<js>"/"</js>)
- <jk>public</jk> ResourceDescription[] getChildMethods() {
- <jk>return new</jk> ResourceDescription[] {
- <jk>new</jk> ResourceDescription(<js>"beanDescription"</js>, <js>"BeanDescription"</js>),
- <jk>new</jk> ResourceDescription(<js>"htmlLinks"</js>, <js>"HtmlLink"</js>)
- };
- }
- }
-</p>
-<p>
- It get rendered as a table of name/description columns with links to child methods:
-</p>
-<img class='bordered' src='doc-files/juneau-rest-server.PredefinedLabelBeans.1.png' style='width:240px'/>
-<p>
- The internals of the class show it simply has two bean properties with a link annotation
- defined on the name property:
-</p>
-<p class='bpcode w800'>
- <jk>public class</jk> ResourceDescription {
-
- <jc>// Renders as hyperlink when serialized as HTML.</jc>
- <ja>@Html</ja>(link=<js>"servlet:/{name}"</js>)
- <jk>public</jk> String getName() {...}
-
- <jk>public</jk> String getDescription() {...}
- }
-</p>
-<p>
- {@link org.apache.juneau.rest.helper.ResourceDescriptions} is a convenience class for doing the same.
- The example above can also be written as follows (which you'll notice is more concise):
-</p>
-<p class='bpcode w800'>
- <ja>@Resource</ja>
- <jk>public class</jk> PredefinedLabelsResource {
-
- <ja>@RestGet</ja>(<js>"/"</js>)
- <jk>public</jk> ResourceDescriptions getChildMethods() {
- <jk>return new</jk> ResourceDescriptions()
- .append(<js>"beanDescription"</js>, <js>"BeanDescription"</js>)
- .append(<js>"htmlLinks"</js>, <js>"HtmlLink"</js>);
- }
- }
-</p>
-<h5 class='topic'>@HtmlLink, LinkString</h5>
-<p>
- The {@link org.apache.juneau.html.annotation.HtmlLink @HtmlLink} annotation can also be useful
- for rendering custom hyperlinks:
-</p>
-<p class='bpcode w800'>
- <ja>@RestGet</ja>
- <jk>public</jk> MyLink[] htmlLinks() {
- <jk>return new</jk> MyLink[] {
- <jk>new</jk> MyLink(<js>"apache"</js>, <js>"http://apache.org"</js>),
- <jk>new</jk> MyLink(<js>"juneau"</js>, <js>"http://juneau.apache.org"</js>)
- };
- }
-</p>
-<p class='bpcode w800'>
- <ja>@HtmlLink</ja>(nameProperty=<js>"name"</js>, hrefProperty=<js>"href"</js>)
- <jk>public class</jk> MyLink {
-
- <jc>// Simple bean properties.</jc>
- <jk>public</jk> String <jf>name</jf>, <jf>href</jf>;
-
- <jk>public</jk> MyLink(String <jv>name</jv>, String <jv>href</jv>) {
- <jk>this</jk>.<jf>name</jf> = <jv>name</jv>;
- <jk>this</jk>.<jf>href</jf> = <jv>href</jv>;
- }
- }
-</p>
-<p>
- The {@link org.apache.juneau.dto.LinkString LinkString} bean is a predefined <ja>@HtmlLink</ja> bean provided
- to simplify specifying actions.
- The following is equivalent to above.
-</p>
-<p class='bpcode w800'>
- <ja>@RestGet</ja>
- <jk>public</jk> LinkString[] htmlLinks() {
- <jk>return new</jk> LinkString[] {
- <jk>new</jk> LinkString(<js>"apache"</js>, <js>"http://apache.org"</js>),
- <jk>new</jk> LinkString(<js>"juneau"</js>, <js>"http://juneau.apache.org"</js>)
- };
- }
-</p>
-<p>
- Both examples render the following consisting of a list of hyperlinks:
-</p>
-<img class='bordered' src='doc-files/juneau-rest-server.PredefinedLabelBeans.3.png' style='width:92px'/>
-<p>
- In all other languages, it gets serialized as a simple bean with two properties.
-</p>
-
-<h5 class='topic'>BeanDescription</h5>
-<p>
- The {@link org.apache.juneau.rest.helper.BeanDescription} class provides a simple view
- of a bean and it's properties.
-</p>
-<p class='bpcode w800'>
- <ja>@RestGet</ja>(<js>"/beanDescription"</js>)
- <jk>public</jk> BeanDescription getBeanDescription() {
- <jk>return new</jk> BeanDescription(Person.<jk>class</jk>);
- }
-</p>
-<p>
- This example renders the following:
-</p>
-<img class='bordered' src='doc-files/juneau-rest-server.PredefinedLabelBeans.2.png' style='width:584px'/>
-
-<h5 class='topic'>ChildResourceDescriptions</h5>
-<p>
- The {@link org.apache.juneau.rest.helper.ChildResourceDescriptions} is a convenience bean for generating
- a table of child resources.
-</p>
-<p>
- The {@link org.apache.juneau.rest.BasicRestServletGroup} class uses this to generate router pages:
-</p>
-<p class='bpcode w800'>
- <ja>@Rest</ja>
- <jk>public abstract class</jk> BasicRestServletGroup <jk>extends</jk> BasicRestServlet {
-
- <ja>@RestGet</ja>(path=<js>"/"</js>, summary=<js>"Navigation page"</js>)
- <jk>public</jk> ChildResourceDescriptions getChildren(RestRequest <jv>req</jv>) <jk>throws</jk> Exception {
- <jk>return new</jk> ChildResourceDescriptions(<jv>req</jv>);
- }
- }
-</p>
-<p>
- Note that all it requires is a {@link org.apache.juneau.rest.RestRequest} object and it will generate a router
- page using reflection against the resource class.
-</p>
-<p>
- For example, the <c>RootResources</c> page in the REST examples renders the child resources attached to the root resource:
-</p>
-<img class='bordered' src='doc-files/juneau-rest-server.PredefinedLabelBeans.4.png' style='width:800px'/>
-<p>
- The <c>RootResources</c> page consists of the following and extends from the {@link org.apache.juneau.rest.BasicRestServletGroup} class:
-</p>
-<p class='bpcode w800'>
- <ja>@Rest</ja>(
- ...
- children={
- HelloWorldResource.<jk>class</jk>,
- PetStoreResource.<jk>class</jk>,
- DtoExamples.<jk>class</jk>,
- PhotosResource.<jk>class</jk>,
- SqlQueryResource.<jk>class</jk>,
- ConfigResource.<jk>class</jk>,
- LogsResource.<jk>class</jk>,
- DebugResource.<jk>class</jk>,
- ShutdownResource.<jk>class</jk>
- }
- )
- <jk>public class</jk> RootResources <jk>extends</jk> BasicRestServletJenaGroup {}
-</p>
-
-<h5 class='topic'>SeeOtherRoot</h5>
-<p>
- The {@link org.apache.juneau.rest.helper.SeeOtherRoot} class can be used to redirect to the root URI
- of a resource class.
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(<js>"/pets"</js>)
- <jk>public</jk> SeeOtherRoot addPet(<ja>@Body</ja> Pet <jv>pet</jv>) {
- <jsm>addPet</jsm>(<jv>pet</jv>);
-
- <jc>// Redirects to the servlet root URL.</jc>
- <jk>return</jk> SeeOtherRoot.<jsf>INSTANCE</jsf>;
- }
-</p>
-<p>
- The runtime behavior is the same as the following:
-</p>
-<p class='bpcode w800'>
- <ja>@RestPost</ja>(<js>"/pets"</js>)
- <jk>public</jk> SeeOther addPet(<ja>@Body</ja> Pet <jv>pet</jv>) {
- <jsm>addPet</jsm>(<jv>pet</jv>);
-
- <jc>// Redirects to the servlet root URL.</jc>
- <jk>return new</jk> SeeOther(URI.<jsm>create</jsm>(<js>"servlet:/"</js>));
- }
-</p>
-<p>
- One distinction is that the former defines the description <js>"Redirect to servlet root"</js> in the generated Swagger documentation.
-</p>
-</div><!-- END: 6.3.10 - juneau-rest-server.RestOpAnnotatedMethods.RestmPredefinedHelperBeans -->
+</div><!-- END: 6.3.1 - juneau-rest-server.RestOpAnnotatedMethods.RestmMatchers -->
</div><!-- END: 6.3 - juneau-rest-server.RestOpAnnotatedMethods -->
<!-- ==================================================================================================== -->
diff --git a/juneau-doc/src/main/javadoc/resources/docs.txt b/juneau-doc/src/main/javadoc/resources/docs.txt
index ddfe78a..62a0674 100644
--- a/juneau-doc/src/main/javadoc/resources/docs.txt
+++ b/juneau-doc/src/main/javadoc/resources/docs.txt
@@ -286,15 +286,6 @@ RestcResponseBody = #juneau-rest-client.RestcResponseBody, Overview > juneau-res
RestcResponseHeaders = #juneau-rest-client.RestcResponseHeaders, Overview > juneau-rest-client > Response Headers
RestcResponseStatus = #juneau-rest-client.RestcResponseStatus, Overview > juneau-rest-client > Response Status
RestmMatchers = #juneau-rest-server.RestOpAnnotatedMethods.RestmMatchers, Overview > juneau-rest-server > @RestOp-Annotated Methods > @RestOp(matchers)
-RestmPredefinedHelperBeans = #juneau-rest-server.RestOpAnnotatedMethods.RestmPredefinedHelperBeans, Overview > juneau-rest-server > @RestOp-Annotated Methods > Predefined Helper Beans
-RestmPredefinedResponses = #juneau-rest-server.RestOpAnnotatedMethods.RestmPredefinedResponses, Overview > juneau-rest-server > @RestOp-Annotated Methods > Predefined Responses
-RestmReaderResource = #juneau-rest-server.RestOpAnnotatedMethods.RestmReaderResource, Overview > juneau-rest-server > @RestOp-Annotated Methods > ReaderResource
-RestmRequestAttributes = #juneau-rest-server.RestOpAnnotatedMethods.RestmRequestAttributes, Overview > juneau-rest-server > @RestOp-Annotated Methods > RequestAttributes
-RestmRequestFormData = #juneau-rest-server.RestOpAnnotatedMethods.RestmRequestFormData, Overview > juneau-rest-server > @RestOp-Annotated Methods > RequestFormData
-RestmRequestHeaders = #juneau-rest-server.RestOpAnnotatedMethods.RestmRequestHeaders, Overview > juneau-rest-server > @RestOp-Annotated Methods > RequestHeaders
-RestmRequestPathMatch = #juneau-rest-server.RestOpAnnotatedMethods.RestmRequestPathMatch, Overview > juneau-rest-server > @RestOp-Annotated Methods > RequestPathMatch
-RestmRequestQuery = #juneau-rest-server.RestOpAnnotatedMethods.RestmRequestQuery, Overview > juneau-rest-server > @RestOp-Annotated Methods > RequestQuery
-RestmStreamResource = #juneau-rest-server.RestOpAnnotatedMethods.RestmStreamResource, Overview > juneau-rest-server > @RestOp-Annotated Methods > StreamResource
Security = #Security, Overview > Security Best-Practices
SecurityMarshall = #Security.SecurityMarshall, Overview > Security Best-Practices > juneau-marshall
SecurityRest = #Security.SecurityRest, Overview > Security Best-Practices > juneau-rest-server
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestAttribute.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestAttribute.java
index 51de7ad..8cd2202 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestAttribute.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestAttribute.java
@@ -59,7 +59,7 @@ public class RequestAttribute extends BasicNamedAttribute {
* @return The converted type, or {@link Optional#empty()} if the part is not present.
* @throws BasicHttpException If value could not be parsed.
*/
- public <T> Optional<T> asType(Class<T> type) {
+ public <T> Optional<T> as(Class<T> type) {
return ofNullable(req.getBeanSession().convertToType(getValue(), type));
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestAttributes.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestAttributes.java
index d4a220c..1a75c11 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestAttributes.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestAttributes.java
@@ -25,11 +25,64 @@ import org.apache.juneau.svl.*;
* Represents the attributes in an HTTP request.
*
* <p>
- * Wraps the request attributes in a {@link Map} interface and provides several convenience methods.
+ * The {@link RequestAttributes} object is the API for accessing the standard servlet attributes on an HTTP request
+ * (i.e. {@link javax.servlet.ServletRequest#getAttribute(String)}.
+ * It wraps the request attributes in a {@link java.util.Map} interface and provides several convenience methods.
+ * </p>
*
- * <ul class='seealso'>
- * <li class='link'>{@doc RestmRequestAttributes}
+ * <p class='bcode w800'>
+ * <ja>@RestPost</ja>(...)
+ * <jk>public</jk> Object myMethod(RequestAttributes <jv>attributes</jv>) {...}
+ * </p>
+ *
+ * <h5 class='figure'>Example:</h5>
+ * <p class='bcode w800'>
+ * <ja>@RestPost</ja>(...)
+ * <jk>public</jk> Object myMethod(RequestAttributes <jv>attributes</jv>) {
+ *
+ * <jc>// Add a default value.</jc>
+ * <jv>attributes</jv>.addDefault(<js>"Foo"</js>, 123);
+ *
+ * <jc>// Get an attribute value as a POJO.</jc>
+ * UUID <jv>etag</jv> = <jv>attributes</jv>.get(<js>"ETag"</js>).as(UUID.<jk>class</jk>).orElse(<jk>null</jk>);
+ * }
+ * </p>
+ *
+ * <p>
+ * Some important methods on this class are:
+ * </p>
+ * <ul class='javatree'>
+ * <li class='jc'>{@link RequestHeaders}
+ * <ul class='spaced-list'>
+ * <li>Methods for retrieving request attributes:
+ * <ul class='javatreec'>
+ * <li class='jm'>{@link RequestAttributes#contains(String...) contains(String...)}
+ * <li class='jm'>{@link RequestAttributes#containsAny(String...) containsAny(String...)}
+ * <li class='jm'>{@link RequestAttributes#get(String) get(String)}
+ * <li class='jm'>{@link RequestAttributes#getAll() getAll()}
+ * </ul>
+ * <li>Methods for overriding request attributes:
+ * <ul class='javatreec'>
+ * <li class='jm'>{@link RequestAttributes#addDefault(List) addDefault(List)}
+ * <li class='jm'>{@link RequestAttributes#addDefault(NamedAttribute...) addDefault(NamedAttribute...)}
+ * <li class='jm'>{@link RequestAttributes#addDefault(NamedAttributeList) addDefault(NamedAttributeList)}
+ * <li class='jm'>{@link RequestAttributes#addDefault(String,Object) addDefault(String,Object)}
+ * <li class='jm'>{@link RequestAttributes#remove(NamedAttribute...) remove(NamedAttribute...)}
+ * <li class='jm'>{@link RequestAttributes#remove(String...) remove(String...)}
+ * <li class='jm'>{@link RequestAttributes#set(NamedAttribute...) set(NamedAttribute...)}
+ * <li class='jm'>{@link RequestAttributes#set(String,Object) set(String,Object)}
+ * </ul>
+ * <li>Other methods:
+ * <ul class='javatreec'>
+ * <li class='jm'>{@link RequestAttributes#asMap() asMap()}
+ * </ul>
+ * </ul>
* </ul>
+ *
+ * <p>
+ * Modifications made to request attributes through the <c>RequestAttributes</c> bean are automatically reflected in
+ * the underlying servlet request attributes making it possible to mix the usage of both APIs.
+ * </p>
*/
public class RequestAttributes {
@@ -91,6 +144,17 @@ public class RequestAttributes {
}
/**
+ * Adds a default entry to the request attributes.
+ *
+ * @param name The name.
+ * @param value The value.
+ * @return This object.
+ */
+ public RequestAttributes addDefault(String name, Object value) {
+ return addDefault(BasicNamedAttribute.of(name, value));
+ }
+
+ /**
* Returns the request attribute with the specified name.
*
* @param name The attribute name.
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 0c6b384..89cedec 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
@@ -39,7 +39,7 @@ import org.apache.juneau.rest.util.*;
* The {@link RequestBody} object is the API for accessing the body of an HTTP request.
* It can be accessed by passing it as a parameter on your REST Java method:
* </p>
- * <p class='bpcode w800'>
+ * <p class='bcode w800'>
* <ja>@RestPost</ja>(...)
* <jk>public</jk> Object myMethod(RequestBody <jv>body</jv>) {...}
* </p>
@@ -49,7 +49,7 @@ import org.apache.juneau.rest.util.*;
* <ja>@RestPost</ja>(...)
* <jk>public void</jk> doPost(RequestBody <jv>body</jv>) {
* <jc>// Convert body to a linked list of Person objects.</jc>
- * List<Person> <jv>list</jv> = <jv>body</jv>.asType(LinkedList.<jk>class</jk>, Person.<jk>class</jk>);
+ * List<Person> <jv>list</jv> = <jv>body</jv>.as(LinkedList.<jk>class</jk>, Person.<jk>class</jk>);
* ...
* }
* </p>
@@ -71,8 +71,8 @@ import org.apache.juneau.rest.util.*;
* </ul>
* <li>Methods for parsing the contents of the request body:
* <ul class='javatreec'>
- * <li class='jm'>{@link RequestBody#asType(Class) asType(Class)}
- * <li class='jm'>{@link RequestBody#asType(Type, Type...) asType(Type, Type...)}
+ * <li class='jm'>{@link RequestBody#as(Class) as(Class)}
+ * <li class='jm'>{@link RequestBody#as(Type, Type...) as(Type, Type...)}
* <li class='jm'>{@link RequestBody#setSchema(HttpPartSchema) setSchema(HttpPartSchema)}
* </ul>
* <li>Other methods:
@@ -197,19 +197,19 @@ public class RequestBody {
* <h5 class='section'>Examples:</h5>
* <p class='bcode w800'>
* <jc>// Parse into an integer.</jc>
- * <jk>int</jk> body = req.getBody().asType(<jk>int</jk>.<jk>class</jk>);
+ * <jk>int</jk> body = req.getBody().as(<jk>int</jk>.<jk>class</jk>);
*
* <jc>// Parse into an int array.</jc>
- * <jk>int</jk>[] body = req.getBody().asType(<jk>int</jk>[].<jk>class</jk>);
+ * <jk>int</jk>[] body = req.getBody().as(<jk>int</jk>[].<jk>class</jk>);
* <jc>// Parse into a bean.</jc>
- * MyBean body = req.getBody().asType(MyBean.<jk>class</jk>);
+ * MyBean body = req.getBody().as(MyBean.<jk>class</jk>);
*
* <jc>// Parse into a linked-list of objects.</jc>
- * List body = req.getBody().asType(LinkedList.<jk>class</jk>);
+ * List body = req.getBody().as(LinkedList.<jk>class</jk>);
*
* <jc>// Parse into a map of object keys/values.</jc>
- * Map body = req.getBody().asType(TreeMap.<jk>class</jk>);
+ * Map body = req.getBody().as(TreeMap.<jk>class</jk>);
* </p>
*
* <ul class='notes'>
@@ -224,7 +224,7 @@ public class RequestBody {
* @throws UnsupportedMediaType Thrown if the Content-Type header value is not supported by one of the parsers.
* @throws InternalServerError Thrown if an {@link IOException} occurs.
*/
- public <T> T asType(Class<T> type) throws BadRequest, UnsupportedMediaType, InternalServerError {
+ public <T> T as(Class<T> type) throws BadRequest, UnsupportedMediaType, InternalServerError {
return getInner(getClassMeta(type));
}
@@ -232,21 +232,21 @@ public class RequestBody {
* Reads the input from the HTTP request parsed into a POJO.
*
* <p>
- * This is similar to {@link #asType(Class)} but allows for complex collections of POJOs to be created.
+ * This is similar to {@link #as(Class)} but allows for complex collections of POJOs to be created.
*
* <h5 class='section'>Examples:</h5>
* <p class='bcode w800'>
* <jc>// Parse into a linked-list of strings.</jc>
- * List<String> body = req.getBody().asType(LinkedList.<jk>class</jk>, String.<jk>class</jk>);
+ * List<String> body = req.getBody().as(LinkedList.<jk>class</jk>, String.<jk>class</jk>);
*
* <jc>// Parse into a linked-list of linked-lists of strings.</jc>
- * List<List<String>> body = req.getBody().asType(LinkedList.<jk>class</jk>, LinkedList.<jk>class</jk>, String.<jk>class</jk>);
+ * List<List<String>> body = req.getBody().as(LinkedList.<jk>class</jk>, LinkedList.<jk>class</jk>, String.<jk>class</jk>);
*
* <jc>// Parse into a map of string keys/values.</jc>
- * Map<String,String> body = req.getBody().asType(TreeMap.<jk>class</jk>, String.<jk>class</jk>, String.<jk>class</jk>);
+ * Map<String,String> body = req.getBody().as(TreeMap.<jk>class</jk>, String.<jk>class</jk>, String.<jk>class</jk>);
*
* <jc>// Parse into a map containing string keys and values of lists containing beans.</jc>
- * Map<String,List<MyBean>> body = req.getBody().asType(TreeMap.<jk>class</jk>, String.<jk>class</jk>, List.<jk>class</jk>, MyBean.<jk>class</jk>);
+ * Map<String,List<MyBean>> body = req.getBody().as(TreeMap.<jk>class</jk>, String.<jk>class</jk>, List.<jk>class</jk>, MyBean.<jk>class</jk>);
* </p>
*
* <ul class='notes'>
@@ -271,7 +271,7 @@ public class RequestBody {
* @throws UnsupportedMediaType Thrown if the Content-Type header value is not supported by one of the parsers.
* @throws InternalServerError Thrown if an {@link IOException} occurs.
*/
- public <T> T asType(Type type, Type...args) throws BadRequest, UnsupportedMediaType, InternalServerError {
+ public <T> T as(Type type, Type...args) throws BadRequest, UnsupportedMediaType, InternalServerError {
return getInner(this.<T>getClassMeta(type, args));
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestFormParam.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestFormParam.java
index 2a0cbf4..f7501a7 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestFormParam.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestFormParam.java
@@ -16,12 +16,9 @@ import static org.apache.juneau.httppart.HttpPartType.*;
import static org.apache.juneau.internal.ThrowableUtils.*;
import java.io.*;
-import java.time.*;
-import java.util.*;
import org.apache.http.*;
import org.apache.juneau.assertions.*;
-import org.apache.juneau.http.part.*;
import org.apache.juneau.httppart.*;
import org.apache.juneau.internal.*;
@@ -72,114 +69,6 @@ public class RequestFormParam extends RequestHttpPart implements NameValuePair {
return value;
}
- /**
- * Returns the value of this parameter as an integer.
- *
- * @return The value of this parameter as an integer, or {@link Optional#empty()} if the parameter was not present.
- */
- public Optional<Integer> asInteger() {
- return asIntegerPart().asInteger();
- }
-
- /**
- * Returns the value of this parameter as a boolean.
- *
- * @return The value of this parameter as a boolean, or {@link Optional#empty()} if the parameter was not present.
- */
- public Optional<Boolean> asBoolean() {
- return asBooleanPart().asBoolean();
- }
-
- /**
- * Returns the value of this parameter as a long.
- *
- * @return The value of this parameter as a long, or {@link Optional#empty()} if the parameter was not present.
- */
- public Optional<Long> asLong() {
- return asLongPart().asLong();
- }
-
- /**
- * Returns the value of this parameter as a date.
- *
- * @return The value of this parameter as a date, or {@link Optional#empty()} if the parameter was not present.
- */
- public Optional<ZonedDateTime> asDate() {
- return asDatePart().asZonedDateTime();
- }
-
- /**
- * Returns the value of this parameter as a list from a comma-delimited string.
- *
- * @return The value of this parameter as a list from a comma-delimited string, or {@link Optional#empty()} if the parameter was not present.
- */
- public Optional<List<String>> asCsvArray() {
- return asCsvArrayPart().asList();
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicCsvArrayPart}.
- *
- * @return The value of this parameter as a {@link BasicCsvArrayPart}, never <jk>null</jk>.
- */
- public BasicCsvArrayPart asCsvArrayPart() {
- return new BasicCsvArrayPart(getName(), getValue());
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicDatePart}.
- *
- * @return The value of this parameter as a {@link BasicDatePart}, never <jk>null</jk>.
- */
- public BasicDatePart asDatePart() {
- return new BasicDatePart(getName(), getValue());
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicIntegerPart}.
- *
- * @return The value of this parameter as a {@link BasicIntegerPart}, never <jk>null</jk>.
- */
- public BasicIntegerPart asIntegerPart() {
- return new BasicIntegerPart(getName(), getValue());
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicBooleanPart}.
- *
- * @return The value of this parameter as a {@link BasicBooleanPart}, never <jk>null</jk>.
- */
- public BasicBooleanPart asBooleanPart() {
- return new BasicBooleanPart(getName(), getValue());
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicLongPart}.
- *
- * @return The value of this parameter as a {@link BasicLongPart}, never <jk>null</jk>.
- */
- public BasicLongPart asLongPart() {
- return new BasicLongPart(getName(), getValue());
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicStringPart}.
- *
- * @return The value of this parameter as a {@link BasicStringPart}, never <jk>null</jk>.
- */
- public BasicStringPart asStringPart() {
- return new BasicStringPart(getName(), getValue());
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicUriPart}.
- *
- * @return The value of this parameter as a {@link BasicUriPart}, never <jk>null</jk>.
- */
- public BasicUriPart asUriPart() {
- return new BasicUriPart(getName(), getValue());
- }
-
//------------------------------------------------------------------------------------------------------------------
// Assertions
//------------------------------------------------------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestFormParams.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestFormParams.java
index e44c5c8..bf5dfff 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestFormParams.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestFormParams.java
@@ -19,7 +19,6 @@ import static org.apache.juneau.internal.ClassUtils.*;
import static org.apache.juneau.internal.StringUtils.*;
import static org.apache.juneau.internal.ThrowableUtils.*;
-import java.time.*;
import java.util.*;
import javax.servlet.http.*;
@@ -29,6 +28,7 @@ import org.apache.juneau.*;
import org.apache.juneau.collections.*;
import org.apache.juneau.http.*;
import org.apache.juneau.http.header.*;
+import org.apache.juneau.http.part.*;
import org.apache.juneau.httppart.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.rest.util.*;
@@ -37,6 +37,76 @@ import org.apache.juneau.utils.*;
/**
* Represents the parsed form-data parameters in an HTTP request.
+ *
+ * <p>
+ * The {@link RequestFormParams} object is the API for accessing the HTTP request body as form data.
+ * It can be accessed by passing it as a parameter on your REST Java method:
+ * </p>
+ * <p class='bcode w800'>
+ * <ja>@RestPost</ja>(...)
+ * <jk>public</jk> Object myMethod(RequestFormParams <jv>formData</jv>) {...}
+ * </p>
+ *
+ * <h5 class='figure'>Example:</h5>
+ * <p class='bcode w800'>
+ * <ja>@RestPost</ja>(...)
+ * <jk>public</jk> Object myMethod(RequestFormParams <jv>formData</jv>) {
+ *
+ * <jc>// Get query parameters converted to various types.</jc>
+ * <jk>int</jk> <jv>p1</jv> = <jv>formData</jv>.get(<js>"p1"</js>).asInteger().orElse(0);
+ * String <jv>p2</jv> = <jv>formData<jv>.get(<js>"p2"</js>).orElse(<jk>null</jk>);
+ * UUID <jv>p3</jv> = <jv>formData</jv>.get(<js>"p3"</js>).as(UUID.<jk>class</jk>).orElse(<jk>null</jk>);
+ * }
+ * </p>
+ *
+ * <p>
+ * Note that this object does NOT take GET parameters into account and only returns values found in the body of the request.
+ * </p>
+ *
+ * <p>
+ * Some important methods on this class are:
+ * </p>
+ * <ul class='javatree'>
+ * <li class='jc'>{@link RequestFormParams}
+ * <ul class='spaced-list'>
+ * <li>Methods for retrieving form data parameters:
+ * <ul class='javatreec'>
+ * <li class='jm'>{@link RequestFormParams#contains(String...) contains(String...)}
+ * <li class='jm'>{@link RequestFormParams#containsAny(String...) containsAny(String...)}
+ * <li class='jm'>{@link RequestFormParams#get(Class) get(Class)}
+ * <li class='jm'>{@link RequestFormParams#get(String) get(String)}
+ * <li class='jm'>{@link RequestFormParams#getAll() getAll()}
+ * <li class='jm'>{@link RequestFormParams#getAll(String) getAll(String)}
+ * <li class='jm'>{@link RequestFormParams#getFirst(String) getFirst(String)}
+ * <li class='jm'>{@link RequestFormParams#getLast(String) getLast(String)}
+ * <li class='jm'>{@link RequestFormParams#getSearchArgs() getSearchArgs()}
+ * </ul>
+ * <li>Methods overridding form data parameters:
+ * <ul class='javatreec'>
+ * <li class='jm'>{@link RequestFormParams#add(NameValuePair...) add(NameValuePair...)}
+ * <li class='jm'>{@link RequestFormParams#add(Part) add(Part)}
+ * <li class='jm'>{@link RequestFormParams#add(String,Object) add(String,Object)}
+ * <li class='jm'>{@link RequestFormParams#addDefault(List) addDefault(List)}
+ * <li class='jm'>{@link RequestFormParams#addDefault(NameValuePair...) addDefault(NameValuePair...)}
+ * <li class='jm'>{@link RequestFormParams#addDefault(String,String) addDefault(String,String)}
+ * <li class='jm'>{@link RequestFormParams#remove(NameValuePair...) remove(NameValuePair...)}
+ * <li class='jm'>{@link RequestFormParams#remove(String...) remove(String...)}
+ * <li class='jm'>{@link RequestFormParams#set(NameValuePair...) set(NameValuePair...)}
+ * <li class='jm'>{@link RequestFormParams#set(String,Object) set(String,Object)}
+ * </ul>
+ * <li>Other methods:
+ * <ul class='javatreec'>
+ * <li class='jm'>{@link RequestFormParams#asQueryString() asQueryString()}
+ * <li class='jm'>{@link RequestFormParams#copy() copy()}
+ * <li class='jm'>{@link RequestFormParams#isEmpty() isEmpty()}
+ * </ul>
+ * </ul>
+ * </ul>
+ *
+ * <ul class='seealso'>
+ * <li class='ja'>{@link org.apache.juneau.http.annotation.FormData}
+ * <li class='ja'>{@link org.apache.juneau.http.annotation.HasFormData}
+ * </ul>
*/
public class RequestFormParams {
@@ -161,6 +231,17 @@ public class RequestFormParams {
}
/**
+ * Adds a default entry to the form data parameters.
+ *
+ * @param name The name.
+ * @param value The value.
+ * @return This object.
+ */
+ public RequestFormParams addDefault(String name, String value) {
+ return addDefault(BasicStringPart.of(name, value));
+ }
+
+ /**
* Returns all the parameters with the specified name.
*
* @param name The parameter name.
@@ -262,6 +343,7 @@ public class RequestFormParams {
list.add(h);
return this;
}
+
/**
* Adds request parameter values.
*
@@ -417,66 +499,7 @@ public class RequestFormParams {
public <T> Optional<T> get(Class<T> type) {
ClassMeta<T> cm = req.getBeanSession().getClassMeta(type);
String name = HttpParts.getName(FORMDATA, cm).orElseThrow(()->runtimeException("@FormData(name) not found on class {0}", className(type)));
- return get(name).asPart(type);
- }
- /**
- * Returns the last parameter with the specified name as a string.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<String> getString(String name) {
- return getLast(name).asString();
- }
-
- /**
- * Returns the last parameter with the specified name as an integer.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<Integer> getInteger(String name) {
- return getLast(name).asInteger();
- }
-
- /**
- * Returns the last parameter with the specified name as a boolean.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<Boolean> getBoolean(String name) {
- return getLast(name).asBoolean();
- }
-
- /**
- * Returns the last parameter with the specified name as a list from a comma-delimited string.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<List<String>> getCsvArray(String name) {
- return getLast(name).asCsvArray();
- }
-
- /**
- * Returns the last parameter with the specified name as a long.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<Long> getLong(String name) {
- return getLast(name).asLong();
- }
-
- /**
- * Returns the last parameter with the specified name as a boolean.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<ZonedDateTime> getDate(String name) {
- return getLast(name).asDate();
+ return get(name).as(type);
}
//-----------------------------------------------------------------------------------------------------------------
@@ -550,12 +573,12 @@ public class RequestFormParams {
public SearchArgs getSearchArgs() {
if (contains("s","v","o","p","l","i")) {
return new SearchArgs.Builder()
- .search(getString("s").orElse(null))
- .view(getString("v").orElse(null))
- .sort(getString("o").orElse(null))
- .position(getInteger("p").orElse(null))
- .limit(getInteger("l").orElse(null))
- .ignoreCase(getBoolean("i").orElse(null))
+ .search(get("s").asString().orElse(null))
+ .view(get("v").asString().orElse(null))
+ .sort(get("o").asString().orElse(null))
+ .position(get("p").asInteger().orElse(null))
+ .limit(get("l").asInteger().orElse(null))
+ .ignoreCase(get("i").asBoolean().orElse(null))
.build();
}
return null;
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestHeader.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestHeader.java
index 56f1f20..da96423 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestHeader.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestHeader.java
@@ -13,8 +13,6 @@
package org.apache.juneau.rest;
import static org.apache.juneau.httppart.HttpPartType.*;
-import java.time.*;
-import java.util.*;
import org.apache.http.*;
import org.apache.juneau.http.header.*;
@@ -50,51 +48,6 @@ public class RequestHeader extends RequestHttpPart implements Header {
}
/**
- * Returns the value of this header as an integer.
- *
- * @return The value of this header as an integer, or {@link Optional#empty()} if the header was not present.
- */
- public Optional<Integer> asInteger() {
- return asIntegerHeader().asInteger();
- }
-
- /**
- * Returns the value of this header as a boolean.
- *
- * @return The value of this header as a boolean, or {@link Optional#empty()} if the header was not present.
- */
- public Optional<Boolean> asBoolean() {
- return asBooleanHeader().asBoolean();
- }
-
- /**
- * Returns the value of this header as a long.
- *
- * @return The value of this header as a long, or {@link Optional#empty()} if the header was not present.
- */
- public Optional<Long> asLong() {
- return asLongHeader().asLong();
- }
-
- /**
- * Returns the value of this header as a date.
- *
- * @return The value of this header as a date, or {@link Optional#empty()} if the header was not present.
- */
- public Optional<ZonedDateTime> asDate() {
- return asDateHeader().asZonedDateTime();
- }
-
- /**
- * Returns the value of this header as a list from a comma-delimited string.
- *
- * @return The value of this header as a list from a comma-delimited string, or {@link Optional#empty()} if the header was not present.
- */
- public Optional<List<String>> asCsvArray() {
- return asCsvArrayHeader().asList();
- }
-
- /**
* Returns the value of this header as a {@link BasicCsvArrayHeader}.
*
* @return The value of this header as a {@link BasicCsvArrayHeader}, never <jk>null</jk>.
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestHeaders.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestHeaders.java
index 6683106..ea101a2 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestHeaders.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestHeaders.java
@@ -20,7 +20,6 @@ import static java.util.stream.Collectors.*;
import static org.apache.juneau.assertions.Assertions.*;
import static org.apache.juneau.httppart.HttpPartType.*;
-import java.time.*;
import java.util.*;
import java.util.function.*;
@@ -31,15 +30,79 @@ import org.apache.juneau.svl.*;
import org.apache.juneau.*;
import org.apache.juneau.collections.*;
import org.apache.juneau.http.*;
+import org.apache.juneau.http.header.*;
/**
* Represents the headers in an HTTP request.
*
* <p>
+ * The {@link RequestHeaders} object is the API for accessing the headers of an HTTP request.
+ * It can be accessed by passing it as a parameter on your REST Java method:
+ * </p>
+ * <p class='bcode w800'>
+ * <ja>@RestPost</ja>(...)
+ * <jk>public</jk> Object myMethod(RequestHeaders <jv>headers</jv>) {...}
+ * </p>
+ *
+ * <h5 class='figure'>Example:</h5>
+ * <p class='bcode w800'>
+ * <ja>@RestPost</ja>(...)
+ * <jk>public</jk> Object myMethod(RequestHeaders <jv>headers</jv>) {
+ *
+ * <jc>// Add a default value.</jc>
+ * <jv>headers</jv>.addDefault(<js>"ETag"</js>, <jsf>DEFAULT_UUID</jsf>);
+ *
+ * <jc>// Get a header value as a POJO.</jc>
+ * UUID <jv>etag</jv> = <jv>headers</jv>.get(<js>"ETag"</js>).as(UUID.<jk>class</jk>).get();
+ *
+ * <jc>// Get a header as a standard HTTP part.</jc>
+ * ContentType <jv>contentType</jv> = <jv>headers</jv>.get(ContentType.<jk>class</jk>).orElse(ContentType.<jsf>TEXT_XML</jsf>);
+ * }
+ * </p>
+ *
+ * <p>
+ * Some important methods on this class are:
+ * </p>
+ * <ul class='javatree'>
+ * <li class='jc'>{@link RequestHeaders}
+ * <ul class='spaced-list'>
+ * <li>Methods for retrieving headers:
+ * <ul class='javatreec'>
+ * <li class='jm'>{@link RequestHeaders#contains(String...) contains(String...)}
+ * <li class='jm'>{@link RequestHeaders#containsAny(String...) containsAny(String...)}
+ * <li class='jm'>{@link RequestHeaders#get(Class) get(Class)}
+ * <li class='jm'>{@link RequestHeaders#get(String) get(String)}
+ * <li class='jm'>{@link RequestHeaders#getAll() getAll()}
+ * <li class='jm'>{@link RequestHeaders#getAll(String) getAll(String)}
+ * <li class='jm'>{@link RequestHeaders#getFirst(String) getFirst(String)}
+ * <li class='jm'>{@link RequestHeaders#getLast(String) getLast(String)}
+ * </ul>
+ * <li>Methods overridding headers:
+ * <ul class='javatreec'>
+ * <li class='jm'>{@link RequestHeaders#add(Header...) add(Header...)}
+ * <li class='jm'>{@link RequestHeaders#add(String, Object) add(String, Object)}
+ * <li class='jm'>{@link RequestHeaders#addDefault(Header...) addDefault(Header...)}
+ * <li class='jm'>{@link RequestHeaders#addDefault(List) addDefault(List)}
+ * <li class='jm'>{@link RequestHeaders#addDefault(String,String) addDefault(String,String)}
+ * <li class='jm'>{@link RequestHeaders#remove(Header...) remove(Header...)}
+ * <li class='jm'>{@link RequestHeaders#remove(String...) remove(String...)}
+ * <li class='jm'>{@link RequestHeaders#set(Header...) set(Header...)}
+ * <li class='jm'>{@link RequestHeaders#set(String,Object) set(String,Object)}
+ * </ul>
+ * <li>Other methods:
+ * <ul class='javatreec'>
+ * <li class='jm'>{@link RequestHeaders#copy() copy()}
+ * <li class='jm'>{@link RequestHeaders#isEmpty() isEmpty()}
+ * <li class='jm'>{@link RequestHeaders#subset(String...) subset(String...)}
+ * </ul>
+ * </ul>
+ * </ul>
+ *
+ * <p>
* Entries are stored in a case-insensitive map unless overridden via the constructor.
*
* <ul class='seealso'>
- * <li class='link'>{@doc RestmRequestHeaders}
+ * <li class='ja'>{@link org.apache.juneau.http.annotation.Header}
* </ul>
*/
public class RequestHeaders {
@@ -157,6 +220,17 @@ public class RequestHeaders {
}
/**
+ * Adds a default entry to the request headers.
+ *
+ * @param name The name.
+ * @param value The value.
+ * @return This object.
+ */
+ public RequestHeaders addDefault(String name, String value) {
+ return addDefault(BasicStringHeader.of(name, value));
+ }
+
+ /**
* Returns all the headers with the specified name.
*
* @param name The header name. Must not be <jk>null</jk>.
@@ -415,67 +489,7 @@ public class RequestHeaders {
public <T> Optional<T> get(Class<T> type) {
ClassMeta<T> cm = req.getBeanSession().getClassMeta(type);
String name = HttpParts.getName(HEADER, cm).orElseThrow(()->runtimeException("@Header(name) not found on class {0}", className(type)));
- return get(name).asPart(type);
- }
-
- /**
- * Returns the last header with the specified name as a string.
- *
- * @param name The header name.
- * @return The header value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<String> getString(String name) {
- return getLast(name).asString();
- }
-
- /**
- * Returns the last header with the specified name as an integer.
- *
- * @param name The header name.
- * @return The header value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<Integer> getInteger(String name) {
- return getLast(name).asInteger();
- }
-
- /**
- * Returns the last header with the specified name as a boolean.
- *
- * @param name The header name.
- * @return The header value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<Boolean> getBoolean(String name) {
- return getLast(name).asBoolean();
- }
-
- /**
- * Returns the last header with the specified name as a list from a comma-delimited string.
- *
- * @param name The header name.
- * @return The header value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<List<String>> getCsvArray(String name) {
- return getLast(name).asCsvArray();
- }
-
- /**
- * Returns the last header with the specified name as a long.
- *
- * @param name The header name.
- * @return The header value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<Long> getLong(String name) {
- return getLast(name).asLong();
- }
-
- /**
- * Returns the last header with the specified name as a boolean.
- *
- * @param name The header name.
- * @return The header value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<ZonedDateTime> getDate(String name) {
- return getLast(name).asDate();
+ return get(name).as(type);
}
//-----------------------------------------------------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestHttpPart.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestHttpPart.java
index 0d471ff..e6784f6 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestHttpPart.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestHttpPart.java
@@ -13,15 +13,15 @@
package org.apache.juneau.rest;
import static org.apache.juneau.httppart.HttpPartType.*;
-import static org.apache.juneau.internal.ClassUtils.*;
-import static org.apache.juneau.internal.ThrowableUtils.*;
-
import java.lang.reflect.*;
+import java.time.*;
import java.util.*;
import java.util.regex.*;
+import org.apache.http.*;
import org.apache.juneau.*;
import org.apache.juneau.http.*;
+import org.apache.juneau.http.part.*;
import org.apache.juneau.http.response.*;
import org.apache.juneau.httppart.*;
import org.apache.juneau.internal.*;
@@ -134,28 +134,6 @@ public abstract class RequestHttpPart {
}
/**
- * Returns the value of this part as the specified type.
- *
- * <p>
- * Looks for one of the following constructors:
- * <ul class='javatree'>
- * <li class='jm><c><jk>public</jv> T(String <jv>value</jv>);</c>
- * <li class='jm><c><jk>public</jv> T(String <jv>name</jv>, String <jv>value</jv>);</c>
- * </ul>
- *
- * @param c The part type.
- * @return The value of this part as the specified type, never <jk>null</jk>.
- */
- public <T> Optional<T> asPart(Class<T> c) {
- if (! isPresent())
- return Optional.empty();
- ConstructorInfo cc = HttpParts.getConstructor(getRequest().getBeanSession().getClassMeta(c)).orElseThrow(()->runtimeException("Could not determine a method to construct type {0}", className(c)));
- if (cc.getParamCount() == 1)
- return Optional.of(cc.invoke(get()));
- return Optional.of(cc.invoke(getName(), get()));
- }
-
- /**
* Returns the value of this part as a string.
*
* @return The value of this part as a string, or {@link Optional#empty()} if the part was not present.
@@ -176,32 +154,65 @@ public abstract class RequestHttpPart {
* @return The converted type, or {@link Optional#empty()} if the part is not present.
* @throws BasicHttpException If value could not be parsed.
*/
- public <T> Optional<T> asType(Type type, Type...args) throws BasicHttpException {
- return asType(request.getBeanSession().getClassMeta(type, args));
+ public <T> Optional<T> as(Type type, Type...args) throws BasicHttpException {
+ return as(request.getBeanSession().getClassMeta(type, args));
}
/**
* Converts this part to the specified POJO type using the request {@link HttpPartParser} and optional schema.
*
+ * <p>
+ * If the specified type is an HTTP part type (extends from {@link org.apache.http.Header}/{@link NameValuePair}), then looks for
+ * one of the following constructors:
+ * <ul class='javatree'>
+ * <li class='jm><c><jk>public</jv> T(String <jv>value</jv>);</c>
+ * <li class='jm><c><jk>public</jv> T(String <jv>name</jv>, String <jv>value</jv>);</c>
+ * </ul>
+ *
+ * <p>
+ * If it doesn't find one of those constructors, then it parses it into the specified type using the part parser.
+ *
* @param <T> The type to convert to.
* @param type The type to convert to.
* @return The converted type, or {@link Optional#empty()} if the part is not present.
* @throws BasicHttpException If value could not be parsed.
*/
- public <T> Optional<T> asType(Class<T> type) throws BasicHttpException {
- return asType(request.getBeanSession().getClassMeta(type));
+ public <T> Optional<T> as(Class<T> type) throws BasicHttpException {
+ return as(request.getBeanSession().getClassMeta(type));
}
/**
* Converts this part to the specified POJO type using the request {@link HttpPartParser} and optional schema.
*
+ * <p>
+ * If the specified type is an HTTP part type (extends from {@link org.apache.http.Header}/{@link NameValuePair}), then looks for
+ * one of the following constructors:
+ * <ul class='javatree'>
+ * <li class='jm><c><jk>public</jv> T(String <jv>value</jv>);</c>
+ * <li class='jm><c><jk>public</jv> T(String <jv>name</jv>, String <jv>value</jv>);</c>
+ * </ul>
+ *
+ * <p>
+ * If it doesn't find one of those constructors, then it parses it into the specified type using the part parser.
+ *
* @param <T> The type to convert to.
* @param type The type to convert to.
* @return The converted type, or {@link Optional#empty()} if the part is not present.
* @throws BasicHttpException If value could not be parsed.
*/
- public <T> Optional<T> asType(ClassMeta<T> type) throws BasicHttpException {
+ public <T> Optional<T> as(ClassMeta<T> type) throws BasicHttpException {
try {
+ if (HttpParts.isHttpPart(partType, type)) {
+ ConstructorInfo cc = HttpParts.getConstructor(type).orElse(null);
+ if (cc != null) {
+ if (! isPresent())
+ return Optional.empty();
+ if (cc.hasParamTypes(String.class))
+ return Optional.of(cc.invoke(get()));
+ if (cc.hasParamTypes(String.class, String.class))
+ return Optional.of(cc.invoke(getName(), get()));
+ }
+ }
return Optional.ofNullable(parser.parse(HEADER, schema, orElse(null), type));
} catch (ParseException e) {
throw new BadRequest(e, "Could not parse {0} parameter ''{1}''.", partType.toString().toLowerCase(), getName());
@@ -276,6 +287,118 @@ public abstract class RequestHttpPart {
}
/**
+ * Returns the value of this parameter as an integer.
+ *
+ * @return The value of this parameter as an integer, or {@link Optional#empty()} if the parameter was not present.
+ */
+ public Optional<Integer> asInteger() {
+ return asIntegerPart().asInteger();
+ }
+
+ /**
+ * Returns the value of this parameter as a boolean.
+ *
+ * @return The value of this parameter as a boolean, or {@link Optional#empty()} if the parameter was not present.
+ */
+ public Optional<Boolean> asBoolean() {
+ return asBooleanPart().asBoolean();
+ }
+
+ /**
+ * Returns the value of this parameter as a long.
+ *
+ * @return The value of this parameter as a long, or {@link Optional#empty()} if the parameter was not present.
+ */
+ public Optional<Long> asLong() {
+ return asLongPart().asLong();
+ }
+
+ /**
+ * Returns the value of this parameter as a date.
+ *
+ * @return The value of this parameter as a date, or {@link Optional#empty()} if the parameter was not present.
+ */
+ public Optional<ZonedDateTime> asDate() {
+ return asDatePart().asZonedDateTime();
+ }
+
+ /**
+ * Returns the value of this parameter as a list from a comma-delimited string.
+ *
+ * @return The value of this parameter as a list from a comma-delimited string, or {@link Optional#empty()} if the parameter was not present.
+ */
+ public Optional<List<String>> asCsvArray() {
+ return asCsvArrayPart().asList();
+ }
+
+ /**
+ * Returns the value of this parameter as a {@link BasicCsvArrayPart}.
+ *
+ * @return The value of this parameter as a {@link BasicCsvArrayPart}, never <jk>null</jk>.
+ */
+ public BasicCsvArrayPart asCsvArrayPart() {
+ return new BasicCsvArrayPart(getName(), getValue());
+ }
+
+ /**
+ * Returns the value of this parameter as a {@link BasicDatePart}.
+ *
+ * @return The value of this parameter as a {@link BasicDatePart}, never <jk>null</jk>.
+ */
+ public BasicDatePart asDatePart() {
+ return new BasicDatePart(getName(), getValue());
+ }
+
+ /**
+ * Returns the value of this parameter as a {@link BasicIntegerPart}.
+ *
+ * @return The value of this parameter as a {@link BasicIntegerPart}, never <jk>null</jk>.
+ */
+ public BasicIntegerPart asIntegerPart() {
+ return new BasicIntegerPart(getName(), getValue());
+ }
+
+ /**
+ * Returns the value of this parameter as a {@link BasicBooleanPart}.
+ *
+ * @return The value of this parameter as a {@link BasicBooleanPart}, never <jk>null</jk>.
+ */
+ public BasicBooleanPart asBooleanPart() {
+ return new BasicBooleanPart(getName(), getValue());
+ }
+
+ /**
+ * Returns the value of this parameter as a {@link BasicLongPart}.
+ *
+ * @return The value of this parameter as a {@link BasicLongPart}, never <jk>null</jk>.
+ */
+ public BasicLongPart asLongPart() {
+ return new BasicLongPart(getName(), getValue());
+ }
+
+ /**
+ * Returns the value of this parameter as a {@link BasicStringPart}.
+ *
+ * @return The value of this parameter as a {@link BasicStringPart}, never <jk>null</jk>.
+ */
+ public BasicStringPart asStringPart() {
+ return new BasicStringPart(getName(), getValue());
+ }
+
+ /**
+ * Returns the value of this parameter as a {@link BasicUriPart}.
+ *
+ * @return The value of this parameter as a {@link BasicUriPart}, never <jk>null</jk>.
+ */
+ public BasicUriPart asUriPart() {
+ return new BasicUriPart(getName(), getValue());
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ // Assertions
+ //------------------------------------------------------------------------------------------------------------------
+
+ /**
* Returns the request that created this part.
*
* @return The request that created this part.
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestPathParam.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestPathParam.java
index a192709..8afedf7 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestPathParam.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestPathParam.java
@@ -14,12 +14,8 @@ package org.apache.juneau.rest;
import static org.apache.juneau.httppart.HttpPartType.*;
-import java.time.*;
-import java.util.*;
-
import org.apache.http.*;
import org.apache.juneau.assertions.*;
-import org.apache.juneau.http.part.*;
import org.apache.juneau.httppart.*;
/**
@@ -50,105 +46,6 @@ public class RequestPathParam extends RequestHttpPart implements NameValuePair {
return value;
}
- /**
- * Returns the value of this parameter as an integer.
- *
- * @return The value of this parameter as an integer, or {@link Optional#empty()} if the parameter was not present.
- */
- public Optional<Integer> asInteger() {
- return asIntegerPart().asInteger();
- }
-
- /**
- * Returns the value of this parameter as a boolean.
- *
- * @return The value of this parameter as a boolean, or {@link Optional#empty()} if the parameter was not present.
- */
- public Optional<Boolean> asBoolean() {
- return asBooleanPart().asBoolean();
- }
-
- /**
- * Returns the value of this parameter as a long.
- *
- * @return The value of this parameter as a long, or {@link Optional#empty()} if the parameter was not present.
- */
- public Optional<Long> asLong() {
- return asLongPart().asLong();
- }
-
- /**
- * Returns the value of this parameter as a date.
- *
- * @return The value of this parameter as a date, or {@link Optional#empty()} if the parameter was not present.
- */
- public Optional<ZonedDateTime> asDate() {
- return asDatePart().asZonedDateTime();
- }
-
- /**
- * Returns the value of this parameter as a list from a comma-delimited string.
- *
- * @return The value of this parameter as a list from a comma-delimited string, or {@link Optional#empty()} if the parameter was not present.
- */
- public Optional<List<String>> asCsvArray() {
- return asCsvArrayPart().asList();
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicCsvArrayPart}.
- *
- * @return The value of this parameter as a {@link BasicCsvArrayPart}, never <jk>null</jk>.
- */
- public BasicCsvArrayPart asCsvArrayPart() {
- return new BasicCsvArrayPart(getName(), getValue());
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicDatePart}.
- *
- * @return The value of this parameter as a {@link BasicDatePart}, never <jk>null</jk>.
- */
- public BasicDatePart asDatePart() {
- return new BasicDatePart(getName(), getValue());
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicIntegerPart}.
- *
- * @return The value of this parameter as a {@link BasicIntegerPart}, never <jk>null</jk>.
- */
- public BasicIntegerPart asIntegerPart() {
- return new BasicIntegerPart(getName(), getValue());
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicBooleanPart}.
- *
- * @return The value of this parameter as a {@link BasicBooleanPart}, never <jk>null</jk>.
- */
- public BasicBooleanPart asBooleanPart() {
- return new BasicBooleanPart(getName(), getValue());
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicLongPart}.
- *
- * @return The value of this parameter as a {@link BasicLongPart}, never <jk>null</jk>.
- */
- public BasicLongPart asLongPart() {
- return new BasicLongPart(getName(), getValue());
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicStringPart}.
- *
- * @return The value of this parameter as a {@link BasicStringPart}, never <jk>null</jk>.
- */
- public BasicStringPart asStringPart() {
- return new BasicStringPart(getName(), getValue());
- }
-
//------------------------------------------------------------------------------------------------------------------
// Assertions
//------------------------------------------------------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestPathParams.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestPathParams.java
index 6acc5de..8f0eee3 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestPathParams.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestPathParams.java
@@ -19,7 +19,6 @@ import static java.util.Collections.*;
import static org.apache.juneau.assertions.Assertions.*;
import static org.apache.juneau.httppart.HttpPartType.*;
-import java.time.*;
import java.util.*;
import org.apache.http.*;
@@ -33,7 +32,71 @@ import org.apache.juneau.http.*;
/**
* Represents the path parameters in an HTTP request.
- */
+ *
+ * <p>
+ * The {@link RequestPathParams} object is the API for accessing the matched variables
+ * and remainder on the URL path.
+ * </p>
+ * <p class='bcode w800'>
+ * <ja>@RestPost</ja>(...)
+ * <jk>public</jk> Object myMethod(RequestPathParams <jv>path</jv>) {...}
+ * </p>
+ *
+ * <h5 class='figure'>Example:</h5>
+ * <p class='bcode w800'>
+ * <ja>@RestPost</ja>(..., path=<js>"/{foo}/{bar}/{baz}/*"</js>)
+ * <jk>public void</jk> doGet(RequestPathParams <jv>path</jv>) {
+ * <jc>// Example URL: /123/qux/true/quux</jc>
+ *
+ * <jk>int</jk> <jv>foo</jv> = <jv>path</jv>.get(<js>"foo"</js>).asInteger().orElse(0); <jc>// =123</jc>
+ * String <jv>bar</jv> = <jv>path</jv>.get(<js>"bar"</js>).orElse(<jk>null</jk>); <jc>// =qux</jc>
+ * <jk>boolean</jk> <jv>baz</jv> = <jv>path</jv>.get(<js>"baz"</js>).asBoolean().orElse(<jk>false</jk>); <jc>// =true</jc>
+ * String <jv>remainder</jv> = <jv>path</jv>.getRemainder(); <jc>// =quux</jc>
+ * }
+ * </p>
+ *
+ * <p>
+ * Some important methods on this class are:
+ * </p>
+ * <ul class='javatree'>
+ * <li class='jc'>{@link RequestPathParams}
+ * <ul class='spaced-list'>
+ * <li>Methods for retrieving path parameters:
+ * <ul class='javatreec'>
+ * <li class='jm'>{@link RequestPathParams#contains(String...) contains(String...)}
+ * <li class='jm'>{@link RequestPathParams#containsAny(String...) containsAny(String...)}
+ * <li class='jm'>{@link RequestPathParams#get(Class) get(Class)}
+ * <li class='jm'>{@link RequestPathParams#get(String) get(String)}
+ * <li class='jm'>{@link RequestPathParams#getAll() getAll()}
+ * <li class='jm'>{@link RequestPathParams#getAll(String) getAll(String)}
+ * <li class='jm'>{@link RequestPathParams#getFirst(String) getFirst(String)}
+ * <li class='jm'>{@link RequestPathParams#getLast(String) getLast(String)}
+ * <li class='jm'>{@link RequestPathParams#getRemainder() getRemainder()}
+ * <li class='jm'>{@link RequestPathParams#getRemainderUndecoded() getRemainderUndecoded()}
+ * </ul>
+ * <li>Methods overridding path parameters:
+ * <ul class='javatreec'>
+ * <li class='jm'>{@link RequestPathParams#add(NameValuePair...) add(NameValuePair...)}
+ * <li class='jm'>{@link RequestPathParams#add(String,Object) add(String,Object)}
+ * <li class='jm'>{@link RequestPathParams#addDefault(List) addDefault(List)}
+ * <li class='jm'>{@link RequestPathParams#addDefault(NameValuePair...) addDefault(NameValuePair...)}
+ * <li class='jm'>{@link RequestPathParams#remove(NameValuePair...) remove(NameValuePair...)}
+ * <li class='jm'>{@link RequestPathParams#remove(String...) remove(String...)}
+ * <li class='jm'>{@link RequestPathParams#set(NameValuePair...) set(NameValuePair...)}
+ * <li class='jm'>{@link RequestPathParams#set(String,Object) set(String,Object)}
+ * </ul>
+ * <li>Other methods:
+ * <ul class='javatreec'>
+ * <li class='jm'>{@link RequestPathParams#copy() copy()}
+ * <li class='jm'>{@link RequestPathParams#isEmpty() isEmpty()}
+ * </ul>
+ * </ul>
+ * </ul>
+ *
+ * <ul class='seealso'>
+ * <li class='ja'>{@link org.apache.juneau.http.annotation.Path}
+ * </ul>
+*/
public class RequestPathParams {
private final RestSession session;
@@ -372,67 +435,7 @@ public class RequestPathParams {
public <T> Optional<T> get(Class<T> type) {
ClassMeta<T> cm = req.getBeanSession().getClassMeta(type);
String name = HttpParts.getName(PATH, cm).orElseThrow(()->runtimeException("@Path(name) not found on class {0}", className(type)));
- return get(name).asPart(type);
- }
-
- /**
- * Returns the last parameter with the specified name as a string.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<String> getString(String name) {
- return getLast(name).asString();
- }
-
- /**
- * Returns the last parameter with the specified name as an integer.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<Integer> getInteger(String name) {
- return getLast(name).asInteger();
- }
-
- /**
- * Returns the last parameter with the specified name as a boolean.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<Boolean> getBoolean(String name) {
- return getLast(name).asBoolean();
- }
-
- /**
- * Returns the last parameter with the specified name as a list from a comma-delimited string.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<List<String>> getCsvArray(String name) {
- return getLast(name).asCsvArray();
- }
-
- /**
- * Returns the last parameter with the specified name as a long.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<Long> getLong(String name) {
- return getLast(name).asLong();
- }
-
- /**
- * Returns the last parameter with the specified name as a boolean.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<ZonedDateTime> getDate(String name) {
- return getLast(name).asDate();
+ return get(name).as(type);
}
//-----------------------------------------------------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestQueryParam.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestQueryParam.java
index a6017fb..a664167 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestQueryParam.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestQueryParam.java
@@ -14,12 +14,8 @@ package org.apache.juneau.rest;
import static org.apache.juneau.httppart.HttpPartType.*;
-import java.time.*;
-import java.util.*;
-
import org.apache.http.*;
import org.apache.juneau.assertions.*;
-import org.apache.juneau.http.part.*;
import org.apache.juneau.httppart.*;
/**
@@ -50,114 +46,6 @@ public class RequestQueryParam extends RequestHttpPart implements NameValuePair
return value;
}
- /**
- * Returns the value of this parameter as an integer.
- *
- * @return The value of this parameter as an integer, or {@link Optional#empty()} if the parameter was not present.
- */
- public Optional<Integer> asInteger() {
- return asIntegerPart().asInteger();
- }
-
- /**
- * Returns the value of this parameter as a boolean.
- *
- * @return The value of this parameter as a boolean, or {@link Optional#empty()} if the parameter was not present.
- */
- public Optional<Boolean> asBoolean() {
- return asBooleanPart().asBoolean();
- }
-
- /**
- * Returns the value of this parameter as a long.
- *
- * @return The value of this parameter as a long, or {@link Optional#empty()} if the parameter was not present.
- */
- public Optional<Long> asLong() {
- return asLongPart().asLong();
- }
-
- /**
- * Returns the value of this parameter as a date.
- *
- * @return The value of this parameter as a date, or {@link Optional#empty()} if the parameter was not present.
- */
- public Optional<ZonedDateTime> asDate() {
- return asDatePart().asZonedDateTime();
- }
-
- /**
- * Returns the value of this parameter as a list from a comma-delimited string.
- *
- * @return The value of this parameter as a list from a comma-delimited string, or {@link Optional#empty()} if the parameter was not present.
- */
- public Optional<List<String>> asCsvArray() {
- return asCsvArrayPart().asList();
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicCsvArrayPart}.
- *
- * @return The value of this parameter as a {@link BasicCsvArrayPart}, never <jk>null</jk>.
- */
- public BasicCsvArrayPart asCsvArrayPart() {
- return new BasicCsvArrayPart(getName(), getValue());
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicDatePart}.
- *
- * @return The value of this parameter as a {@link BasicDatePart}, never <jk>null</jk>.
- */
- public BasicDatePart asDatePart() {
- return new BasicDatePart(getName(), getValue());
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicIntegerPart}.
- *
- * @return The value of this parameter as a {@link BasicIntegerPart}, never <jk>null</jk>.
- */
- public BasicIntegerPart asIntegerPart() {
- return new BasicIntegerPart(getName(), getValue());
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicBooleanPart}.
- *
- * @return The value of this parameter as a {@link BasicBooleanPart}, never <jk>null</jk>.
- */
- public BasicBooleanPart asBooleanPart() {
- return new BasicBooleanPart(getName(), getValue());
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicLongPart}.
- *
- * @return The value of this parameter as a {@link BasicLongPart}, never <jk>null</jk>.
- */
- public BasicLongPart asLongPart() {
- return new BasicLongPart(getName(), getValue());
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicStringPart}.
- *
- * @return The value of this parameter as a {@link BasicStringPart}, never <jk>null</jk>.
- */
- public BasicStringPart asStringPart() {
- return new BasicStringPart(getName(), getValue());
- }
-
- /**
- * Returns the value of this parameter as a {@link BasicUriPart}.
- *
- * @return The value of this parameter as a {@link BasicUriPart}, never <jk>null</jk>.
- */
- public BasicUriPart asUriPart() {
- return new BasicUriPart(getName(), getValue());
- }
-
//------------------------------------------------------------------------------------------------------------------
// Assertions
//------------------------------------------------------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestQueryParams.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestQueryParams.java
index 61e09f5..1296f2a 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestQueryParams.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestQueryParams.java
@@ -19,7 +19,6 @@ import static java.util.Collections.*;
import static org.apache.juneau.assertions.Assertions.*;
import static org.apache.juneau.httppart.HttpPartType.*;
-import java.time.*;
import java.util.*;
import org.apache.http.*;
@@ -30,15 +29,85 @@ import org.apache.juneau.utils.*;
import org.apache.juneau.*;
import org.apache.juneau.collections.*;
import org.apache.juneau.http.*;
+import org.apache.juneau.http.part.*;
/**
* Represents the query parameters in an HTTP request.
*
* <p>
+ * The {@link RequestQueryParams} object is the API for accessing the GET query parameters of an HTTP request.
+ * It can be accessed by passing it as a parameter on your REST Java method:
+ * </p>
+ * <p class='bcode w800'>
+ * <ja>@RestPost</ja>(...)
+ * <jk>public</jk> Object myMethod(RequestQueryParams <jv>query</jv>) {...}
+ * </p>
+ *
+ * <h5 class='figure'>Example:</h5>
+ * <p class='bcode w800'>
+ * <ja>@RestPost</ja>(...)
+ * <jk>public</jk> Object myMethod(RequestQueryParams <jv>query</jv>) {
+ *
+ * <jc>// Get query parameters converted to various types.</jc>
+ * <jk>int</jk> <jv>p1</jv> = <jv>query</jv>.get(<js>"p1"</js>).asInteger().orElse(0);
+ * String <jv>p2</jv> = <jv>query</jv>.get(<js>"p2"</js>).orElse(<jk>null</jk>);
+ * UUID <jv>p3</jv> = <jv>query</jv>.get(<js>"p3"</js>).as(UUID.<jk>class</jk>).orElse(<jk>null</jk>);
+ * }
+ * </p>
+ *
+ * <p>
+ * An important distinction between the behavior of this object and <l>HttpServletRequest.getParameter(String)</l> is
+ * that the former will NOT load the body of the request on FORM POSTS and will only look at parameters
+ * found in the query string.
+ * This can be useful in cases where you're mixing GET parameters and FORM POSTS and you don't want to
+ * inadvertently read the body of the request to get a query parameter.
+ * </p>
+ *
+ * <p>
+ * Some important methods on this class are:
+ * </p>
+ * <ul class='javatree'>
+ * <li class='jc'>{@link RequestQueryParams}
+ * <ul class='spaced-list'>
+ * <li>Methods for retrieving query parameters:
+ * <ul class='javatreec'>
+ * <li class='jm'>{@link RequestQueryParams#contains(String...) contains(String...)}
+ * <li class='jm'>{@link RequestQueryParams#containsAny(String...) containsAny(String...)}
+ * <li class='jm'>{@link RequestQueryParams#get(Class) get(Class)}
+ * <li class='jm'>{@link RequestQueryParams#get(String) get(String)}
+ * <li class='jm'>{@link RequestQueryParams#getAll() getAll()}
+ * <li class='jm'>{@link RequestQueryParams#getAll(String) getAll(String)}
+ * <li class='jm'>{@link RequestQueryParams#getFirst(String) getFirst(String)}
+ * <li class='jm'>{@link RequestQueryParams#getLast(String) getLast(String)}
+ * <li class='jm'>{@link RequestQueryParams#getSearchArgs() getSearchArgs()}
+ * </ul>
+ * <li>Methods overridding query parameters:
+ * <ul class='javatreec'>
+ * <li class='jm'>{@link RequestQueryParams#add(NameValuePair...) add(NameValuePair...)}
+ * <li class='jm'>{@link RequestQueryParams#add(String,Object) add(String,Object)}
+ * <li class='jm'>{@link RequestQueryParams#addDefault(List) addDefault(List)}
+ * <li class='jm'>{@link RequestQueryParams#addDefault(NameValuePair...) addDefault(NameValuePair...)}
+ * <li class='jm'>{@link RequestQueryParams#addDefault(String,String) addDefault(String,String)}
+ * <li class='jm'>{@link RequestQueryParams#remove(NameValuePair...) remove(NameValuePair...)}
+ * <li class='jm'>{@link RequestQueryParams#remove(String...) remove(String...)}
+ * <li class='jm'>{@link RequestQueryParams#set(NameValuePair...) set(NameValuePair...)}
+ * <li class='jm'>{@link RequestQueryParams#set(String,Object) set(String,Object)}
+ * </ul>
+ * <li>Other methods:
+ * <ul class='javatreec'>
+ * <li class='jm'>{@link RequestQueryParams#asQueryString() asQueryString()}
+ * <li class='jm'>{@link RequestQueryParams#copy() copy()}
+ * <li class='jm'>{@link RequestQueryParams#isEmpty() isEmpty()}
+ * </ul>
+ * </ul>
+ * </ul>
+ *
+ * <p>
* Entries are stored in a case-sensitive map unless overridden via the constructor.
*
* <ul class='seealso'>
- * <li class='link'>{@doc RestmRequestHeaders}
+ * <li class='ja'>{@link org.apache.juneau.http.annotation.Query}
+ * <li class='ja'>{@link org.apache.juneau.http.annotation.HasQuery}
* </ul>
*/
public class RequestQueryParams {
@@ -147,6 +216,17 @@ public class RequestQueryParams {
}
/**
+ * Adds a default entry to the query parameters.
+ *
+ * @param name The name.
+ * @param value The value.
+ * @return This object.
+ */
+ public RequestQueryParams addDefault(String name, String value) {
+ return addDefault(BasicStringPart.of(name, value));
+ }
+
+ /**
* Returns all the parameters with the specified name.
*
* @param name The parameter name.
@@ -382,67 +462,7 @@ public class RequestQueryParams {
public <T> Optional<T> get(Class<T> type) {
ClassMeta<T> cm = req.getBeanSession().getClassMeta(type);
String name = HttpParts.getName(QUERY, cm).orElseThrow(()->runtimeException("@Query(name) not found on class {0}", className(type)));
- return get(name).asPart(type);
- }
-
- /**
- * Returns the last parameter with the specified name as a string.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<String> getString(String name) {
- return getLast(name).asString();
- }
-
- /**
- * Returns the last parameter with the specified name as an integer.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<Integer> getInteger(String name) {
- return getLast(name).asInteger();
- }
-
- /**
- * Returns the last parameter with the specified name as a boolean.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<Boolean> getBoolean(String name) {
- return getLast(name).asBoolean();
- }
-
- /**
- * Returns the last parameter with the specified name as a list from a comma-delimited string.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<List<String>> getCsvArray(String name) {
- return getLast(name).asCsvArray();
- }
-
- /**
- * Returns the last parameter with the specified name as a long.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<Long> getLong(String name) {
- return getLast(name).asLong();
- }
-
- /**
- * Returns the last parameter with the specified name as a boolean.
- *
- * @param name The parameter name.
- * @return The parameter value, or {@link Optional#empty()} if it doesn't exist.
- */
- public Optional<ZonedDateTime> getDate(String name) {
- return getLast(name).asDate();
+ return get(name).as(type);
}
//-----------------------------------------------------------------------------------------------------------------
@@ -516,12 +536,12 @@ public class RequestQueryParams {
public SearchArgs getSearchArgs() {
if (contains("s","v","o","p","l","i")) {
return new SearchArgs.Builder()
- .search(getString("s").orElse(null))
- .view(getString("v").orElse(null))
- .sort(getString("o").orElse(null))
- .position(getInteger("p").orElse(null))
- .limit(getInteger("l").orElse(null))
- .ignoreCase(getBoolean("i").orElse(null))
+ .search(get("s").asString().orElse(null))
+ .view(get("v").asString().orElse(null))
+ .sort(get("o").asString().orElse(null))
+ .position(get("p").asInteger().orElse(null))
+ .limit(get("l").asInteger().orElse(null))
+ .ignoreCase(get("i").asBoolean().orElse(null))
.build();
}
return null;
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpInvoker.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpInvoker.java
index 5f059c6..6de34cb 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpInvoker.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpInvoker.java
@@ -66,7 +66,7 @@ public class RestOpInvoker extends MethodInvoker {
Object output = super.invoke(session.getResource(), args);
// Handle manual call to req.setDebug().
- Boolean debug = req.getAttribute("Debug").asType(Boolean.class).orElse(null);
+ Boolean debug = req.getAttribute("Debug").as(Boolean.class).orElse(null);
if (debug == Boolean.TRUE) {
session.debug(true);
} else if (debug == Boolean.FALSE) {
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
index 259b2f1..3937746 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
@@ -234,7 +234,7 @@ public final class RestRequest {
body = new RequestBody(this);
if (context.isAllowBodyParam()) {
- String b = queryParams.getString("body").orElse(null);
+ String b = queryParams.get("body").asString().orElse(null);
if (b != null) {
headers.set("Content-Type", UonSerializer.DEFAULT.getResponseContentType());
body.load(MediaType.UON, UonParser.DEFAULT, b.getBytes(UTF8));
@@ -407,7 +407,7 @@ public final class RestRequest {
* <jv>headers</jv>.addDefault(<js>"ETag"</js>, <jsf>DEFAULT_UUID</jsf>);
*
* <jc>// Get a header value as a POJO.</jc>
- * UUID etag = <jv>headers</jv>.get(<js>"ETag"</js>).asType(UUID.<jk>class</jk>).orElse(<jk>null</jk>);
+ * UUID etag = <jv>headers</jv>.get(<js>"ETag"</js>).as(UUID.<jk>class</jk>).orElse(<jk>null</jk>);
*
* <jc>// Get a standard header.</jc>
* Optional<CacheControl> = <jv>headers</jv>.getCacheControl();
@@ -530,7 +530,7 @@ public final class RestRequest {
*/
public Locale getLocale() {
Locale best = inner.getLocale();
- String h = headers.getString("Accept-Language").orElse(null);
+ String h = headers.get("Accept-Language").asString().orElse(null);
if (h != null) {
StringRanges sr = StringRanges.of(h);
float qValue = 0;
@@ -612,7 +612,7 @@ public final class RestRequest {
* @return The parsed header on the request, never <jk>null</jk>.
*/
public Optional<TimeZone> getTimeZone() {
- String tz = headers.getString("Time-Zone").orElse(null);
+ String tz = headers.get("Time-Zone").asString().orElse(null);
if (tz != null)
return of(TimeZone.getTimeZone(tz));
return empty();
@@ -947,7 +947,7 @@ public final class RestRequest {
* <jk>public void</jk> doPost(RestRequest <jv>req</jv>) {
*
* <jc>// Convert body to a linked list of Person objects.</jc>
- * List<Person> <jv>list</jv> = <jv>req</jv>.getBody().asType(LinkedList.<jk>class</jk>, Person.<jk>class</jk>);
+ * List<Person> <jv>list</jv> = <jv>req</jv>.getBody().as(LinkedList.<jk>class</jk>, Person.<jk>class</jk>);
* ..
* }
* </p>
@@ -1272,7 +1272,7 @@ public final class RestRequest {
* @return <jk>true</jk> if {@code &plainText=true} was specified as a URL parameter
*/
public boolean isPlainText() {
- return "true".equals(queryParams.getString("plainText").orElse("false"));
+ return "true".equals(queryParams.get("plainText").asString().orElse("false"));
}
/**
@@ -1356,7 +1356,7 @@ public final class RestRequest {
* @return <jk>true</jk> if debug mode is enabled.
*/
public boolean isDebug() {
- return getAttribute("Debug").asType(Boolean.class).orElse(false);
+ return getAttribute("Debug").as(Boolean.class).orElse(false);
}
/**
@@ -1605,15 +1605,15 @@ public final class RestRequest {
ClassMeta<?> type = bs.getClassMeta(method.getGenericReturnType());
HttpPartType pt = pm.getPartType();
if (pt == HttpPartType.BODY)
- return getBody().setSchema(schema).asType(type);
+ return getBody().setSchema(schema).as(type);
if (pt == QUERY)
- return getQueryParam(name).parser(pp).schema(schema).asType(type).orElse(null);
+ return getQueryParam(name).parser(pp).schema(schema).as(type).orElse(null);
if (pt == FORMDATA)
- return getFormParam(name).parser(pp).schema(schema).asType(type).orElse(null);
+ return getFormParam(name).parser(pp).schema(schema).as(type).orElse(null);
if (pt == HEADER)
- return getHeader(name).parser(pp).schema(schema).asType(type).orElse(null);
+ return getHeader(name).parser(pp).schema(schema).as(type).orElse(null);
if (pt == PATH)
- return getPathParam(name).parser(pp).schema(schema).asType(type).orElse(null);
+ return getPathParam(name).parser(pp).schema(schema).as(type).orElse(null);
}
return null;
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/AttributeArg.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/AttributeArg.java
index c2aa3a7..3ac13a1 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/AttributeArg.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/AttributeArg.java
@@ -28,7 +28,7 @@ import org.apache.juneau.rest.annotation.*;
* .{@link RestOpSession#getRequest() getRequest}()
* .{@link RestRequest#getAttributes() getAttributes}()
* .{@link RequestAttributes#get(String) get}(<jv>name</jv>)
- * .{@link RequestAttribute#asType(Class) asType}(<jv>type</jv>);
+ * .{@link RequestAttribute#as(Class) as}(<jv>type</jv>);
* </p>
*/
public class AttributeArg implements RestOpArg {
@@ -71,6 +71,6 @@ public class AttributeArg implements RestOpArg {
@Override /* RestOpArg */
public Object resolve(RestOpSession opSession) throws Exception {
- return opSession.getRequest().getAttribute(name).asType(type).orElse(null);
+ return opSession.getRequest().getAttribute(name).as(type).orElse(null);
}
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/BodyArg.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/BodyArg.java
index ba58f37..81c0207 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/BodyArg.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/BodyArg.java
@@ -30,7 +30,7 @@ import org.apache.juneau.rest.annotation.*;
* .{@link RestOpSession#getRequest() getRequest}()
* .{@link RestRequest#getBody() getBody}()
* .{@link RequestBody#setSchema(HttpPartSchema) setSchema}(<jv>schema</jv>)
- * .{@link RequestBody#asType(Type,Type...) asType}(<jv>type</jv>);
+ * .{@link RequestBody#as(Type,Type...) as}(<jv>type</jv>);
* </p>
*
* <p>
@@ -65,6 +65,6 @@ public class BodyArg implements RestOpArg {
@Override /* RestOpArg */
public Object resolve(RestOpSession opSession) throws Exception {
- return opSession.getRequest().getBody().setSchema(schema).asType(type);
+ return opSession.getRequest().getBody().setSchema(schema).as(type);
}
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/FormDataArg.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/FormDataArg.java
index e2878db..332768d 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/FormDataArg.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/FormDataArg.java
@@ -36,7 +36,7 @@ import org.apache.juneau.rest.annotation.*;
* .{@link RestOpSession#getRequest() getRequest}()
* .{@link RestRequest#getFormParams() getFormParams}()
* .{@link RequestFormParams#get(String) get}(<jv>name</jv>)
- * .{@link RequestFormParam#asType(Class) asType}(<jv>type</jv>);
+ * .{@link RequestFormParam#as(Class) as}(<jv>type</jv>);
* </p>
*
* <p>
@@ -111,17 +111,17 @@ public class FormDataArg implements RestOpArg {
if (multi) {
Collection c = cm.isArray() ? new ArrayList<>() : (Collection)(cm.canCreateNewInstance() ? cm.newInstance() : new OList());
- rh.getAll(name).stream().map(x -> x.parser(ps).schema(schema).asType(cm.getElementType()).orElse(null)).forEach(x -> c.add(x));
+ rh.getAll(name).stream().map(x -> x.parser(ps).schema(schema).as(cm.getElementType()).orElse(null)).forEach(x -> c.add(x));
return cm.isArray() ? ArrayUtils.toArray(c, cm.getElementType().getInnerClass()) : c;
}
if (cm.isMapOrBean() && isOneOf(name, "*", "")) {
OMap m = new OMap();
for (RequestFormParam e : rh.getAll())
- m.put(e.getName(), e.parser(ps).schema(schema == null ? null : schema.getProperty(e.getName())).asType(cm.getValueType()).orElse(null));
+ m.put(e.getName(), e.parser(ps).schema(schema == null ? null : schema.getProperty(e.getName())).as(cm.getValueType()).orElse(null));
return req.getBeanSession().convertToType(m, cm);
}
- return rh.getLast(name).parser(ps).schema(schema).asType(type.innerType()).orElse(null);
+ return rh.getLast(name).parser(ps).schema(schema).as(type.innerType()).orElse(null);
}
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/HeaderArg.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/HeaderArg.java
index 25224bd..3a8dc3a 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/HeaderArg.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/HeaderArg.java
@@ -155,17 +155,17 @@ public class HeaderArg implements RestOpArg {
if (multi) {
Collection c = cm.isArray() ? new ArrayList<>() : (Collection)(cm.canCreateNewInstance() ? cm.newInstance() : new OList());
- rh.getAll(name).stream().map(x -> x.parser(ps).schema(schema).asType(cm.getElementType()).orElse(null)).forEach(x -> c.add(x));
+ rh.getAll(name).stream().map(x -> x.parser(ps).schema(schema).as(cm.getElementType()).orElse(null)).forEach(x -> c.add(x));
return cm.isArray() ? ArrayUtils.toArray(c, cm.getElementType().getInnerClass()) : c;
}
if (cm.isMapOrBean() && isOneOf(name, "*", "")) {
OMap m = new OMap();
for (RequestHeader e : rh.getAll())
- m.put(e.getName(), e.parser(ps).schema(schema == null ? null : schema.getProperty(e.getName())).asType(cm.getValueType()).orElse(null));
+ m.put(e.getName(), e.parser(ps).schema(schema == null ? null : schema.getProperty(e.getName())).as(cm.getValueType()).orElse(null));
return req.getBeanSession().convertToType(m, cm);
}
- return rh.getLast(name).parser(ps).schema(schema).asType(type.innerType()).orElse(null);
+ return rh.getLast(name).parser(ps).schema(schema).as(type.innerType()).orElse(null);
}
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/PathArg.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/PathArg.java
index a21cd31..946c520 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/PathArg.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/PathArg.java
@@ -37,7 +37,7 @@ import org.apache.juneau.rest.util.*;
* .{@link RestOpSession#getRequest() getRequest}()
* .{@link RestRequest#getPathParams() getPathParams}()
* .{@link RequestPathParams#get(String) get}(<jv>name</jv>)
- * .{@link RequestPathParam#asType(Class) asType}(<jv>type</jv>);
+ * .{@link RequestPathParam#as(Class) as}(<jv>type</jv>);
* </p>
*
* <p>
@@ -118,6 +118,6 @@ public class PathArg implements RestOpArg {
return req.getBeanSession().convertToType(m, type);
}
HttpPartParserSession ps = partParser == null ? req.getPartParserSession() : partParser.getPartSession();
- return req.getPathParams().get(name).parser(ps).schema(schema).asType(type).orElse(null);
+ return req.getPathParams().get(name).parser(ps).schema(schema).as(type).orElse(null);
}
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/QueryArg.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/QueryArg.java
index b0e8f88..0fe8fba 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/QueryArg.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/QueryArg.java
@@ -36,7 +36,7 @@ import org.apache.juneau.rest.annotation.*;
* .{@link RestOpSession#getRequest() getRequest}()
* .{@link RestRequest#getQueryParams() getQueryParams}()
* .{@link RequestQueryParams#get(String) get}(<jv>name</jv>)
- * .{@link RequestQueryParam#asType(Class) asType}(<jv>type</jv>);
+ * .{@link RequestQueryParam#as(Class) as}(<jv>type</jv>);
* </p>
*
* <p>
@@ -111,17 +111,17 @@ public class QueryArg implements RestOpArg {
if (multi) {
Collection c = cm.isArray() ? new ArrayList<>() : (Collection)(cm.canCreateNewInstance() ? cm.newInstance() : new OList());
- rh.getAll(name).stream().map(x -> x.parser(ps).schema(schema).asType(cm.getElementType()).orElse(null)).forEach(x -> c.add(x));
+ rh.getAll(name).stream().map(x -> x.parser(ps).schema(schema).as(cm.getElementType()).orElse(null)).forEach(x -> c.add(x));
return cm.isArray() ? ArrayUtils.toArray(c, cm.getElementType().getInnerClass()) : c;
}
if (cm.isMapOrBean() && isOneOf(name, "*", "")) {
OMap m = new OMap();
for (RequestQueryParam e : rh.getAll())
- m.put(e.getName(), e.parser(ps).schema(schema == null ? null : schema.getProperty(e.getName())).asType(cm.getValueType()).orElse(null));
+ m.put(e.getName(), e.parser(ps).schema(schema == null ? null : schema.getProperty(e.getName())).as(cm.getValueType()).orElse(null));
return req.getBeanSession().convertToType(m, cm);
}
- return rh.getLast(name).parser(ps).schema(schema).asType(type.innerType()).orElse(null);
+ return rh.getLast(name).parser(ps).schema(schema).as(type.innerType()).orElse(null);
}
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestBodyAssertion.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestBodyAssertion.java
index 377765f..2906394 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestBodyAssertion.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestBodyAssertion.java
@@ -56,8 +56,8 @@ import org.apache.juneau.serializer.*;
* <h5 class='topic'>Transform Methods</h5>
* <ul>
* <li class='jm'>{@link FluentRequestBodyAssertion#asBytes()}
- * <li class='jm'>{@link FluentRequestBodyAssertion#asType(Class)}
- * <li class='jm'>{@link FluentRequestBodyAssertion#asType(Type,Type...)}
+ * <li class='jm'>{@link FluentRequestBodyAssertion#as(Class)}
+ * <li class='jm'>{@link FluentRequestBodyAssertion#as(Type,Type...)}
* <li class='jm'>{@link FluentObjectAssertion#asString()}
* <li class='jm'>{@link FluentObjectAssertion#asString(WriterSerializer)}
* <li class='jm'>{@link FluentObjectAssertion#asString(Function)}
@@ -156,14 +156,14 @@ public class FluentRequestBodyAssertion<R> extends FluentObjectAssertion<Request
}
/**
- * Converts the body to a type using {@link RequestBody#asType(Class)} and then returns the value as an object assertion.
+ * Converts the body to a type using {@link RequestBody#as(Class)} and then returns the value as an object assertion.
*
* <h5 class='section'>Examples:</h5>
* <p class='bcode w800'>
* <jc>// Validates the request body bean is the expected value.</jc>
* <jv>request</jv>
* .assertBody()
- * .asType(MyBean.<jk>class</jk>)
+ * .as(MyBean.<jk>class</jk>)
* .json().is(<js>"{foo:'bar'}"</js>);
* </p>
*
@@ -182,19 +182,19 @@ public class FluentRequestBodyAssertion<R> extends FluentObjectAssertion<Request
* @param type The object type to create.
* @return A new fluent assertion object.
*/
- public <V> FluentObjectAssertion<V,R> asType(Class<V> type) {
+ public <V> FluentObjectAssertion<V,R> as(Class<V> type) {
return new FluentObjectAssertion<>(valueAsType(type), returns());
}
/**
- * Converts the body to a type using {@link RequestBody#asType(Type,Type...)} and then returns the value as an object assertion.
+ * Converts the body to a type using {@link RequestBody#as(Type,Type...)} and then returns the value as an object assertion.
*
* <h5 class='section'>Examples:</h5>
* <p class='bcode w800'>
* <jc>// Validates the request body bean is the expected value.</jc>
* <jv>request</jv>
* .assertBody()
- * .asType(Map.<jk>class</jk>,String.<jk>class</jk>,Integer.<jk>class</jk>)
+ * .as(Map.<jk>class</jk>,String.<jk>class</jk>,Integer.<jk>class</jk>)
* .json().is(<js>"{foo:123}"</js>);
* </p>
*
@@ -214,7 +214,7 @@ public class FluentRequestBodyAssertion<R> extends FluentObjectAssertion<Request
* @param args Optional type arguments.
* @return A new fluent assertion object.
*/
- public <V> FluentObjectAssertion<V,R> asType(Type type, Type...args) {
+ public <V> FluentObjectAssertion<V,R> as(Type type, Type...args) {
return new FluentObjectAssertion<>(valueAsType(type, args), returns());
}
@@ -298,7 +298,7 @@ public class FluentRequestBodyAssertion<R> extends FluentObjectAssertion<Request
private <T> T valueAsType(Class<T> c) throws AssertionError {
try {
- return value().cache().asType(c);
+ return value().cache().as(c);
} catch (IOException e) {
throw error(e, "Exception occurred during call.");
}
@@ -306,7 +306,7 @@ public class FluentRequestBodyAssertion<R> extends FluentObjectAssertion<Request
private <T> T valueAsType(Type c, Type...args) throws AssertionError {
try {
- return value().cache().asType(c, args);
+ return value().cache().as(c, args);
} catch (IOException e) {
throw error(e, "Exception occurred during call.");
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestFormParamAssertion.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestFormParamAssertion.java
index 1197c5a..31889d3 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestFormParamAssertion.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestFormParamAssertion.java
@@ -71,8 +71,8 @@ import org.apache.juneau.serializer.*;
* <li class='jm'>{@link FluentRequestFormParamAssertion#asInteger()}
* <li class='jm'>{@link FluentRequestFormParamAssertion#asLong()}
* <li class='jm'>{@link FluentRequestFormParamAssertion#asZonedDateTime()}
- * <li class='jm'>{@link FluentRequestFormParamAssertion#asType(Class)}
- * <li class='jm'>{@link FluentRequestFormParamAssertion#asType(Type,Type...)}
+ * <li class='jm'>{@link FluentRequestFormParamAssertion#as(Class)}
+ * <li class='jm'>{@link FluentRequestFormParamAssertion#as(Type,Type...)}
* <li class='jm'>{@link FluentStringAssertion#replaceAll(String,String)}
* <li class='jm'>{@link FluentStringAssertion#replace(String,String)}
* <li class='jm'>{@link FluentStringAssertion#urlDecode()}
@@ -198,17 +198,17 @@ public class FluentRequestFormParamAssertion<R> extends FluentStringAssertion<R>
}
/**
- * Converts the parameter value to a type using {@link RequestFormParam#asType(Class)} and then returns the value as an any-object assertion.
+ * Converts the parameter value to a type using {@link RequestFormParam#as(Class)} and then returns the value as an any-object assertion.
*
* @param type The object type to create.
* @return A new fluent assertion object.
*/
- public <V> FluentAnyAssertion<V,R> asType(Class<V> type) {
- return new FluentAnyAssertion<>(value.asType(type).orElse(null), returns());
+ public <V> FluentAnyAssertion<V,R> as(Class<V> type) {
+ return new FluentAnyAssertion<>(value.as(type).orElse(null), returns());
}
/**
- * Converts the parameter value to a type using {@link RequestFormParam#asType(Type,Type...)} and then returns the value as an any-object assertion.
+ * Converts the parameter value to a type using {@link RequestFormParam#as(Type,Type...)} and then returns the value as an any-object assertion.
*
* <p>
* See {@doc Generics Generics} for information on defining complex generic types of {@link Map Maps} and {@link Collection Collections}.
@@ -217,8 +217,8 @@ public class FluentRequestFormParamAssertion<R> extends FluentStringAssertion<R>
* @param args Optional type arguments.
* @return A new fluent assertion object.
*/
- public FluentAnyAssertion<Object,R> asType(Type type, Type...args) {
- return new FluentAnyAssertion<>(value.asType(type, args).orElse(null), returns());
+ public FluentAnyAssertion<Object,R> as(Type type, Type...args) {
+ return new FluentAnyAssertion<>(value.as(type, args).orElse(null), returns());
}
//-----------------------------------------------------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestHeaderAssertion.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestHeaderAssertion.java
index f75e7fa..8022a02 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestHeaderAssertion.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestHeaderAssertion.java
@@ -71,7 +71,7 @@ import org.apache.juneau.serializer.*;
* <li class='jm'>{@link FluentRequestHeaderAssertion#asInteger()}
* <li class='jm'>{@link FluentRequestHeaderAssertion#asLong()}
* <li class='jm'>{@link FluentRequestHeaderAssertion#asZonedDateTime()}
- * <li class='jm'>{@link FluentRequestHeaderAssertion#asType(Class)}
+ * <li class='jm'>{@link FluentRequestHeaderAssertion#as(Class)}
* <li class='jm'>{@link FluentStringAssertion#replaceAll(String,String)}
* <li class='jm'>{@link FluentStringAssertion#replace(String,String)}
* <li class='jm'>{@link FluentStringAssertion#urlDecode()}
@@ -199,17 +199,17 @@ public class FluentRequestHeaderAssertion <R> extends FluentStringAssertion<R> {
}
/**
- * Converts the parameter value to a type using {@link RequestHeader#asType(Class)} and then returns the value as an any-object assertion.
+ * Converts the parameter value to a type using {@link RequestHeader#as(Class)} and then returns the value as an any-object assertion.
*
* @param type The object type to create.
* @return A new fluent assertion object.
*/
- public <V> FluentAnyAssertion<V,R> asType(Class<V> type) {
- return new FluentAnyAssertion<>(value.asType(type).orElse(null), returns());
+ public <V> FluentAnyAssertion<V,R> as(Class<V> type) {
+ return new FluentAnyAssertion<>(value.as(type).orElse(null), returns());
}
/**
- * Converts the parameter value to a type using {@link RequestHeader#asType(Type,Type...)} and then returns the value as an any-object assertion.
+ * Converts the parameter value to a type using {@link RequestHeader#as(Type,Type...)} and then returns the value as an any-object assertion.
*
* <p>
* See {@doc Generics Generics} for information on defining complex generic types of {@link Map Maps} and {@link Collection Collections}.
@@ -218,8 +218,8 @@ public class FluentRequestHeaderAssertion <R> extends FluentStringAssertion<R> {
* @param args Optional type arguments.
* @return A new fluent assertion object.
*/
- public FluentAnyAssertion<Object,R> asType(Type type, Type...args) {
- return new FluentAnyAssertion<>(value.asType(type, args).orElse(null), returns());
+ public FluentAnyAssertion<Object,R> as(Type type, Type...args) {
+ return new FluentAnyAssertion<>(value.as(type, args).orElse(null), returns());
}
//-----------------------------------------------------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestQueryParamAssertion.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestQueryParamAssertion.java
index d541557..f789bc5 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestQueryParamAssertion.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestQueryParamAssertion.java
@@ -71,7 +71,7 @@ import org.apache.juneau.serializer.*;
* <li class='jm'>{@link FluentRequestQueryParamAssertion#asInteger()}
* <li class='jm'>{@link FluentRequestQueryParamAssertion#asLong()}
* <li class='jm'>{@link FluentRequestQueryParamAssertion#asZonedDateTime()}
- * <li class='jm'>{@link FluentRequestQueryParamAssertion#asType(Class)}
+ * <li class='jm'>{@link FluentRequestQueryParamAssertion#as(Class)}
* <li class='jm'>{@link FluentStringAssertion#replaceAll(String,String)}
* <li class='jm'>{@link FluentStringAssertion#replace(String,String)}
* <li class='jm'>{@link FluentStringAssertion#urlDecode()}
@@ -197,17 +197,17 @@ public class FluentRequestQueryParamAssertion<R> extends FluentStringAssertion<R
}
/**
- * Converts the parameter value to a type using {@link RequestQueryParam#asType(Class)} and then returns the value as an any-object assertion.
+ * Converts the parameter value to a type using {@link RequestQueryParam#as(Class)} and then returns the value as an any-object assertion.
*
* @param type The object type to create.
* @return A new fluent assertion object.
*/
- public <V> FluentAnyAssertion<V,R> asType(Class<V> type) {
- return new FluentAnyAssertion<>(value.asType(type).orElse(null), returns());
+ public <V> FluentAnyAssertion<V,R> as(Class<V> type) {
+ return new FluentAnyAssertion<>(value.as(type).orElse(null), returns());
}
/**
- * Converts the parameter value to a type using {@link RequestQueryParam#asType(Type,Type...)} and then returns the value as an any-object assertion.
+ * Converts the parameter value to a type using {@link RequestQueryParam#as(Type,Type...)} and then returns the value as an any-object assertion.
*
* <p>
* See {@doc Generics Generics} for information on defining complex generic types of {@link Map Maps} and {@link Collection Collections}.
@@ -216,8 +216,8 @@ public class FluentRequestQueryParamAssertion<R> extends FluentStringAssertion<R
* @param args Optional type arguments.
* @return A new fluent assertion object.
*/
- public FluentAnyAssertion<Object,R> asType(Type type, Type...args) {
- return new FluentAnyAssertion<>(value.asType(type, args).orElse(null), returns());
+ public FluentAnyAssertion<Object,R> as(Type type, Type...args) {
+ return new FluentAnyAssertion<>(value.as(type, args).orElse(null), returns());
}
//-----------------------------------------------------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/widget/MenuItemWidget.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/widget/MenuItemWidget.java
index e14d17e..e565235 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/widget/MenuItemWidget.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/widget/MenuItemWidget.java
@@ -172,7 +172,7 @@ public abstract class MenuItemWidget extends Widget {
}
private Integer getId(RestRequest req) {
- Integer id = req.getAttribute("LastMenuItemId").asType(Integer.class).orElse(0) + 1;
+ Integer id = req.getAttribute("LastMenuItemId").as(Integer.class).orElse(0) + 1;
req.setAttribute("LastMenuItemId", id);
return id;
}
diff --git a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/FormData_Test.java b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/FormData_Test.java
index 78cad68..05f2bf5 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/FormData_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/FormData_Test.java
@@ -40,7 +40,7 @@ public class FormData_Test {
@RestPost
public String a(RestRequest req, @FormData(name="p1",allowEmptyValue=true) String p1, @FormData(name="p2",allowEmptyValue=true) int p2) throws Exception {
RequestFormParams f = req.getFormParams();
- return "p1=["+p1+","+f.get("p1").orElse(null)+","+f.get("p1").asString().orElse(null)+"],p2=["+p2+","+f.get("p2").orElse(null)+","+f.get("p2").asType(int.class).orElse(null)+"]";
+ return "p1=["+p1+","+f.get("p1").orElse(null)+","+f.get("p1").asString().orElse(null)+"],p2=["+p2+","+f.get("p2").orElse(null)+","+f.get("p2").as(int.class).orElse(null)+"]";
}
}
@@ -99,9 +99,9 @@ public class FormData_Test {
@RestPost(defaultRequestFormData={"f1:1","f2=2"," f3 : 3 "})
public OMap a(RequestFormParams formData) {
return OMap.create()
- .a("f1", formData.getString("f1"))
- .a("f2", formData.getString("f2"))
- .a("f3", formData.getString("f3"));
+ .a("f1", formData.get("f1").asString())
+ .a("f2", formData.get("f2").asString())
+ .a("f3", formData.get("f3").asString());
}
@RestPost
public OMap b(@FormData("f1") String f1, @FormData("f2") String f2, @FormData("f3") String f3) {
diff --git a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Query_Test.java b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Query_Test.java
index 25d13ad..15ab65f 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Query_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Query_Test.java
@@ -40,12 +40,12 @@ public class Query_Test {
@RestGet
public String a(RestRequest req, @Query(n="p1",aev=true) String p1, @Query(n="p2",aev=true) int p2) throws Exception {
RequestQueryParams q = req.getQueryParams();
- return "p1=["+p1+","+q.getString("p1").orElse(null)+","+q.get("p1").asString().orElse(null)+"],p2=["+p2+","+q.getString("p2").orElse(null)+","+q.get("p2").asInteger().orElse(0)+"]";
+ return "p1=["+p1+","+q.get("p1").orElse(null)+","+q.get("p1").asString().orElse(null)+"],p2=["+p2+","+q.get("p2").orElse(null)+","+q.get("p2").asInteger().orElse(0)+"]";
}
@RestPost
public String b(RestRequest req, @Query(n="p1",aev=true) String p1, @Query(n="p2",aev=true) int p2) throws Exception {
RequestQueryParams q = req.getQueryParams();
- return "p1=["+p1+","+q.getString("p1").orElse(null)+","+q.get("p1").asString().orElse(null)+"],p2=["+p2+","+q.getString("p2").orElse(null)+","+q.get("p2").asInteger().orElse(0)+"]";
+ return "p1=["+p1+","+q.get("p1").orElse(null)+","+q.get("p1").asString().orElse(null)+"],p2=["+p2+","+q.get("p2").orElse(null)+","+q.get("p2").asInteger().orElse(0)+"]";
}
}
@@ -89,22 +89,22 @@ public class Query_Test {
@RestGet
public String a(RestRequest req, @Query(n="p1") String p1) throws Exception {
RequestQueryParams q = req.getQueryParams();
- return "p1=["+p1+","+q.getString("p1").orElse(null)+","+q.get("p1").asString().orElse(null)+"]";
+ return "p1=["+p1+","+q.get("p1").orElse(null)+","+q.get("p1").asString().orElse(null)+"]";
}
@RestGet
public String b(RestRequest req, @Query(n="p1",f="uon") String p1) throws Exception {
RequestQueryParams q = req.getQueryParams();
- return "p1=["+p1+","+q.getString("p1").orElse(null)+","+q.get("p1").asString().orElse(null)+"]";
+ return "p1=["+p1+","+q.get("p1").orElse(null)+","+q.get("p1").asString().orElse(null)+"]";
}
@RestPost
public String c(RestRequest req, @Query(n="p1") String p1) throws Exception {
RequestQueryParams q = req.getQueryParams();
- return "p1=["+p1+","+q.getString("p1").orElse(null)+","+q.get("p1").asString().orElse(null)+"]";
+ return "p1=["+p1+","+q.get("p1").orElse(null)+","+q.get("p1").asString().orElse(null)+"]";
}
@RestPost
public String d(RestRequest req, @Query(n="p1",f="uon") String p1) throws Exception {
RequestQueryParams q = req.getQueryParams();
- return "p1=["+p1+","+q.getString("p1").orElse(null)+","+q.get("p1").asString().orElse(null)+"]";
+ return "p1=["+p1+","+q.get("p1").orElse(null)+","+q.get("p1").asString().orElse(null)+"]";
}
}
@@ -185,9 +185,9 @@ public class Query_Test {
@RestGet(defaultRequestQueryData={"f1:1","f2=2"," f3 : 3 "})
public OMap a(RequestQueryParams query) {
return OMap.create()
- .a("f1", query.getString("f1"))
- .a("f2", query.getString("f2"))
- .a("f3", query.getString("f3"));
+ .a("f1", query.get("f1").asString())
+ .a("f2", query.get("f2").asString())
+ .a("f3", query.get("f3").asString());
}
@RestGet
public OMap b(@Query("f1") String f1, @Query("f2") String f2, @Query("f3") String f3) {
diff --git a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestHook_Test.java b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestHook_Test.java
index 673e9b2..ad6e274 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestHook_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestHook_Test.java
@@ -77,7 +77,7 @@ public class RestHook_Test {
public String b(RestRequest req, RequestAttributes attrs) throws Exception {
attrs.set("p3", "pp3");
attrs.set("p4", "pp4");
- return req.getBody().asType(String.class);
+ return req.getBody().as(String.class);
}
}
diff --git a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestOp_ReqHeaders_Test.java b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestOp_ReqHeaders_Test.java
index 417e6ae..6ccbe2c 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestOp_ReqHeaders_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestOp_ReqHeaders_Test.java
@@ -32,37 +32,37 @@ public class RestOp_ReqHeaders_Test {
@RestOp(defaultRequestHeaders={"H1:1","H2=2"," H3 : 3 "})
public OMap a(RequestHeaders headers) {
return OMap.create()
- .a("h1", headers.getString("H1").orElse(null))
- .a("h2", headers.getString("H2").orElse(null))
- .a("h3", headers.getString("H3").orElse(null));
+ .a("h1", headers.get("H1").orElse(null))
+ .a("h2", headers.get("H2").orElse(null))
+ .a("h3", headers.get("H3").orElse(null));
}
@RestGet(defaultRequestHeaders={"H1:1","H2=2"," H3 : 3 "})
public OMap b(RequestHeaders headers) {
return OMap.create()
- .a("h1", headers.getString("H1").orElse(null))
- .a("h2", headers.getString("H2").orElse(null))
- .a("h3", headers.getString("H3").orElse(null));
+ .a("h1", headers.get("H1").orElse(null))
+ .a("h2", headers.get("H2").orElse(null))
+ .a("h3", headers.get("H3").orElse(null));
}
@RestPut(defaultRequestHeaders={"H1:1","H2=2"," H3 : 3 "})
public OMap c(RequestHeaders headers) {
return OMap.create()
- .a("h1", headers.getString("H1").orElse(null))
- .a("h2", headers.getString("H2").orElse(null))
- .a("h3", headers.getString("H3").orElse(null));
+ .a("h1", headers.get("H1").orElse(null))
+ .a("h2", headers.get("H2").orElse(null))
+ .a("h3", headers.get("H3").orElse(null));
}
@RestPost(defaultRequestHeaders={"H1:1","H2=2"," H3 : 3 "})
public OMap d(RequestHeaders headers) {
return OMap.create()
- .a("h1", headers.getString("H1").orElse(null))
- .a("h2", headers.getString("H2").orElse(null))
- .a("h3", headers.getString("H3").orElse(null));
+ .a("h1", headers.get("H1").orElse(null))
+ .a("h2", headers.get("H2").orElse(null))
+ .a("h3", headers.get("H3").orElse(null));
}
@RestDelete(defaultRequestHeaders={"H1:1","H2=2"," H3 : 3 "})
public OMap e(RequestHeaders headers) {
return OMap.create()
- .a("h1", headers.getString("H1").orElse(null))
- .a("h2", headers.getString("H2").orElse(null))
- .a("h3", headers.getString("H3").orElse(null));
+ .a("h1", headers.get("H1").orElse(null))
+ .a("h2", headers.get("H2").orElse(null))
+ .a("h3", headers.get("H3").orElse(null));
}
}
@@ -100,9 +100,9 @@ public class RestOp_ReqHeaders_Test {
@RestGet(defaultRequestHeaders={"H1:1","H2=2"," H3 : 3 "})
public OMap a(RequestHeaders headers) {
return OMap.create()
- .a("h1", headers.getString("h1").orElse(null))
- .a("h2", headers.getString("h2").orElse(null))
- .a("h3", headers.getString("h3").orElse(null));
+ .a("h1", headers.get("h1").orElse(null))
+ .a("h2", headers.get("h2").orElse(null))
+ .a("h3", headers.get("h3").orElse(null));
}
}
diff --git a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Rest_AllowedHeaderParams_Test.java b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Rest_AllowedHeaderParams_Test.java
index d081b8f..440cccf 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Rest_AllowedHeaderParams_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Rest_AllowedHeaderParams_Test.java
@@ -30,9 +30,9 @@ public class Rest_AllowedHeaderParams_Test {
public static class A {
@RestOp
public String put(RequestHeaders h) {
- Accept accept = h.get("Accept").asPart(Accept.class).orElse(Accept.NULL);
- ContentType contentType = h.get("Content-Type").asPart(ContentType.class).orElse(ContentType.NULL);
- return "Accept="+(accept.isPresent() ? accept.get() : null)+",Content-Type=" + (contentType.isPresent() ? contentType.get() : null) + ",Custom=" + h.getString("Custom").orElse(null);
+ Accept accept = h.get("Accept").as(Accept.class).orElse(Accept.NULL);
+ ContentType contentType = h.get("Content-Type").as(ContentType.class).orElse(ContentType.NULL);
+ return "Accept="+(accept.isPresent() ? accept.get() : null)+",Content-Type=" + (contentType.isPresent() ? contentType.get() : null) + ",Custom=" + h.get("Custom").orElse(null);
}
}