Package com.yahoo.container.jdisc
Class HttpRequest
java.lang.Object
com.yahoo.container.jdisc.HttpRequest
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
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionHttpRequest
(HttpRequest jdiscHttpRequest, InputStream requestData) Wrap a JDisc HTTP request in a synchronous API.HttpRequest
(HttpRequest jdiscHttpRequest, InputStream requestData, Map<String, String> propertyOverrides) Wrap a JDisc HTTP request in a synchronous API. -
Method Summary
Modifier and TypeMethodDescriptioncontext()
Returns the named application context objects.static HttpRequest
createRequest
(com.yahoo.jdisc.service.CurrentContainer container, URI uri, HttpRequest.Method method, InputStream requestData) Create a new HTTP request from an URI.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.static HttpRequest
createTestRequest
(String uri, HttpRequest.Method method) Only for simpler unit testing.static HttpRequest
createTestRequest
(String uri, HttpRequest.Method method, InputStream requestData) Only for simpler unit testing.static HttpRequest
createTestRequest
(String uri, HttpRequest.Method method, InputStream requestData, Map<String, String> properties) long
creationTime
(TimeUnit unit) Returns the time at which this Request was created.boolean
getBooleanProperty
(String name) Helper method to parse boolean request flags, using Boolean.parseBoolean(String).long
getConnectedAt
(TimeUnit unit) For server requests, this returns the timestamp of when the underlying HTTP channel was connected.getData()
The input stream for this request, i.e.Access an HTTP header in the request.getHost()
Get the host segment of the URI of this request.static Optional<HttpRequest>
getHttpRequest
(Request processingRequest) Access the underlying JDisc for this HTTP request.Return the HTTP method (GET, POST...) of the incoming request.int
getPort()
The port of the URI of this request.getProperty
(String name) Returns the value of a request property/parameter.getUri()
Get the full URI corresponding to this request.boolean
hasProperty
(String name) Check whether a property exists.Return a read-only view of the request parameters.long
-
Constructor Details
-
HttpRequest
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 requestrequestData
- 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 requestrequestData
- the associated input stream, e.g. with POST requestpropertyOverrides
- 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 instanceuri
- the request parametersmethod
- GET, POST, etcrequestData
- 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 instanceuri
- the request parametersmethod
- GET, POST, etcrequestData
- the associated data stream, may be nullproperties
- a set of properties to set in the request in addition to the implicit ones from the URI- Returns:
- a new HTTP request
-
getHttpRequest
-
getAccessLogEntry
-
createTestRequest
Only for simpler unit testing.- Parameters:
uri
- the complete URI stringmethod
- 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 stringmethod
- POST, GET, etcrequestData
- 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
Return the HTTP method (GET, POST...) of the incoming request.- Returns:
- a Method instance matching the HTTP method of the request
-
getUri
Get the full URI corresponding to this request.- Returns:
- the URI of this request
-
getJDiscRequest
Access the underlying JDisc for this HTTP request.- Returns:
- the corresponding JDisc request instance
-
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
Returns the time at which this Request was created. -
getConnectedAt
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
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
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
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
Check whether a property exists.- Parameters:
name
- the name of a request property- Returns:
- true if the property has a value
-
getHeader
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
Get the host segment of the URI of this request. -
getPort
public int getPort()The port of the URI of this request. -
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
-