![JAR search and dependency download from the Maven repository](/logo.png)
org.apache.juneau.rest.httppart.RequestAttribute Maven / Gradle / Ivy
// ***************************************************************************************************************************
// * 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.httppart;
import static org.apache.juneau.common.internal.StringUtils.*;
import static org.apache.juneau.internal.CollectionUtils.*;
import java.util.*;
import org.apache.juneau.http.response.*;
import org.apache.juneau.rest.*;
/**
* Represents a single request attribute on an HTTP request.
*
*
* Typically accessed through the {@link RequestAttributes} class.
*
*
* Some important methods on this class are:
*
*
* - {@link RequestAttribute}
*
* - Methods for retrieving simple string values:
*
* - {@link RequestAttribute#asString() asString()}
*
- {@link RequestAttribute#get() get()}
*
- {@link RequestAttribute#isPresent() isPresent()}
*
- {@link RequestAttribute#orElse(Object) orElse(Object)}
*
* - Methods for retrieving as custom types:
*
* - {@link RequestAttribute#as(Class) as(Class)}
*
* - Methods for performing assertion checks:
*
* - {@link RequestAttribute#assertName() assertName()}
*
- {@link RequestAttribute#assertValue() assertValue()}
*
* - Other methods:
*
* - {@link RequestAttribute#getName() getName()}
*
- {@link RequestAttribute#getValue() getValue()}
*
*
*
* See Also:
* - HTTP Parts
*
*/
public class RequestAttribute extends BasicNamedAttribute {
private final RestRequest req;
/**
* Constructor.
*
* @param request The request object.
* @param name The parameter name.
* @param value The parameter value.
*/
public RequestAttribute(RestRequest request, String name, Object value) {
super(name, value);
this.req = request;
}
//------------------------------------------------------------------------------------------------------------------
// Retrievers
//------------------------------------------------------------------------------------------------------------------
/**
* 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 asString() {
return optional(stringify(getValue()));
}
/**
* Converts this part to the specified POJO.
*
* @param 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 Optional as(Class type) {
return optional(req.getBeanSession().convertToType(getValue(), type));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy