Package com.isomorphic.servlet

# Class RequestContext

java.lang.Object
com.isomorphic.servlet.RequestContext

public class RequestContext extends Object
`RequestContext` aggregates state about the current request.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `ISCHttpServletRequest`
  `request`
  `ISCHttpServletRequest` instance for the current request.
  `jakarta.servlet.http.HttpServletResponse`
  `response`
  `HttpServletResponse` instance associated with this request

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static RequestContext`
  `instance(jakarta.servlet.jsp.PageContext pageContext)`
  Creates a `RequestContext` from a JSP `PageContext`.
  `static RequestContext`
  `instance(jakarta.servlet.ServletContext servletContext, jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response)`
  Creates a `RequestContext` from a ServletContext, ServletRequest and ServletResponse.
  `static RequestContext`
  `instance(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response)`
  Creates a `RequestContext` from a `ServletRequest` and `ServletResponse`.
  `static RequestContext`
  `instance(jakarta.servlet.Servlet servlet, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)`
  Creates a `RequestContext` from a `Servlet`, `HttpServletRequest` and `HttpServletResponse`.
  `static RequestContext`
  `instance(jakarta.servlet.Servlet servlet, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Writer out)`
  Creates a `RequestContext` from a `Servlet`, `HttpServletRequest`, `HttpServletResponse` and `Writer`.
  `static void`
  `setCacheControlHeader(jakarta.servlet.http.HttpServletResponse response, String value)`
  Sets the Cache-Control HTTP response header directly
  `void`
  `setCacheControlHeader(String value)`
  Sets the Cache-Control HTTP response header directly
  `void`
  `setCachePolicy(CachePolicy... directives)`
  Sets the Cache-Control HTTP response header
  `static void`
  `setCachePolicy(jakarta.servlet.http.HttpServletResponse response, CachePolicy... directives)`
  Sets the Cache-Control HTTP response header

- ## Field Details

  - ### request

    public ISCHttpServletRequest request
    `ISCHttpServletRequest` instance for the current request.

  - ### response

    public jakarta.servlet.http.HttpServletResponse response
    `HttpServletResponse` instance associated with this request

- ## Method Details

  - ### instance

    public static RequestContext instance(jakarta.servlet.jsp.PageContext pageContext) throws Exception
    Creates a `RequestContext` from a JSP `PageContext`.
    Parameters:
      `pageContext` - the page context to use for creating the RequestContext
    Returns:
      the new RequestContext
    Throws:
      `Exception`
    See Also:
      - `instance(ServletContext, ServletRequest, ServletResponse)`

  - ### instance

    public static RequestContext instance(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) throws Exception
    Creates a `RequestContext` from a `ServletRequest` and `ServletResponse`.
    Parameters:
      `request` - the ServletRequest
      `response` - the ServletResponse
    Returns:
      the new RequestContext
    Throws:
      `Exception`
    See Also:
      - `instance(ServletContext, ServletRequest, ServletResponse)`

  - ### instance

    public static RequestContext instance(jakarta.servlet.Servlet servlet, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws Exception
    Creates a `RequestContext` from a `Servlet`, `HttpServletRequest` and `HttpServletResponse`.
    Parameters:
      `servlet` - the servlet
      `request` - the HttpServletRequest
      `response` - the HttpServletResponse
    Throws:
      `Exception`
    See Also:
      - `instance(ServletContext, ServletRequest, ServletResponse)`

  - ### instance

    public static RequestContext instance(jakarta.servlet.Servlet servlet, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Writer out) throws Exception
    Creates a `RequestContext` from a `Servlet`, `HttpServletRequest`, `HttpServletResponse` and `Writer`.
    Parameters:
      `servlet` - the Servlet
      `request` - the HttpServletRequest
      `response` - the HttpServletResponse
      `out` - the output writer
    Returns:
      the new RequestContext
    Throws:
      `Exception`
    See Also:
      - `instance(ServletContext, ServletRequest, ServletResponse)`

  - ### instance

    public static RequestContext instance(jakarta.servlet.ServletContext servletContext, jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) throws Exception
    Creates a `RequestContext` from a ServletContext, ServletRequest and ServletResponse.

    Important Note
    Before we explain the benefits of creating your own RequestContext please take note that only one instance of this must be created and passed along during a requests life-cycle. In normal circumstances one will be created through the `IDACall` servlet and there will be no need for you to handle this explicitly.

    A typical use case for explicitly creating a RequestContext is is you've implemented your own standalone servlet which does not extend `IDACall` and you require the servlet request/response to be available further down the request chain such as in a DMI call you might issue from your servlet. This could be useful when passing session related data down to your DMI implementations for instance. Once you've created a RequestContext you simply set it on your `DSRequest` or `RPCRequest` using `setContext(requestContext)`.

    Parameters:
      `servletContext` - the servlet context.
      `request` - the servlet request.
      `response` - the servlet response.
    Returns:
      a RequestContext.
    Throws:
      `Exception`
    See Also:
      - `BaseRequest.setContext(RequestContext)`

  - ### setCachePolicy

    public void setCachePolicy(CachePolicy... directives) throws Exception
    Sets the Cache-Control HTTP response header
    Parameters:
      `directives` - an array of `CachePolicy` response directives
    Throws:
      `Exception`

  - ### setCachePolicy

    public static void setCachePolicy(jakarta.servlet.http.HttpServletResponse response, CachePolicy... directives)
    Sets the Cache-Control HTTP response header
    Parameters:
      `response` - `HttpServletResponse` to set header to
      `directives` - an array of `CachePolicy` response directives

  - ### setCacheControlHeader

    public void setCacheControlHeader(String value) throws Exception
    Sets the Cache-Control HTTP response header directly
    Parameters:
      `value` - `String` of response directives
    Throws:
      `Exception`

  - ### setCacheControlHeader

    public static void setCacheControlHeader(jakarta.servlet.http.HttpServletResponse response, String value)
    Sets the Cache-Control HTTP response header directly
    Parameters:
      `response` - `HttpServletResponse` to set header to
      `value` - `String` of response directives