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 c8390e2 REST refactoring.
c8390e2 is described below
commit c8390e2b27ee4ca2d7c2554a640eff55c372fb1c
Author: JamesBognar <[email protected]>
AuthorDate: Sat Feb 20 14:10:05 2021 -0500
REST refactoring.
---
.../java/org/apache/juneau/rest/RequestHeader.java | 243 ++----------------
.../org/apache/juneau/rest/RequestHttpPart.java | 272 +++++++++++++++++++++
.../org/apache/juneau/rest/RequestQueryParam.java | 249 ++-----------------
.../rest/Rest_PredefinedStatusCodes_Test.java | 2 +-
4 files changed, 310 insertions(+), 456 deletions(-)
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 bcb0bdc..fd999ce 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,32 +13,23 @@
package org.apache.juneau.rest;
import static org.apache.juneau.httppart.HttpPartType.*;
-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.exception.*;
import org.apache.juneau.http.exception.HttpException;
import org.apache.juneau.http.header.*;
import org.apache.juneau.httppart.*;
-import org.apache.juneau.oapi.*;
-import org.apache.juneau.parser.ParseException;
import org.apache.juneau.reflect.*;
import org.apache.juneau.rest.assertions.*;
/**
* Represents a single header on an HTTP request.
*/
-public class RequestHeader implements Header {
-
- private final String name, value;
- private final RestRequest request;
- private HttpPartParserSession parser;
- private HttpPartSchema schema;
+public class RequestHeader extends RequestHttpPart implements Header {
/**
* Constructor.
@@ -48,45 +39,7 @@ public class RequestHeader implements Header {
* @param value The header value.
*/
public RequestHeader(RestRequest request, String name, String value) {
- this.request = request;
- this.name = name;
- this.value = value;
- parser(null);
- }
-
-
//------------------------------------------------------------------------------------------------------------------
- // Setters
-
//------------------------------------------------------------------------------------------------------------------
-
- /**
- * Specifies the part schema for this header.
- *
- * <p>
- * Used by schema-based part parsers such as {@link OpenApiParser}.
- *
- * @param value
- * The part schema.
- * @return This object (for method chaining).
- */
- public RequestHeader schema(HttpPartSchema value) {
- this.schema = value;
- return this;
- }
-
- /**
- * Specifies the part parser to use for this header.
- *
- * <p>
- * If not specified, uses the part parser defined on the client by
calling {@link RestContextBuilder#partParser(Class)}.
- *
- * @param value
- * The new part parser to use for this header.
- * <br>If <jk>null</jk>, {@link SimplePartParser#DEFAULT} will be
used.
- * @return This object (for method chaining).
- */
- public RequestHeader parser(HttpPartParserSession value) {
- this.parser = value == null ? SimplePartParser.DEFAULT_SESSION
: value;
- return this;
+ super(HEADER, request, name, value);
}
//------------------------------------------------------------------------------------------------------------------
@@ -94,52 +47,6 @@ public class RequestHeader implements Header {
//------------------------------------------------------------------------------------------------------------------
/**
- * Returns <jk>true</jk> if this header exists on the request.
- *
- * <p>
- * This is a shortened form for calling <c>asString().isPresent()</c>.
- *
- * @return <jk>true</jk> if this header exists on the request.
- */
- public boolean isPresent() {
- return asString().isPresent();
- }
-
- /**
- * If a value is present, returns the value, otherwise throws {@link
NoSuchElementException}.
- *
- * <p>
- * This is a shortened form for calling <c>asString().get()</c>.
- *
- * @return The value if present.
- */
- public String get() {
- return asString().get();
- }
-
- /**
- * Return the value if present, otherwise return other.
- *
- * <p>
- * This is a shortened form for calling
<c>asString().orElse(<jv>other</jv>)</c>.
- *
- * @param other The value to be returned if there is no value present,
may be <jk>null</jk>.
- * @return The value, if present, otherwise other.
- */
- public String orElse(String other) {
- return asString().orElse(other);
- }
-
- /**
- * Returns the value of this header as a string.
- *
- * @return The value of this header as a string, or {@link
Optional#empty()} if the header was not present.
- */
- public Optional<String> asString() {
- return asStringHeader().asString();
- }
-
- /**
* 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.
@@ -296,114 +203,6 @@ public class RequestHeader implements Header {
return new BasicUriHeader(getName(), getValue());
}
- /**
- * Converts this header to the specified POJO type using the request
{@link HttpPartParser} and optional schema.
- *
- * @param <T> The type to convert to.
- * @param type The type to convert to.
- * @param args The type parameters.
- * @return The converted type, or {@link Optional#empty()} if the
header is not present.
- * @throws HttpException If value could not be parsed.
- */
- public <T> Optional<T> asType(Type type, Type...args) throws
HttpException {
- return asType(request.getBeanSession().getClassMeta(type,
args));
- }
-
- /**
- * Converts this header to the specified POJO type using the request
{@link HttpPartParser} and optional schema.
- *
- * @param <T> The type to convert to.
- * @param type The type to convert to.
- * @return The converted type, or {@link Optional#empty()} if the
header is not present.
- * @throws HttpException If value could not be parsed.
- */
- public <T> Optional<T> asType(Class<T> type) throws HttpException {
- return asType(request.getBeanSession().getClassMeta(type));
- }
-
- /**
- * Converts this header to the specified POJO type using the request
{@link HttpPartParser} and optional schema.
- *
- * @param <T> The type to convert to.
- * @param type The type to convert to.
- * @return The converted type, or {@link Optional#empty()} if the
header is not present.
- * @throws HttpException If value could not be parsed.
- */
- public <T> Optional<T> asType(ClassMeta<T> type) throws HttpException {
- try {
- return Optional.ofNullable(parser.parse(HEADER, schema,
orElse(null), type));
- } catch (ParseException e) {
- throw new BadRequest(e, "Could not parse header
''{0}''.", getName());
- }
- }
-
- /**
- * Matches the specified pattern against this header value.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * Matcher <jv>matcher</jv> = <jv>request</jv>
- * .getRequestHeader(<js>"Content-Type"</js>)
- *
.asMatcher(Pattern.<jsm>compile</jsm>(<js>"application/(.*)"</js>));
- *
- * <jk>if</jk> (<jv>matcher</jv>.matches()) {
- * String <jv>mediaType</jv> = <jv>matcher</jv>.group(1);
- * }
- * </p>
- *
- * @param pattern The regular expression pattern to match.
- * @return The matcher.
- * @throws HttpException If a connection error occurred.
- */
- public Matcher asMatcher(Pattern pattern) throws HttpException {
- return pattern.matcher(orElse(""));
- }
-
- /**
- * Matches the specified pattern against this header value.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * Matcher <jv>matcher</jv> = <jv>request</jv>
- * .getRequestHeader(<js>"Content-Type"</js>)
- * .asMatcher(<js>"application/(.*)"</js>);
- *
- * <jk>if</jk> (<jv>matcher</jv>.matches()) {
- * String <jv>mediaType</jv> = <jv>matcher</jv>.group(1);
- * }
- * </p>
- *
- * @param regex The regular expression pattern to match.
- * @return The matcher.
- * @throws HttpException If a connection error occurred.
- */
- public Matcher asMatcher(String regex) throws HttpException {
- return asMatcher(regex, 0);
- }
-
- /**
- * Matches the specified pattern against this header value.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * Matcher <jv>matcher</jv> = <jv>request</jv>
- * .getRequestHeader(<js>"Content-Type"</js>)
- * .asMatcher(<js>"application/(.*)"</js>,
<jsf>CASE_INSENSITIVE</jsf>);
- *
- * <jk>if</jk> (<jv>matcher</jv>.matches()) {
- * String <jv>mediaType</jv> = <jv>matcher</jv>.group(1);
- * }
- * </p>
- *
- * @param regex The regular expression pattern to match.
- * @param flags Pattern match flags. See {@link
Pattern#compile(String, int)}.
- * @return The matcher.
- * @throws HttpException If a connection error occurred.
- */
- public Matcher asMatcher(String regex, int flags) throws HttpException {
- return asMatcher(Pattern.compile(regex, flags));
- }
-
//------------------------------------------------------------------------------------------------------------------
// Assertions.
//------------------------------------------------------------------------------------------------------------------
@@ -429,26 +228,6 @@ public class RequestHeader implements Header {
//------------------------------------------------------------------------------------------------------------------
/**
- * Gets the name of this header.
- *
- * @return The name of this header, never <jk>null</jk>.
- */
- @Override /* Header */
- public String getName() {
- return name;
- }
-
- /**
- * Gets the value of this header.
- *
- * @return The value of this header, may be <jk>null</jk>.
- */
- @Override /* Header */
- public String getValue() {
- return value;
- }
-
- /**
* Parses the value.
*
* @return An array of {@link HeaderElement} entries, may be empty, but
is never <jk>null</jk>.
@@ -463,4 +242,20 @@ public class RequestHeader implements Header {
public String toString() {
return getName() + ": " + getValue();
}
+
+ // <FluentSetters>
+
+ @Override /* GENERATED */
+ public RequestHeader schema(HttpPartSchema value) {
+ super.schema(value);
+ return this;
+ }
+
+ @Override /* GENERATED */
+ public RequestHeader parser(HttpPartParserSession value) {
+ super.parser(value);
+ return this;
+ }
+
+ // </FluentSetters>
}
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
new file mode 100644
index 0000000..22628f5
--- /dev/null
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestHttpPart.java
@@ -0,0 +1,272 @@
+//
***************************************************************************************************************************
+// * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file *
+// * distributed with this work for additional information regarding copyright
ownership. The ASF licenses this file *
+// * to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance *
+// * with the License. You may obtain a copy of the License at
*
+// *
*
+// * http://www.apache.org/licenses/LICENSE-2.0
*
+// *
*
+// * Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an *
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the *
+// * specific language governing permissions and limitations under the
License. *
+//
***************************************************************************************************************************
+package org.apache.juneau.rest;
+
+import static org.apache.juneau.httppart.HttpPartType.*;
+import java.lang.reflect.*;
+import java.util.*;
+import java.util.regex.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.http.exception.*;
+import org.apache.juneau.http.exception.HttpException;
+import org.apache.juneau.httppart.*;
+import org.apache.juneau.internal.*;
+import org.apache.juneau.oapi.*;
+import org.apache.juneau.parser.ParseException;
+
+/**
+ * Represents a single HTTP part on an HTTP request.
+ */
+public class RequestHttpPart {
+
+ private final HttpPartType partType;
+ private final String name, value;
+ private final RestRequest request;
+ private HttpPartParserSession parser;
+ private HttpPartSchema schema;
+
+ /**
+ * Constructor.
+ *
+ * @param partType The HTTP part type.
+ * @param request The request object.
+ * @param name The header name.
+ * @param value The header value.
+ */
+ public RequestHttpPart(HttpPartType partType, RestRequest request,
String name, String value) {
+ this.partType = partType;
+ this.request = request;
+ this.name = name;
+ this.value = value;
+ parser(null);
+ }
+
+
//------------------------------------------------------------------------------------------------------------------
+ // Setters
+
//------------------------------------------------------------------------------------------------------------------
+
+ /**
+ * Specifies the part schema for this part.
+ *
+ * <p>
+ * Used by schema-based part parsers such as {@link OpenApiParser}.
+ *
+ * @param value
+ * The part schema.
+ * @return This object (for method chaining).
+ */
+ @FluentSetter
+ public RequestHttpPart schema(HttpPartSchema value) {
+ this.schema = value;
+ return this;
+ }
+
+ /**
+ * Specifies the part parser to use for this part.
+ *
+ * <p>
+ * If not specified, uses the part parser defined on the client by
calling {@link RestContextBuilder#partParser(Class)}.
+ *
+ * @param value
+ * The new part parser to use for this part.
+ * <br>If <jk>null</jk>, {@link SimplePartParser#DEFAULT} will be
used.
+ * @return This object (for method chaining).
+ */
+ @FluentSetter
+ public RequestHttpPart parser(HttpPartParserSession value) {
+ this.parser = value == null ? SimplePartParser.DEFAULT_SESSION
: value;
+ return this;
+ }
+
+
//------------------------------------------------------------------------------------------------------------------
+ // Retrievers
+
//------------------------------------------------------------------------------------------------------------------
+
+ /**
+ * Returns <jk>true</jk> if this part exists on the request.
+ *
+ * <p>
+ * This is a shortened form for calling <c>asString().isPresent()</c>.
+ *
+ * @return <jk>true</jk> if this part exists on the request.
+ */
+ public boolean isPresent() {
+ return asString().isPresent();
+ }
+
+ /**
+ * If a value is present, returns the value, otherwise throws {@link
NoSuchElementException}.
+ *
+ * <p>
+ * This is a shortened form for calling <c>asString().get()</c>.
+ *
+ * @return The value if present.
+ */
+ public String get() {
+ return asString().get();
+ }
+
+ /**
+ * Return the value if present, otherwise return other.
+ *
+ * <p>
+ * This is a shortened form for calling
<c>asString().orElse(<jv>other</jv>)</c>.
+ *
+ * @param other The value to be returned if there is no value present,
may be <jk>null</jk>.
+ * @return The value, if present, otherwise other.
+ */
+ public String orElse(String other) {
+ return asString().orElse(other);
+ }
+
+ /**
+ * 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.
+ */
+ public Optional<String> asString() {
+ return Optional.ofNullable(value);
+ }
+
+ /**
+ * Converts this part to the specified POJO type using the request
{@link HttpPartParser} and optional schema.
+ *
+ * @param <T> The type to convert to.
+ * @param type The type to convert to.
+ * @param args The type parameters.
+ * @return The converted type, or {@link Optional#empty()} if the part
is not present.
+ * @throws HttpException If value could not be parsed.
+ */
+ public <T> Optional<T> asType(Type type, Type...args) throws
HttpException {
+ return asType(request.getBeanSession().getClassMeta(type,
args));
+ }
+
+ /**
+ * Converts this part to the specified POJO type using the request
{@link HttpPartParser} and optional schema.
+ *
+ * @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 HttpException If value could not be parsed.
+ */
+ public <T> Optional<T> asType(Class<T> type) throws HttpException {
+ return asType(request.getBeanSession().getClassMeta(type));
+ }
+
+ /**
+ * Converts this part to the specified POJO type using the request
{@link HttpPartParser} and optional schema.
+ *
+ * @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 HttpException If value could not be parsed.
+ */
+ public <T> Optional<T> asType(ClassMeta<T> type) throws HttpException {
+ try {
+ 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());
+ }
+ }
+
+ /**
+ * Matches the specified pattern against this part value.
+ *
+ * <h5 class='section'>Example:</h5>
+ * <p class='bcode w800'>
+ * Matcher <jv>matcher</jv> = <jv>request</jv>
+ * .getRequestHeader(<js>"Content-Type"</js>)
+ *
.asMatcher(Pattern.<jsm>compile</jsm>(<js>"application/(.*)"</js>));
+ *
+ * <jk>if</jk> (<jv>matcher</jv>.matches()) {
+ * String <jv>mediaType</jv> = <jv>matcher</jv>.group(1);
+ * }
+ * </p>
+ *
+ * @param pattern The regular expression pattern to match.
+ * @return The matcher.
+ * @throws HttpException If a connection error occurred.
+ */
+ public Matcher asMatcher(Pattern pattern) throws HttpException {
+ return pattern.matcher(orElse(""));
+ }
+
+ /**
+ * Matches the specified pattern against this part value.
+ *
+ * <h5 class='section'>Example:</h5>
+ * <p class='bcode w800'>
+ * Matcher <jv>matcher</jv> = <jv>request</jv>
+ * .getRequestHeader(<js>"Content-Type"</js>)
+ * .asMatcher(<js>"application/(.*)"</js>);
+ *
+ * <jk>if</jk> (<jv>matcher</jv>.matches()) {
+ * String <jv>mediaType</jv> = <jv>matcher</jv>.group(1);
+ * }
+ * </p>
+ *
+ * @param regex The regular expression pattern to match.
+ * @return The matcher.
+ * @throws HttpException If a connection error occurred.
+ */
+ public Matcher asMatcher(String regex) throws HttpException {
+ return asMatcher(regex, 0);
+ }
+
+ /**
+ * Matches the specified pattern against this part value.
+ *
+ * <h5 class='section'>Example:</h5>
+ * <p class='bcode w800'>
+ * Matcher <jv>matcher</jv> = <jv>request</jv>
+ * .getRequestHeader(<js>"Content-Type"</js>)
+ * .asMatcher(<js>"application/(.*)"</js>,
<jsf>CASE_INSENSITIVE</jsf>);
+ *
+ * <jk>if</jk> (<jv>matcher</jv>.matches()) {
+ * String <jv>mediaType</jv> = <jv>matcher</jv>.group(1);
+ * }
+ * </p>
+ *
+ * @param regex The regular expression pattern to match.
+ * @param flags Pattern match flags. See {@link
Pattern#compile(String, int)}.
+ * @return The matcher.
+ * @throws HttpException If a connection error occurred.
+ */
+ public Matcher asMatcher(String regex, int flags) throws HttpException {
+ return asMatcher(Pattern.compile(regex, flags));
+ }
+
+ /**
+ * Gets the name of this part.
+ *
+ * @return The name of this part, never <jk>null</jk>.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Gets the value of this part.
+ *
+ * @return The value of this part, may be <jk>null</jk>.
+ */
+ public String getValue() {
+ return value;
+ }
+
+ @Override /* Object */
+ public String toString() {
+ return getName() + ": " + getValue();
+ }
+}
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 7a0fb13..f1dd624 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
@@ -13,32 +13,22 @@
package org.apache.juneau.rest;
import static org.apache.juneau.httppart.HttpPartType.*;
-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.assertions.*;
import org.apache.juneau.http.*;
-import org.apache.juneau.http.exception.*;
-import org.apache.juneau.http.exception.HttpException;
import org.apache.juneau.http.pair.*;
import org.apache.juneau.httppart.*;
-import org.apache.juneau.oapi.*;
-import org.apache.juneau.parser.ParseException;
import org.apache.juneau.reflect.*;
/**
* Represents a single query parameter on an HTTP request.
*/
-public class RequestQueryParam implements NameValuePair {
-
- private final String name, value;
- private final RestRequest request;
- private HttpPartParserSession parser;
- private HttpPartSchema schema;
+public class RequestQueryParam extends RequestHttpPart implements
NameValuePair {
/**
* Constructor.
@@ -48,45 +38,7 @@ public class RequestQueryParam implements NameValuePair {
* @param value The parameter value.
*/
public RequestQueryParam(RestRequest request, String name, String
value) {
- this.request = request;
- this.name = name;
- this.value = value;
- parser(null);
- }
-
-
//------------------------------------------------------------------------------------------------------------------
- // Setters
-
//------------------------------------------------------------------------------------------------------------------
-
- /**
- * Specifies the part schema for this parameter.
- *
- * <p>
- * Used by schema-based part parsers such as {@link OpenApiParser}.
- *
- * @param value
- * The part schema.
- * @return This object (for method chaining).
- */
- public RequestQueryParam schema(HttpPartSchema value) {
- this.schema = value;
- return this;
- }
-
- /**
- * Specifies the part parser to use for this parameter.
- *
- * <p>
- * If not specified, uses the part parser defined on the client by
calling {@link RestContextBuilder#partParser(Class)}.
- *
- * @param value
- * The new part parser to use for this parameter.
- * <br>If <jk>null</jk>, {@link SimplePartParser#DEFAULT} will be
used.
- * @return This object (for method chaining).
- */
- public RequestQueryParam parser(HttpPartParserSession value) {
- this.parser = value == null ? SimplePartParser.DEFAULT_SESSION
: value;
- return this;
+ super(QUERY, request, name, value);
}
//------------------------------------------------------------------------------------------------------------------
@@ -94,52 +46,6 @@ public class RequestQueryParam implements NameValuePair {
//------------------------------------------------------------------------------------------------------------------
/**
- * Returns <jk>true</jk> if this parameter exists on the request.
- *
- * <p>
- * This is a shortened form for calling <c>asString().isPresent()</c>.
- *
- * @return <jk>true</jk> if this parameter exists on the request.
- */
- public boolean isPresent() {
- return value != null;
- }
-
- /**
- * If a value is present, returns the value, otherwise throws {@link
NoSuchElementException}.
- *
- * <p>
- * This is a shortened form for calling <c>asString().get()</c>.
- *
- * @return The value if present.
- */
- public String get() {
- return asString().get();
- }
-
- /**
- * Return the value if present, otherwise return other.
- *
- * <p>
- * This is a shortened form for calling
<c>asString().orElse(<jv>other</jv>)</c>.
- *
- * @param other The value to be returned if there is no value present,
may be <jk>null</jk>.
- * @return The value, if present, otherwise other.
- */
- public String orElse(String other) {
- return asString().orElse(other);
- }
-
- /**
- * Returns the value of this parameter as a string.
- *
- * @return The value of this parameter as a string, or {@link
Optional#empty()} if the parameter was not present.
- */
- public Optional<String> asString() {
- return asNamedString().asString();
- }
-
- /**
* 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.
@@ -269,117 +175,6 @@ public class RequestQueryParam implements NameValuePair {
return new BasicNamedUri(getName(), getValue());
}
- /**
- * Converts this parameter to the specified POJO type using the request
{@link HttpPartParser} and optional schema.
- *
- * @param <T> The type to convert to.
- * @param type The type to convert to.
- * @param args The type parameters.
- * @return The converted type, or {@link Optional#empty()} if the
parameter is not present.
- * @throws HttpException If value could not be parsed.
- */
- public <T> Optional<T> asType(Type type, Type...args) throws
HttpException {
- return asType(request.getBeanSession().getClassMeta(type,
args));
- }
-
- /**
- * Converts this parameter to the specified POJO type using the request
{@link HttpPartParser} and optional schema.
- *
- * @param <T> The type to convert to.
- * @param type The type to convert to.
- * @return The converted type, or {@link Optional#empty()} if the
parameter is not present.
- * @throws HttpException If value could not be parsed.
- */
- public <T> Optional<T> asType(Class<T> type) throws HttpException {
- return asType(request.getBeanSession().getClassMeta(type));
- }
-
- /**
- * Converts this parameter to the specified POJO type using the request
{@link HttpPartParser} and optional schema.
- *
- * @param <T> The type to convert to.
- * @param type The type to convert to.
- * @return The converted type, or {@link Optional#empty()} if the
parameter is not present.
- * @throws HttpException If value could not be parsed.
- */
- public <T> Optional<T> asType(ClassMeta<T> type) throws HttpException {
- try {
- return Optional.ofNullable(parser.parse(HEADER, schema,
orElse(null), type));
- } catch (ParseException e) {
- throw new BadRequest(e, "Could not parse query
parameter ''{0}''.", getName());
- }
- }
-
- /**
- * Matches the specified pattern against this parameter value.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Parse parameter using a regular expression.</jc>
- * Matcher <jv>matcher</jv> = <jv>request</jv>
- * .getQueryParam(<js>"foo"</js>)
- *
.asMatcher(Pattern.<jsm>compile</jsm>(<js>"foo/(.*)"</js>));
- *
- * <jk>if</jk> (<jv>matcher</jv>.matches()) {
- * String <jv>bar</jv> = <jv>matcher</jv>.group(1);
- * }
- * </p>
- *
- * @param pattern The regular expression pattern to match.
- * @return The matcher.
- * @throws HttpException If a connection error occurred.
- */
- public Matcher asMatcher(Pattern pattern) throws HttpException {
- return pattern.matcher(orElse(""));
- }
-
- /**
- * Matches the specified pattern against this parameter value.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Parse parameter using a regular expression.</jc>
- * Matcher <jv>matcher</jv> = <jv>request</jv>
- * .getQueryParam(<js>"foo"</js>)
- * .asMatcher(<js>"foo/(.*)"</js>);
- *
- * <jk>if</jk> (<jv>matcher</jv>.matches()) {
- * String <jv>bar</jv> = <jv>matcher</jv>.group(1);
- * }
- * </p>
- *
- * @param regex The regular expression pattern to match.
- * @return The matcher.
- * @throws HttpException If a connection error occurred.
- */
- public Matcher asMatcher(String regex) throws HttpException {
- return asMatcher(regex, 0);
- }
-
- /**
- * Matches the specified pattern against this parameter value.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Parse parameter using a regular expression.</jc>
- * Matcher <jv>matcher</jv> = <jv>request</jv>
- * .getQueryParam(<js>"foo"</js>)
- * .asMatcher(<js>"foo/(.*)"</js>,
<jsf>CASE_INSENSITIVE</jsf>);
- *
- * <jk>if</jk> (<jv>matcher</jv>.matches()) {
- * String <jv>bar</jv> = <jv>matcher</jv>.group(1);
- * }
- * </p>
- *
- * @param regex The regular expression pattern to match.
- * @param flags Pattern match flags. See {@link
Pattern#compile(String, int)}.
- * @return The matcher.
- * @throws HttpException If a connection error occurred.
- */
- public Matcher asMatcher(String regex, int flags) throws HttpException {
- return asMatcher(Pattern.compile(regex, flags));
- }
-
//------------------------------------------------------------------------------------------------------------------
// Assertions.
//------------------------------------------------------------------------------------------------------------------
@@ -477,32 +272,24 @@ public class RequestQueryParam implements NameValuePair {
// Header passthrough methods.
//------------------------------------------------------------------------------------------------------------------
- /**
- * Gets the name of this pair.
- *
- * @return The name of this pair, never <jk>null</jk>.
- */
- @Override /* Header */
- public String getName() {
- return name;
+ @Override /* Object */
+ public String toString() {
+ return getName() + "=" + getValue();
}
- /**
- * Gets the value of this pair.
- *
- * <ul class='notes'>
- * <li>{@link #asString()} is an equivalent method and the
preferred method for fluent-style coding.
- * </ul>
- *
- * @return The value of this pair, may be <jk>null</jk>.
- */
- @Override /* Header */
- public String getValue() {
- return value;
+ // <FluentSetters>
+
+ @Override /* GENERATED */
+ public RequestQueryParam schema(HttpPartSchema value) {
+ super.schema(value);
+ return this;
}
- @Override /* Object */
- public String toString() {
- return getName() + "=" + getValue();
+ @Override /* GENERATED */
+ public RequestQueryParam parser(HttpPartParserSession value) {
+ super.parser(value);
+ return this;
}
+
+ // </FluentSetters>
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/Rest_PredefinedStatusCodes_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/Rest_PredefinedStatusCodes_Test.java
index 3cdec3f..b4144a7 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/Rest_PredefinedStatusCodes_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/Rest_PredefinedStatusCodes_Test.java
@@ -171,7 +171,7 @@ public class Rest_PredefinedStatusCodes_Test {
.run()
.assertCode().is(400)
.assertBody().contains(
- "Could not parse header 'h1'."
+ "Could not parse header parameter 'h1'."
);
}