public abstract class InternalRequest extends Object
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.Modifier and Type | Field and Description |
---|---|
protected String |
contentType |
static String |
DEFAULT_METHOD |
protected String |
extension |
protected org.slf4j.Logger |
log |
static String |
MDC_KEY
An slf4j MDC value is set at this key with request information.
|
protected String |
path |
protected String |
requestMethod |
protected org.apache.sling.api.resource.ResourceResolver |
resourceResolver |
protected String |
selectorString |
Modifier | Constructor and Description |
---|---|
protected |
InternalRequest(@NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver,
@NotNull String path)
Clients use subclasses of this one
|
Modifier and Type | Method and Description |
---|---|
protected void |
assertRequestExecuted() |
protected void |
checkNotNull(Class<?> clazz,
Object candidate) |
protected void |
checkNotNull(String info,
Object candidate) |
InternalRequest |
checkResponseContentType(String contentType)
After executing the request, checks that the response content-type
is as expected.
|
InternalRequest |
checkStatus(int... acceptableValues)
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)
Execute the supplied Request
|
InternalRequest |
execute()
Execute the internal request.
|
protected abstract org.apache.sling.api.resource.Resource |
getExecutionResource()
Provide the Resource to use to execute the request
|
org.apache.sling.api.SlingHttpServletResponse |
getResponse()
Return the response object.
|
String |
getResponseAsString()
Return the response as a String.
|
int |
getStatus()
Return the response status.
|
InternalRequest |
withBody(Reader bodyContent)
Use the supplied Reader as the request's body content
|
InternalRequest |
withContentType(String contentType)
Set the HTTP request's Content-Type
|
InternalRequest |
withExtension(String extension)
Sets the optional extension of the internal request, which influence
the Servlet/Script resolution.
|
InternalRequest |
withParameter(String key,
Object value)
Set a request parameter
|
InternalRequest |
withParameters(Map<String,Object> additionalParameters)
Add the supplied request parameters to the current ones
|
InternalRequest |
withRequestMethod(String method)
Set the HTTP request method to use - defaults to GET
|
InternalRequest |
withSelectors(String... selectors)
Sets the optional selectors of the internal request, which influence
the Servlet/Script resolution.
|
protected final org.apache.sling.api.resource.ResourceResolver resourceResolver
protected final String path
protected String selectorString
protected String extension
protected String requestMethod
protected String contentType
protected final org.slf4j.Logger log
public static final String DEFAULT_METHOD
public static final String MDC_KEY
protected InternalRequest(@NotNull @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver, @NotNull @NotNull String path)
public InternalRequest withRequestMethod(String method)
public InternalRequest withContentType(String contentType)
public InternalRequest withBody(Reader bodyContent)
public InternalRequest withSelectors(String... selectors)
public InternalRequest withExtension(String extension)
public InternalRequest withParameter(String key, Object value)
public InternalRequest withParameters(Map<String,Object> additionalParameters)
public final InternalRequest execute() throws IOException
IOException
- if the request was already executed,
or if an error occurs during execution.protected abstract org.apache.sling.api.resource.Resource getExecutionResource()
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
javax.servlet.ServletException
IOException
protected void assertRequestExecuted() throws IOException
IOException
public InternalRequest checkStatus(int... acceptableValues) throws IOException
acceptableValues
- providing no values means "don't care"IOException
- if status doesn't match any of these valuespublic InternalRequest checkResponseContentType(String contentType) throws IOException
IOException
- if the actual content-type doesn't match the expected onepublic int getStatus() throws IOException
IOException
- if the request hasn't been executed yetpublic org.apache.sling.api.SlingHttpServletResponse getResponse() throws IOException
checkStatus(int...)
has
been called before.IOException
- if the request hasn't been executed yet or if the status
check fails.public String getResponseAsString() throws IOException
checkStatus(int...)
has
been called before.IOException
- if the request hasn't been executed yet or if the status
check fails.Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.