Package org.apache.sling.api.request

# Class RequestUtil

java.lang.Object
org.apache.sling.api.request.RequestUtil

public class RequestUtil extends Object
Request related utility methods.

This class is not intended to be extended or instantiated because it just provides static utility methods not intended to be overwritten.

Since:
  2.1 (Sling API Bundle 2.1.0)

## Constructor Summary

Constructors
Constructor
Description
`RequestUtil()`

## Method Summary

Modifier and Type
Method
Description
`static @NotNull String`
`getServletName(@NotNull jakarta.servlet.Servlet servlet)`
Utility method to return a name for the given servlet.
`static @NotNull String`
`getServletName(javax.servlet.Servlet servlet)`
Deprecated.
Use `getServletName(Servlet)`
`static boolean`
`handleIfModifiedSince(@NotNull SlingJakartaHttpServletRequest req, @NotNull jakarta.servlet.http.HttpServletResponse resp)`
Checks if the request contains a if-last-modified-since header and if the the request's underlying resource has a jcr:lastModified property.
`static boolean`
`handleIfModifiedSince(SlingHttpServletRequest req, javax.servlet.http.HttpServletResponse resp)`
Deprecated.
Use `handleIfModifiedSince(SlingJakartaHttpServletRequest, HttpServletResponse)` instead.
`static @NotNull Map<String,Double>`
`parserAcceptHeader(@NotNull String value)`
Parses an `Accept-*` header of the form:
`static @NotNull Map<String,Map<String,String>>`
`parserHeader(@NotNull String value)`
Parses a header of the form:
`static @Nullable Object`
`setRequestAttribute(@NotNull jakarta.servlet.http.HttpServletRequest request, @NotNull String name, Object value)`
Sets the named request attribute to the new value and returns the previous value.
`static @Nullable Object`
`setRequestAttribute(javax.servlet.http.HttpServletRequest request, @NotNull String name, Object value)`
Deprecated.
Use `setRequestAttribute(HttpServletRequest, String, Object)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### RequestUtil

public RequestUtil()

## Method Details

### parserHeader

@NotNull public static @NotNull Map<String,Map<String,String>> parserHeader(@NotNull @NotNull String value)
Parses a header of the form:

                Header = Token { "," Token } .
                Token = name { ";" Parameter } .
                Parameter = name [ "=" value ] .

"," and ";" are not allowed within name and value

Parameters:
  `value` - The header value
Returns:
  A Map indexed by the Token names where the values are Map instances indexed by parameter name

### parserAcceptHeader

@NotNull public static @NotNull Map<String,Double> parserAcceptHeader(@NotNull @NotNull String value)
Parses an `Accept-*` header of the form:

                Header = Token { "," Token } .
                Token = name { ";" "q" [ "=" value ] } .
                Parameter =  .

"," and ";" are not allowed within name and value

Parameters:
  `value` - The header value
Returns:
  A Map indexed by the Token names where the values are `Double` instances providing the value of the `q` parameter.

### getServletName

@NotNull public static @NotNull String getServletName(@NotNull @NotNull jakarta.servlet.Servlet servlet)
Utility method to return a name for the given servlet. This method applies the following algorithm to find a non-`null`, non-empty name:

1. If the servlet has a servlet config, the servlet name from the servlet config is taken.
2. Otherwise check the servlet info
3. Otherwise use the fully qualified name of the servlet class

Parameters:
  `servlet` - The servlet
Returns:
  The name of the servlet.
Since:
  2.8.0

### getServletName

@Deprecated @NotNull public static @NotNull String getServletName(@NotNull javax.servlet.Servlet servlet)
Deprecated.
Use `getServletName(Servlet)`
Utility method to return a name for the given servlet. This method applies the following algorithm to find a non-`null`, non-empty name:

1. If the servlet has a servlet config, the servlet name from the servlet config is taken.
2. Otherwise check the servlet info
3. Otherwise use the fully qualified name of the servlet class

Parameters:
  `servlet` - The servlet
Returns:
  The name of the servlet.

### setRequestAttribute

@Nullable public static @Nullable Object setRequestAttribute(@NotNull @NotNull jakarta.servlet.http.HttpServletRequest request, @NotNull @NotNull String name, Object value)
Sets the named request attribute to the new value and returns the previous value.

Parameters:
  `request` - The request object whose attribute is to be set.
  `name` - The name of the attribute to be set.
  `value` - The new value of the attribute. If this is `null` the attribte is actually removed from the request.
Returns:
  The previous value of the named request attribute or `null` if it was not set.
Since:
  2.8.0

### setRequestAttribute

@Deprecated @Nullable public static @Nullable Object setRequestAttribute(@NotNull javax.servlet.http.HttpServletRequest request, @NotNull @NotNull String name, Object value)
Deprecated.
Use `setRequestAttribute(HttpServletRequest, String, Object)`
Sets the named request attribute to the new value and returns the previous value.

Parameters:
  `request` - The request object whose attribute is to be set.
  `name` - The name of the attribute to be set.
  `value` - The new value of the attribute. If this is `null` the attribte is actually removed from the request.
Returns:
  The previous value of the named request attribute or `null` if it was not set.

### handleIfModifiedSince

public static boolean handleIfModifiedSince(@NotNull @NotNull SlingJakartaHttpServletRequest req, @NotNull @NotNull jakarta.servlet.http.HttpServletResponse resp)
Checks if the request contains a if-last-modified-since header and if the the request's underlying resource has a jcr:lastModified property. if the properties were modified before the header a 304 is sent otherwise the response last modified header is set.

Parameters:
  `req` - the request
  `resp` - the response
Returns:
  `true` if the response was set
Since:
  2.8.0

### handleIfModifiedSince

@Deprecated public static boolean handleIfModifiedSince(@NotNull SlingHttpServletRequest req, @NotNull javax.servlet.http.HttpServletResponse resp)
Deprecated.
Use `handleIfModifiedSince(SlingJakartaHttpServletRequest, HttpServletResponse)` instead.
Checks if the request contains a if-last-modified-since header and if the the request's underlying resource has a jcr:lastModified property. if the properties were modified before the header a 304 is sent otherwise the response last modified header is set.

Parameters:
  `req` - the request
  `resp` - the response
Returns:
  `true` if the response was set