Class HttpRequest

java.lang.Object
com.yahoo.container.jdisc.HttpRequest

public class HttpRequest extends Object
Wraps a JDisc HTTP request for a synchronous API.

The properties of this request represents what was received in the request and are thus immutable. If you need mutable abstractions, use a higher level framework, e.g. Processing.

Author:
hmusum, Steinar Knutsen
  • Constructor Details

    • HttpRequest

      public HttpRequest(HttpRequest jdiscHttpRequest, InputStream requestData)
      Wrap a JDisc HTTP request in a synchronous API. The properties from the JDisc request will be copied into the HTTP request.
      Parameters:
      jdiscHttpRequest - the JDisc request
      requestData - the associated input stream, e.g. with POST request
    • HttpRequest

      public HttpRequest(HttpRequest jdiscHttpRequest, InputStream requestData, Map<String,String> propertyOverrides)
      Wrap a JDisc HTTP request in a synchronous API. The properties from the JDisc request will be copied into the HTTP request. The mappings in propertyOverrides will mask the settings in the JDisc request. The content of propertyOverrides will be copied, so it is safe to re-use and changes in propertyOverrides after constructing the HttpRequest instance will obviously not be reflected by the request. The same applies for JDisc parameters.
      Parameters:
      jdiscHttpRequest - the JDisc request
      requestData - the associated input stream, e.g. with POST request
      propertyOverrides - properties which should not have the same settings as in the parent JDisc request, may be null
  • Method Details

    • createRequest

      public static HttpRequest createRequest(com.yahoo.jdisc.service.CurrentContainer container, URI uri, HttpRequest.Method method, InputStream requestData)
      Create a new HTTP request from an URI.
      Parameters:
      container - the current container instance
      uri - the request parameters
      method - GET, POST, etc
      requestData - the associated data stream, may be null
      Returns:
      a new HTTP request
    • createRequest

      public static HttpRequest createRequest(com.yahoo.jdisc.service.CurrentContainer container, URI uri, HttpRequest.Method method, InputStream requestData, Map<String,String> properties)
      Create a new HTTP request from an URI.
      Parameters:
      container - the current container instance
      uri - the request parameters
      method - GET, POST, etc
      requestData - the associated data stream, may be null
      properties - a set of properties to set in the request in addition to the implicit ones from the URI
      Returns:
      a new HTTP request
    • getHttpRequest

      public static Optional<HttpRequest> getHttpRequest(Request processingRequest)
    • getAccessLogEntry

      public Optional<AccessLogEntry> getAccessLogEntry()
    • createTestRequest

      public static HttpRequest createTestRequest(String uri, HttpRequest.Method method)
      Only for simpler unit testing.
      Parameters:
      uri - the complete URI string
      method - POST, GET, etc
      Returns:
      a valid HTTP request
    • createTestRequest

      public static HttpRequest createTestRequest(String uri, HttpRequest.Method method, InputStream requestData)
      Only for simpler unit testing.
      Parameters:
      uri - the complete URI string
      method - POST, GET, etc
      requestData - for simulating POST
      Returns:
      a valid HTTP request
    • createTestRequest

      public static HttpRequest createTestRequest(String uri, HttpRequest.Method method, InputStream requestData, Map<String,String> properties)
    • getMethod

      public HttpRequest.Method getMethod()
      Return the HTTP method (GET, POST...) of the incoming request.
      Returns:
      a Method instance matching the HTTP method of the request
    • getUri

      public URI getUri()
      Get the full URI corresponding to this request.
      Returns:
      the URI of this request
    • getJDiscRequest

      public HttpRequest getJDiscRequest()
      Access the underlying JDisc for this HTTP request.
      Returns:
      the corresponding JDisc request instance
    • context

      public Map<String,Object> context()

      Returns the named application context objects. This data is not intended for network transport, rather they are intended for passing shared data between components of an Application.

      Returns:
      The context map.
    • creationTime

      public long creationTime(TimeUnit unit)
      Returns the time at which this Request was created.
    • getConnectedAt

      public long getConnectedAt(TimeUnit unit)

      For server requests, this returns the timestamp of when the underlying HTTP channel was connected.

      Parameters:
      unit - the unit to return the time in
      Returns:
      the timestamp of when the underlying HTTP channel was connected, or request creation time
    • relativeCreatedAtNanoTime

      public long relativeCreatedAtNanoTime()
      Returns:
      the relative created timestamp (using System.nanoTime()
    • getProperty

      public String getProperty(String name)
      Returns the value of a request property/parameter. Multi-value properties are not supported.
      Parameters:
      name - the name of the URI property to return
      Returns:
      the value of the property in question, or null if not present
    • propertyMap

      public Map<String,String> propertyMap()
      Return a read-only view of the request parameters. Multi-value parameters are not supported.
      Returns:
      a map containing all the parameters in the request
    • getBooleanProperty

      public boolean getBooleanProperty(String name)
      Helper method to parse boolean request flags, using Boolean.parseBoolean(String). Unset values are regarded as false.
      Parameters:
      name - the name of a request property
      Returns:
      whether the property has been explicitly set to true
    • hasProperty

      public boolean hasProperty(String name)
      Check whether a property exists.
      Parameters:
      name - the name of a request property
      Returns:
      true if the property has a value
    • getHeader

      public String getHeader(String name)
      Access an HTTP header in the request. Multi-value headers are not supported.
      Parameters:
      name - the name of an HTTP header
      Returns:
      the first pertinent value
    • getHost

      public String getHost()
      Get the host segment of the URI of this request.
    • getPort

      public int getPort()
      The port of the URI of this request.
    • getData

      public InputStream getData()
      The input stream for this request, i.e. data POSTed from the client. A client may read as much or as little data as needed from this stream, draining and closing will be done by the RequestHandler base classes using this HttpRequest (sub-)class. In other words, this stream should not be closed after use.
      Returns:
      the stream with the client data for this request