|
aerogear-controller 1.0.2 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jboss.aerogear.controller.util.RequestUtils
public class RequestUtils
Utility methods for various HttpServletRequest operation.
| Field Summary | |
|---|---|
private static Pattern |
ACCEPT_HEADER_PATTERN
|
private static String |
MEDIA_RANGE
|
private static Pattern |
PATH_PATTERN
|
private static Pattern |
PATH_PLACEHOLDER_PATTERN
|
private static Pattern |
PATH_SEGMENT_PATTERN
|
private static Pattern |
PLACEHOLDER_PATTERN
|
| Constructor Summary | |
|---|---|
private |
RequestUtils()
|
| Method Summary | |
|---|---|
static boolean |
acceptsMediaType(Set<String> acceptHeaders,
Set<MediaType> produces)
Determines if a request's 'Accept' header media types are compatible with the media types that a route produces. |
static Set<String> |
extractAcceptHeader(javax.servlet.http.HttpServletRequest request)
Returns the Accept header from the passed-in HttpServletRequest. |
static RequestMethod |
extractMethod(javax.servlet.http.HttpServletRequest httpServletRequest)
Returns the RequestMethod for the passed-in HttpServletRequest. |
static String |
extractPath(javax.servlet.http.HttpServletRequest request)
Returns the path of the current request with out the context path. |
static Map<Integer,String> |
extractPathSegments(String path)
Extracts the path elements and returns a map indexed by the order in which the path elements appear. |
static Map<String,Integer> |
extractPathVariableNames(String path)
Extracts path parameter placeholders from the passed in path. |
static Set<String> |
extractPlaceHolders(String str)
Will extract any placeholders, {name}, from the passed-in string. |
static com.google.common.base.Optional<MediaType> |
getAcceptedMediaType(Set<String> acceptHeaders,
Set<MediaType> produces)
Gets the media type that is compatible with the requested media type and the media types that a route produces. |
static String |
injectParamValues(String str,
Map<String,Object> map)
Injects/replaces the placeholders in the passed-in string with the corresponding values from the passed-in map. |
static Map<String,String> |
mapPathParams(String requestPath,
String configPath)
Extracts path parameters from the passed-in request path. |
static List<String> |
pathSegements(String path)
Returns a List of segments for the passed-in path. |
static boolean |
segmentsMatch(String placeHolderPath,
String realPath)
Determines whether to paths match in terms of having the same number of segments and the same segment names. |
private static String |
trimPlaceHolder(String str)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final Pattern PATH_SEGMENT_PATTERN
private static final Pattern PATH_PLACEHOLDER_PATTERN
private static final Pattern PLACEHOLDER_PATTERN
private static final Pattern PATH_PATTERN
private static final String MEDIA_RANGE
private static final Pattern ACCEPT_HEADER_PATTERN
| Constructor Detail |
|---|
private RequestUtils()
| Method Detail |
|---|
public static String extractPath(javax.servlet.http.HttpServletRequest request)
request - the HttpServletRequest.
String the request path without the context path (suffix)public static RequestMethod extractMethod(javax.servlet.http.HttpServletRequest httpServletRequest)
RequestMethod for the passed-in HttpServletRequest.
httpServletRequest - the HttpServletRequest
RequestMethod matching the Http Method of the request.public static Set<String> extractAcceptHeader(javax.servlet.http.HttpServletRequest request)
Accept header from the passed-in HttpServletRequest.
request - the HttpServletRequest
Set<String> of the values of the Http Accept Header, or an empty list if there was not Accept headerpublic static Map<Integer,String> extractPathSegments(String path)
path - the path from which the path elements will be extracted/collected.
Map<Integer, String indexed by the position of the path elements.public static Map<String,Integer> extractPathVariableNames(String path)
path - the path from which the path elements will be extracted/collected.
Map<String, Integer indexed name of the placeholder/variable name, and the value is the position
of this name in the path.private static String trimPlaceHolder(String str)
public static Map<String,String> mapPathParams(String requestPath,
String configPath)
requestPath - the actual request path.configPath - the configuration time path. This path can contain path variable placeholders which will
be mapped to the corresponding request path values.
Map<String, String> index by the name of the parameter, and the value is the value of the corresponding
request path parameter.
public static boolean acceptsMediaType(Set<String> acceptHeaders,
Set<MediaType> produces)
acceptHeaders - the 'Accept' header media types for the current request.produces - the MediaTypes that the route is capable of producing.
true if the one of the accept media types are compatible with on of the media types.
public static com.google.common.base.Optional<MediaType> getAcceptedMediaType(Set<String> acceptHeaders,
Set<MediaType> produces)
acceptHeaders - the 'Accept' header media types for the current request.produces - the MediaTypes that the route is capable of producing.
Optional<MediaType an Optional instance of the MediaType accepted.public static Set<String> extractPlaceHolders(String str)
str - the string from with placeholder names should be extracted.
Set containing the placeholder names.
public static String injectParamValues(String str,
Map<String,Object> map)
str - the string containing placeholders that are to be replaced by values in the mapmap - the map containing the mapping of param name to param value.
String the string with the placesholders replaced by the values.
public static boolean segmentsMatch(String placeHolderPath,
String realPath)
placeHolderPath - path that may contain placeholders.realPath - the actual path of the request.
true if the number of segments match and the segments names match.public static List<String> pathSegements(String path)
path - which can include placeholders which will be included as-is, for example {placeholderName}
List<String> containing the segments of the path.
|
aerogear-controller 1.0.2 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||