Package com.yahoo.container.jdisc
Class HttpRequest
- java.lang.Object
-
- com.yahoo.container.jdisc.HttpRequest
-
public class HttpRequest extends java.lang.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HttpRequest.Builder
Builder of HTTP requests
-
Constructor Summary
Constructors Constructor Description HttpRequest(com.yahoo.jdisc.http.HttpRequest jdiscHttpRequest, java.io.InputStream requestData)
Wrap a JDisc HTTP request in a synchronous API.HttpRequest(com.yahoo.jdisc.http.HttpRequest jdiscHttpRequest, java.io.InputStream requestData, java.util.Map<java.lang.String,java.lang.String> propertyOverrides)
Wrap a JDisc HTTP request in a synchronous API.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static HttpRequest
createRequest(com.yahoo.jdisc.service.CurrentContainer container, java.net.URI uri, com.yahoo.jdisc.http.HttpRequest.Method method, java.io.InputStream requestData)
Create a new HTTP request from an URI.static HttpRequest
createRequest(com.yahoo.jdisc.service.CurrentContainer container, java.net.URI uri, com.yahoo.jdisc.http.HttpRequest.Method method, java.io.InputStream requestData, java.util.Map<java.lang.String,java.lang.String> properties)
Create a new HTTP request from an URI.static HttpRequest
createTestRequest(java.lang.String uri, com.yahoo.jdisc.http.HttpRequest.Method method)
Only for simpler unit testing.static HttpRequest
createTestRequest(java.lang.String uri, com.yahoo.jdisc.http.HttpRequest.Method method, java.io.InputStream requestData)
Only for simpler unit testing.static HttpRequest
createTestRequest(java.lang.String uri, com.yahoo.jdisc.http.HttpRequest.Method method, java.io.InputStream requestData, java.util.Map<java.lang.String,java.lang.String> properties)
java.util.Optional<com.yahoo.container.logging.AccessLogEntry>
getAccessLogEntry()
boolean
getBooleanProperty(java.lang.String name)
Helper method to parse boolean request flags, using Boolean.parseBoolean(String).java.io.InputStream
getData()
The input stream for this request, i.e.java.lang.String
getHeader(java.lang.String name)
Access an HTTP header in the request.java.lang.String
getHost()
Get the host segment of the URI of this request.static java.util.Optional<HttpRequest>
getHttpRequest(com.yahoo.processing.Request processingRequest)
com.yahoo.jdisc.http.HttpRequest
getJDiscRequest()
Access the underlying JDisc for this HTTP request.com.yahoo.jdisc.http.HttpRequest.Method
getMethod()
Return the HTTP method (GET, POST...) of the incoming request.int
getPort()
The port of the URI of this request.java.lang.String
getProperty(java.lang.String name)
Returns the value of a request property/parameter.java.net.URI
getUri()
Get the full URI corresponding to this request.boolean
hasProperty(java.lang.String name)
Check whether a property exists.java.util.Map<java.lang.String,java.lang.String>
propertyMap()
Return a read-only view of the request parameters.
-
-
-
Constructor Detail
-
HttpRequest
public HttpRequest(com.yahoo.jdisc.http.HttpRequest jdiscHttpRequest, java.io.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 requestrequestData
- the associated input stream, e.g. with POST request
-
HttpRequest
public HttpRequest(com.yahoo.jdisc.http.HttpRequest jdiscHttpRequest, java.io.InputStream requestData, java.util.Map<java.lang.String,java.lang.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 Detail
-
createRequest
public static HttpRequest createRequest(com.yahoo.jdisc.service.CurrentContainer container, java.net.URI uri, com.yahoo.jdisc.http.HttpRequest.Method method, java.io.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, java.net.URI uri, com.yahoo.jdisc.http.HttpRequest.Method method, java.io.InputStream requestData, java.util.Map<java.lang.String,java.lang.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
public static java.util.Optional<HttpRequest> getHttpRequest(com.yahoo.processing.Request processingRequest)
-
getAccessLogEntry
public java.util.Optional<com.yahoo.container.logging.AccessLogEntry> getAccessLogEntry()
-
createTestRequest
public static HttpRequest createTestRequest(java.lang.String uri, com.yahoo.jdisc.http.HttpRequest.Method method)
Only for simpler unit testing.- Parameters:
uri
- the complete URI stringmethod
- POST, GET, etc- Returns:
- a valid HTTP request
-
createTestRequest
public static HttpRequest createTestRequest(java.lang.String uri, com.yahoo.jdisc.http.HttpRequest.Method method, java.io.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(java.lang.String uri, com.yahoo.jdisc.http.HttpRequest.Method method, java.io.InputStream requestData, java.util.Map<java.lang.String,java.lang.String> properties)
-
getMethod
public com.yahoo.jdisc.http.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 java.net.URI getUri()
Get the full URI corresponding to this request.- Returns:
- the URI of this request
-
getJDiscRequest
public com.yahoo.jdisc.http.HttpRequest getJDiscRequest()
Access the underlying JDisc for this HTTP request.- Returns:
- the corresponding JDisc request instance
-
getProperty
public java.lang.String getProperty(java.lang.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 java.util.Map<java.lang.String,java.lang.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(java.lang.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(java.lang.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 java.lang.String getHeader(java.lang.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 java.lang.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 java.io.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
-
-