Package org.apache.sling.servlethelpers.internalrequests

# Class InternalRequest

java.lang.Object
org.apache.sling.servlethelpers.internalrequests.BaseInternalRequest
org.apache.sling.servlethelpers.internalrequests.InternalRequest

Direct Known Subclasses:
  `ServletInternalRequest`, `SlingInternalRequest`

@Deprecated(since="2.0.0") public abstract class InternalRequest extends BaseInternalRequest
Deprecated.
Use `JakartaInternalRequest` instead.
Fluent helper for Sling internal requests. The `ServletInternalRequest` and `SlingInternalRequest` subclasses provide two modes for executing the internal requests, one that's very similar to the way Sling executes an HTTP request and another one that's faster by calling Servlets or Scripts directly.

## Field Summary

### Fields inherited from class org.apache.sling.servlethelpers.internalrequests.BaseInternalRequest

`bodyReader, contentType, DEFAULT_METHOD, explicitStatusCheck, extension, log, MDC_KEY, parameters, path, requestMethod, resourceResolver, selectorString`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`InternalRequest(@NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver, @NotNull String path)`
Deprecated.
Clients use subclasses of this one

## Method Summary

Modifier and Type
Method
Description
`protected void`
`assertRequestExecuted()`
Deprecated.
`InternalRequest`
`checkResponseContentType(String contentType)`
Deprecated.
After executing the request, checks that the response content-type is as expected.
`InternalRequest`
`checkStatus(int... acceptableValues)`
Deprecated.
After executing the request, checks that the request status is one of the supplied values.
`protected abstract void`
`delegateExecute(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response, org.apache.sling.api.resource.ResourceResolver resourceResolver)`
Deprecated.
Execute the supplied Request
`final InternalRequest`
`execute()`
Deprecated.
Execute the internal request.
`org.apache.sling.api.SlingHttpServletResponse`
`getResponse()`
Deprecated.
Return the response object.
`String`
`getResponseAsString()`
Deprecated.
Return the response as a String.
`int`
`getStatus()`
Deprecated.
Return the response status.
`InternalRequest`
`withBody(Reader bodyContent)`
Deprecated.
Use the supplied Reader as the request's body content
`InternalRequest`
`withContentType(String contentType)`
Deprecated.
Set the HTTP request's Content-Type
`InternalRequest`
`withExtension(String extension)`
Deprecated.
Sets the optional extension of the internal request, which influence the Servlet/Script resolution.
`InternalRequest`
`withParameter(String key, Object value)`
Deprecated.
Set a request parameter
`InternalRequest`
`withParameters(Map<String,Object> additionalParameters)`
Deprecated.
Add the supplied request parameters to the current ones
`InternalRequest`
`withRequestMethod(String method)`
Deprecated.
Set the HTTP request method to use - defaults to GET
`InternalRequest`
`withSelectors(String... selectors)`
Deprecated.
Sets the optional selectors of the internal request, which influence the Servlet/Script resolution.

### Methods inherited from class org.apache.sling.servlethelpers.internalrequests.BaseInternalRequest

`checkNotNull, checkNotNull, getExecutionResource`

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

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

## Constructor Details

### InternalRequest

protected InternalRequest(@NotNull @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver, @NotNull @NotNull String path)
Deprecated.
Clients use subclasses of this one

## Method Details

### withRequestMethod

public InternalRequest withRequestMethod(String method)
Deprecated.
Description copied from class: `BaseInternalRequest`
Set the HTTP request method to use - defaults to GET

Overrides:
  `withRequestMethod` in class `BaseInternalRequest`

### withContentType

public InternalRequest withContentType(String contentType)
Deprecated.
Description copied from class: `BaseInternalRequest`
Set the HTTP request's Content-Type

Overrides:
  `withContentType` in class `BaseInternalRequest`

### withBody

public InternalRequest withBody(Reader bodyContent)
Deprecated.
Description copied from class: `BaseInternalRequest`
Use the supplied Reader as the request's body content

Overrides:
  `withBody` in class `BaseInternalRequest`

### withSelectors

public InternalRequest withSelectors(String... selectors)
Deprecated.
Description copied from class: `BaseInternalRequest`
Sets the optional selectors of the internal request, which influence the Servlet/Script resolution.

Overrides:
  `withSelectors` in class `BaseInternalRequest`

### withExtension

public InternalRequest withExtension(String extension)
Deprecated.
Description copied from class: `BaseInternalRequest`
Sets the optional extension of the internal request, which influence the Servlet/Script resolution.

Overrides:
  `withExtension` in class `BaseInternalRequest`

### withParameter

public InternalRequest withParameter(String key, Object value)
Deprecated.
Description copied from class: `BaseInternalRequest`
Set a request parameter

Overrides:
  `withParameter` in class `BaseInternalRequest`

### withParameters

public InternalRequest withParameters(Map<String,Object> additionalParameters)
Deprecated.
Description copied from class: `BaseInternalRequest`
Add the supplied request parameters to the current ones

Overrides:
  `withParameters` in class `BaseInternalRequest`

### execute

public final InternalRequest execute() throws IOException
Deprecated.
Execute the internal request. Can be called right after creating it, if no options need to be set.

Specified by:
  `execute` in class `BaseInternalRequest`
Throws:
  `IOException` - if the request was already executed, or if an error occurs during execution.

### delegateExecute

protected abstract void delegateExecute(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response, org.apache.sling.api.resource.ResourceResolver resourceResolver) throws javax.servlet.ServletException, IOException
Deprecated.
Execute the supplied Request

Throws:
  `javax.servlet.ServletException`
  `IOException`

### assertRequestExecuted

protected void assertRequestExecuted() throws IOException
Deprecated.

Specified by:
  `assertRequestExecuted` in class `BaseInternalRequest`
Throws:
  `IOException`

### checkStatus

public InternalRequest checkStatus(int... acceptableValues) throws IOException
Deprecated.
Description copied from class: `BaseInternalRequest`
After executing the request, checks that the request status is one of the supplied values. If this is not called before methods that access the response, a check for a 200 OK status is done automatically unless this was called with no arguments before. This makes sure a status check is done or explicitly disabled.

Overrides:
  `checkStatus` in class `BaseInternalRequest`
Parameters:
  `acceptableValues` - providing no values means "don't care"
Throws:
  `IOException` - if status doesn't match any of these values

### checkResponseContentType

public InternalRequest checkResponseContentType(String contentType) throws IOException
Deprecated.
After executing the request, checks that the response content-type is as expected.

Specified by:
  `checkResponseContentType` in class `BaseInternalRequest`
Throws:
  `IOException` - if the actual content-type doesn't match the expected one

### getStatus

public int getStatus() throws IOException
Deprecated.
Return the response status. The execute method must be called before this one.

Specified by:
  `getStatus` in class `BaseInternalRequest`
Throws:
  `IOException` - if the request hasn't been executed yet

### getResponse

public org.apache.sling.api.SlingHttpServletResponse getResponse() throws IOException
Deprecated.
Return the response object. The execute method must be called before this one. A check for "200 OK" status is done automatically unless `checkStatus(int...)` has been called before.

Throws:
  `IOException` - if the request hasn't been executed yet or if the status check fails.

### getResponseAsString

public String getResponseAsString() throws IOException
Deprecated.
Return the response as a String. The execute method must be called before this one. A check for "200 OK" status is done automatically unless `checkStatus(int...)` has been called before.

Specified by:
  `getResponseAsString` in class `BaseInternalRequest`
Throws:
  `IOException` - if the request hasn't been executed yet or if the status check fails.