Class RequestEntity
- java.lang.Object
-
- org.simpleframework.http.core.RequestMessage
-
- org.simpleframework.http.core.RequestEntity
-
- All Implemented Interfaces:
Request
,RequestHeader
,RequestLine
class RequestEntity extends RequestMessage implements Request
This object is used to represent a HTTP request. This defines the attributes that a HTTP request has such as a request line and the headers that come with the message header.The
Request
is used to provide an interface to the HTTPInputStream
and message header. The stream can have certain characteristics, these characteristics are available by this object. TheRequest
provides methods that allow theInputStream
's semantics to be known, for example if the stream is keep-alive or if the stream has a length.The
Request
origin is also retrievable from theRequest
as is the attributesMap
object which defines specific connection attributes. And acts as a simple model for the request transaction.It is important to note that the
Request
controls the processing of the HTTP pipeline. The next HTTP request is not processed until the request has read all of the content body within theInputStream
. The stream must be fully read or closed for the next request to be processed.
-
-
Field Summary
Fields Modifier and Type Field Description private Body
body
The body contains the message content sent by the client.private QueryBuilder
builder
This will create the form object using the query and body.private Certificate
certificate
This is the certificate associated with the connection.private Channel
channel
This channel represents the connected pipeline used.private java.util.Map
map
This is used to contain the values for this request.private Query
query
The query contains all the parameters for the request.private long
time
This is the time at which the request is ready to be used.-
Fields inherited from class org.simpleframework.http.core.RequestMessage
header
-
-
Constructor Summary
Constructors Constructor Description RequestEntity(ResponseObserver observer, Entity entity)
Constructor for theRequestEntity
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
getAttribute(java.lang.Object key)
This is used as a shortcut for acquiring attributes for the response.java.util.Map
getAttributes()
This can be used to retrieve the response attributes.java.nio.channels.ReadableByteChannel
getByteChannel()
This is used to read the content body.Channel
getChannel()
This provides the underlying channel for the request.java.net.InetSocketAddress
getClientAddress()
This is used to acquire the remote client address.private java.net.InetSocketAddress
getClientAddress(java.net.Socket socket)
This is used to acquire the remote client address.Certificate
getClientCertificate()
This is used to acquire the SSL certificate used when the server is using a HTTPS connection.java.lang.String
getContent()
This is used to get the content body.java.lang.String
getContent(ContentType type)
This is used to get the content body.java.io.InputStream
getInputStream()
This is used to read the content body.java.lang.String
getParameter(java.lang.String name)
This is used to provide quick access to the parameters.Part
getPart(java.lang.String name)
This method is used to acquire aPart
from the HTTP request using a known name for the part.java.util.List<Part>
getParts()
This method is used to get allPart
objects that are associated with the request.Query
getQuery()
This method is used to acquire the query part from the HTTP request URI target and a form post if it exists.long
getRequestTime()
This is the time in milliseconds when the request was first read from the underlying socket.boolean
isKeepAlive()
This is a convenience method that is used to determine whether or not this message has the Connection header with the close token.boolean
isSecure()
This is used to determine if the request has been transferred over a secure connection.-
Methods inherited from class org.simpleframework.http.core.RequestMessage
getAddress, getContentLength, getContentType, getCookie, getCookies, getDate, getHeader, getInteger, getLocales, getMajor, getMethod, getMinor, getNames, getPath, getTarget, getValue, getValue, getValues, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.simpleframework.http.RequestHeader
getContentLength, getContentType, getCookie, getCookies, getDate, getHeader, getInteger, getLocales, getNames, getValue, getValue, getValues, toString
-
Methods inherited from interface org.simpleframework.http.RequestLine
getAddress, getMajor, getMethod, getMinor, getPath, getTarget
-
-
-
-
Field Detail
-
certificate
private Certificate certificate
This is the certificate associated with the connection.
-
builder
private QueryBuilder builder
This will create the form object using the query and body.
-
channel
private Channel channel
This channel represents the connected pipeline used.
-
query
private Query query
The query contains all the parameters for the request.
-
body
private Body body
The body contains the message content sent by the client.
-
map
private java.util.Map map
This is used to contain the values for this request.
-
time
private long time
This is the time at which the request is ready to be used.
-
-
Constructor Detail
-
RequestEntity
public RequestEntity(ResponseObserver observer, Entity entity)
Constructor for theRequestEntity
object. This is used to create a request that contains all the parts sent by the client, including the headers and the request body. Each of the request elements are accessible through this object in a convenient manner, all parts and parameters, as well as cookies can be accessed and used without much effort.- Parameters:
observer
- this is the observer used to monitor eventsentity
- this is the entity that was sent by the client
-
-
Method Detail
-
isSecure
public boolean isSecure()
This is used to determine if the request has been transferred over a secure connection. If the protocol is HTTPS and the content is delivered over SSL then the request is considered to be secure. Also the associated response will be secure.
-
isKeepAlive
public boolean isKeepAlive()
This is a convenience method that is used to determine whether or not this message has the Connection header with the close token. If the close token is present then this stream is not a keep-alive connection. However if this has no Connection header then the keep alive status is determined by the HTTP version, that is HTTP/1.1 is keep alive by default, HTTP/1.0 has the connection close by default.- Specified by:
isKeepAlive
in interfaceRequest
- Returns:
- returns true if this is keep alive connection
-
getRequestTime
public long getRequestTime()
This is the time in milliseconds when the request was first read from the underlying socket. The time represented here represents the time collection of this request began. This does not necessarily represent the time the bytes arrived on the receive buffers as some data may have been buffered.- Specified by:
getRequestTime
in interfaceRequest
- Returns:
- this represents the time the request arrived at
-
getChannel
public Channel getChannel()
This provides the underlying channel for the request. It contains the TCP socket channel and various other low level components. Typically this will only ever be needed when there is a need to switch protocols.- Specified by:
getChannel
in interfaceRequest
- Returns:
- the underlying channel for this request
-
getClientCertificate
public Certificate getClientCertificate()
This is used to acquire the SSL certificate used when the server is using a HTTPS connection. For plain text connections or connections that use a security mechanism other than SSL this will be null. This is only available when the connection makes specific use of an SSL engine to secure the connection.- Specified by:
getClientCertificate
in interfaceRequest
- Returns:
- this returns the associated SSL certificate if any
-
getClientAddress
public java.net.InetSocketAddress getClientAddress()
This is used to acquire the remote client address. This can be used to acquire both the port and the I.P address for the client. It allows the connected clients to be logged and if require it can be used to perform course grained security.- Specified by:
getClientAddress
in interfaceRequest
- Returns:
- this returns the client address for this request
-
getClientAddress
private java.net.InetSocketAddress getClientAddress(java.net.Socket socket)
This is used to acquire the remote client address. This can be used to acquire both the port and the I.P address for the client. It allows the connected clients to be logged and if require it can be used to perform course grained security.- Parameters:
socket
- this is the socket to get the address for- Returns:
- this returns the client address for this request
-
getContent
public java.lang.String getContent() throws java.io.IOException
This is used to get the content body. This will essentially get the content from the body and present it as a single string. The encoding of the string is determined from the content type charset value. If the charset is not supported this will throw an exception. Typically only text values should be extracted using this method if there is a need to parse that content.- Specified by:
getContent
in interfaceRequest
- Returns:
- the body content containing the message body
- Throws:
java.io.IOException
-
getContent
public java.lang.String getContent(ContentType type) throws java.io.IOException
This is used to get the content body. This will essentially get the content from the body and present it as a single string. The encoding of the string is determined from the content type charset value. If the charset is not supported this will throw an exception. Typically only text values should be extracted using this method if there is a need to parse that content.- Parameters:
type
- this is the content type used with the request- Returns:
- the input stream containing the message body
- Throws:
java.io.IOException
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOException
This is used to read the content body. The specifics of the data that is read from thisInputStream
can be determined by thegetContentLength
method. If the data sent by the client is chunked then it is decoded, see RFC 2616 section 3.6. Also multipart data is available asPart
objects however the raw content of the multipart body is still available.- Specified by:
getInputStream
in interfaceRequest
- Returns:
- the input stream containing the message body
- Throws:
java.io.IOException
-
getByteChannel
public java.nio.channels.ReadableByteChannel getByteChannel() throws java.io.IOException
This is used to read the content body. The specifics of the data that is read from thisReadableByteChannel
can be determined by thegetContentLength
method. If the data sent by the client is chunked then it is decoded, see RFC 2616 section 3.6. This stream will never provide empty reads as the content is internally buffered, so this can do a full read.- Specified by:
getByteChannel
in interfaceRequest
- Returns:
- this returns the byte channel used to read the content
- Throws:
java.io.IOException
-
getAttributes
public java.util.Map getAttributes()
This can be used to retrieve the response attributes. These can be used to keep state with the response when it is passed to other systems for processing. Attributes act as a convenient model for storing objects associated with the response. This also inherits attributes associated with the client connection.- Specified by:
getAttributes
in interfaceRequest
- Returns:
- the attributes that have been added to this request
-
getAttribute
public java.lang.Object getAttribute(java.lang.Object key)
This is used as a shortcut for acquiring attributes for the response. This avoids acquiring the attributeMap
in order to retrieve the attribute directly from that object. The attributes contain data specific to the response.- Specified by:
getAttribute
in interfaceRequest
- Parameters:
key
- this is the key of the attribute to acquire- Returns:
- this returns the attribute for the specified name
-
getQuery
public Query getQuery()
This method is used to acquire the query part from the HTTP request URI target and a form post if it exists. Both the query and the form post are merge together in a single query.- Specified by:
getQuery
in interfaceRequestLine
- Overrides:
getQuery
in classRequestMessage
- Returns:
- the query associated with the HTTP target URI
-
getParameter
public java.lang.String getParameter(java.lang.String name)
This is used to provide quick access to the parameters. This avoids having to acquire the requestForm
object. This basically acquires the parameters object and invokes thegetParameters
method with the given name.- Specified by:
getParameter
in interfaceRequest
- Parameters:
name
- this is the name of the parameter value
-
getPart
public Part getPart(java.lang.String name)
This method is used to acquire aPart
from the HTTP request using a known name for the part. This is typically used when there is a file upload with a multipart POST request. All parts that are not files can be acquired as string values from the attachment object.
-
getParts
public java.util.List<Part> getParts()
This method is used to get allPart
objects that are associated with the request. Each attachment contains the body and headers associated with it. If the request is not a multipart POST request then this will return an empty list.
-
-