Package org.apache.sling.api.request.builder

# Interface SlingHttpServletRequestBuilder

@ProviderType public interface SlingHttpServletRequestBuilder

Fluent helper for building a request.

Note: instances of this interface are not thread-safe.

Since:
  1.0 (Sling API Bundle 2.24.0)

## Method Summary

Modifier and Type
Method
Description
`SlingHttpServletRequest`
`build()`
Deprecated.
Use `buildJakartaRequest()` instead
`@NotNull SlingJakartaHttpServletRequest`
`buildJakartaRequest()`
Builds the request.
`@NotNull SlingHttpServletRequestBuilder`
`useAttributesFrom(@NotNull jakarta.servlet.http.HttpServletRequest request)`
Uses the attributes backed by the provided request.
`@NotNull SlingHttpServletRequestBuilder`
`useAttributesFrom(javax.servlet.http.HttpServletRequest request)`
Deprecated.
Use `useAttributesFrom(HttpServletRequest)` instead
`@NotNull SlingHttpServletRequestBuilder`
`useRequestDispatcherFrom(SlingHttpServletRequest request)`
Deprecated.
Use `useRequestDispatcherFrom(SlingJakartaHttpServletRequest)` instead
`@NotNull SlingHttpServletRequestBuilder`
`useRequestDispatcherFrom(SlingJakartaHttpServletRequest request)`
Uses the request dispatcher from the provided request.
`@NotNull SlingHttpServletRequestBuilder`
`useServletContextFrom(@NotNull jakarta.servlet.http.HttpServletRequest request)`
Uses the servlet context from the provided request.
`@NotNull SlingHttpServletRequestBuilder`
`useServletContextFrom(javax.servlet.http.HttpServletRequest request)`
Deprecated.
Use `useServletContextFrom(HttpServletRequest)` instead
`@NotNull SlingHttpServletRequestBuilder`
`useSessionFrom(@NotNull jakarta.servlet.http.HttpServletRequest request)`
Uses the session from the provided request.
`@NotNull SlingHttpServletRequestBuilder`
`useSessionFrom(javax.servlet.http.HttpServletRequest request)`
Deprecated.
Use `useSessionFrom(HttpServletRequest)` instead
`@NotNull SlingHttpServletRequestBuilder`
`withBody(@Nullable String content)`
Uses the supplied content as the request's body content.
`@NotNull SlingHttpServletRequestBuilder`
`withContentType(@Nullable String contentType)`
Sets the HTTP request's `Content-Type` header.
`@NotNull SlingHttpServletRequestBuilder`
`withExtension(@Nullable String extension)`
Sets the optional extension of the internal request, which influences the servlet/script resolution.
`@NotNull SlingHttpServletRequestBuilder`
`withParameter(@NotNull String key, @NotNull String value)`
Sets a request parameter.
`@NotNull SlingHttpServletRequestBuilder`
`withParameter(@NotNull String key, @NotNull String[] values)`
Sets a request parameter.
`@NotNull SlingHttpServletRequestBuilder`
`withParameters(@Nullable Map<String,String[]> parameters)`
Adds the supplied request parameters to the current ones.
`@NotNull SlingHttpServletRequestBuilder`
`withRequestMethod(@NotNull String method)`
Sets the HTTP request method to use - defaults to `GET`.
`@NotNull SlingHttpServletRequestBuilder`
`withRequestProgressTracker(@NotNull RequestProgressTracker tracker)`
Uses the provided request progress tracker
`@NotNull SlingHttpServletRequestBuilder`
`withSelectors(@Nullable String... selectors)`
Sets the optional selectors of the internal request, which influence the servlet/script resolution.
`@NotNull SlingHttpServletRequestBuilder`
`withSuffix(@Nullable String suffix)`
Sets the optional suffix of the internal request.

## Method Details

### withRequestMethod

@NotNull @NotNull SlingHttpServletRequestBuilder withRequestMethod(@NotNull @NotNull String method)
Sets the HTTP request method to use - defaults to `GET`.

Parameters:
  `method` - the HTTP method
Returns:
  this object
Throws:
  `IllegalArgumentException` - If method is `null`

### withContentType

@NotNull @NotNull SlingHttpServletRequestBuilder withContentType(@Nullable @Nullable String contentType)
Sets the HTTP request's `Content-Type` header.

Parameters:
  `contentType` - the `Content-Type` value
Returns:
  this object

### withBody

@NotNull @NotNull SlingHttpServletRequestBuilder withBody(@Nullable @Nullable String content)
Uses the supplied content as the request's body content.

Parameters:
  `content` - the request body content
Returns:
  this object

### withSelectors

@NotNull @NotNull SlingHttpServletRequestBuilder withSelectors(@Nullable @Nullable String... selectors)
Sets the optional selectors of the internal request, which influence the servlet/script resolution.

Parameters:
  `selectors` - the selectors
Returns:
  this object

### withExtension

@NotNull @NotNull SlingHttpServletRequestBuilder withExtension(@Nullable @Nullable String extension)
Sets the optional extension of the internal request, which influences the servlet/script resolution.

Parameters:
  `extension` - the extension
Returns:
  this object

### withSuffix

@NotNull @NotNull SlingHttpServletRequestBuilder withSuffix(@Nullable @Nullable String suffix)
Sets the optional suffix of the internal request.

Parameters:
  `suffix` - the suffix
Returns:
  this object

### withParameter

@NotNull @NotNull SlingHttpServletRequestBuilder withParameter(@NotNull @NotNull String key, @NotNull @NotNull String value)
Sets a request parameter.

Parameters:
  `key` - the name of the parameter
  `value` - the value of the parameter
Returns:
  this object
Throws:
  `IllegalArgumentException` - if either `key` or `value` is `null`

### withParameter

@NotNull @NotNull SlingHttpServletRequestBuilder withParameter(@NotNull @NotNull String key, @NotNull @NotNull String[] values)
Sets a request parameter.

Parameters:
  `key` - the name of the parameter
  `values` - the values of the parameter
Returns:
  this object
Throws:
  `IllegalArgumentException` - if either `key` or `values` is `null`

### withParameters

@NotNull @NotNull SlingHttpServletRequestBuilder withParameters(@Nullable @Nullable Map<String,String[]> parameters)
Adds the supplied request parameters to the current ones.

Parameters:
  `parameters` - additional parameters
Returns:
  this object

### useRequestDispatcherFrom

@Deprecated @NotNull @NotNull SlingHttpServletRequestBuilder useRequestDispatcherFrom(@NotNull SlingHttpServletRequest request)
Deprecated.
Use `useRequestDispatcherFrom(SlingJakartaHttpServletRequest)` instead
Uses the request dispatcher from the provided request.

Parameters:
  `request` - the request from which to use the dispatcher
Returns:
  this object
Throws:
  `IllegalArgumentException` - if `request` is `null`

### useRequestDispatcherFrom

@NotNull @NotNull SlingHttpServletRequestBuilder useRequestDispatcherFrom(@NotNull SlingJakartaHttpServletRequest request)
Uses the request dispatcher from the provided request.

Parameters:
  `request` - the request from which to use the dispatcher
Returns:
  this object
Throws:
  `IllegalArgumentException` - if `request` is `null`

### useSessionFrom

@Deprecated @NotNull @NotNull SlingHttpServletRequestBuilder useSessionFrom(@NotNull javax.servlet.http.HttpServletRequest request)
Deprecated.
Use `useSessionFrom(HttpServletRequest)` instead
Uses the session from the provided request.

Parameters:
  `request` - the request from which to use the session
Returns:
  this object
Throws:
  `IllegalArgumentException` - if `request` is `null`

### useAttributesFrom

@Deprecated @NotNull @NotNull SlingHttpServletRequestBuilder useAttributesFrom(@NotNull javax.servlet.http.HttpServletRequest request)
Deprecated.
Use `useAttributesFrom(HttpServletRequest)` instead
Uses the attributes backed by the provided request.

Parameters:
  `request` - the request from which to use the attributes
Returns:
  this object
Throws:
  `IllegalArgumentException` - if `request` is `null`

### useServletContextFrom

@Deprecated @NotNull @NotNull SlingHttpServletRequestBuilder useServletContextFrom(@NotNull javax.servlet.http.HttpServletRequest request)
Deprecated.
Use `useServletContextFrom(HttpServletRequest)` instead
Uses the servlet context from the provided request.

Parameters:
  `request` - the request from which to use the servlet context
Returns:
  this object
Throws:
  `IllegalArgumentException` - if `request` is `null`

### useSessionFrom

@NotNull @NotNull SlingHttpServletRequestBuilder useSessionFrom(@NotNull @NotNull jakarta.servlet.http.HttpServletRequest request)
Uses the session from the provided request.

Parameters:
  `request` - the request from which to use the session
Returns:
  this object
Throws:
  `IllegalArgumentException` - if `request` is `null`

### useAttributesFrom

@NotNull @NotNull SlingHttpServletRequestBuilder useAttributesFrom(@NotNull @NotNull jakarta.servlet.http.HttpServletRequest request)
Uses the attributes backed by the provided request.

Parameters:
  `request` - the request from which to use the attributes
Returns:
  this object
Throws:
  `IllegalArgumentException` - if `request` is `null`

### useServletContextFrom

@NotNull @NotNull SlingHttpServletRequestBuilder useServletContextFrom(@NotNull @NotNull jakarta.servlet.http.HttpServletRequest request)
Uses the servlet context from the provided request.

Parameters:
  `request` - the request from which to use the servlet context
Returns:
  this object
Throws:
  `IllegalArgumentException` - if `request` is `null`

### withRequestProgressTracker

@NotNull @NotNull SlingHttpServletRequestBuilder withRequestProgressTracker(@NotNull @NotNull RequestProgressTracker tracker)
Uses the provided request progress tracker

Parameters:
  `tracker` - The tracker
Returns:
  this object
Since:
  1.1 (Sling API Bundle 2.25.0)

### buildJakartaRequest

@NotNull @NotNull SlingJakartaHttpServletRequest buildJakartaRequest()
Builds the request. Once this method has been called, the builder must not be used anymore. In order to create a new request a new builder has to be used.

Returns:
  a request object
Since:
  1.4

### build

@Deprecated @NotNull SlingHttpServletRequest build()
Deprecated.
Use `buildJakartaRequest()` instead
Builds the request. Once this method has been called, the builder must not be used anymore. In order to create a new request a new builder has to be used.

Returns:
  a request object