org.liquidsite.core.web
Class Request

java.lang.Object
  extended byorg.liquidsite.core.web.Request
Direct Known Subclasses:
MultiPartRequest

public class Request
extends java.lang.Object

An HTTP request and response.


Nested Class Summary
static interface Request.FileParameter
          A request file parameter.
 
Constructor Summary
Request(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Creates a new request.
 
Method Summary
 void commit(javax.servlet.ServletContext context, boolean content)
          Sends the request response to the underlying HTTP response object.
 void dispose()
          Disposes of all resources used by this request object.
 java.util.Map getAllAttributes()
          Returns all the request attributes in a map.
 java.util.Map getAllParameters()
          Returns a map with all the request parameter names and values.
 java.lang.Object getAttribute(java.lang.String name)
          Returns the value of a request attribute.
 java.lang.Object getAttribute(java.lang.String name, java.lang.Object defVal)
          Returns the value of a request attribute.
 RequestEnvironment getEnvironment()
          Returns the request environment object.
 Request.FileParameter getFileParameter(java.lang.String name)
          Returns the specified file request parameter.
 java.lang.String getHost()
          Returns the host name in the request.
 java.lang.String getParameter(java.lang.String name)
          Returns the value of a request parameter.
 java.lang.String getParameter(java.lang.String name, java.lang.String defVal)
          Returns the value of a request parameter.
 java.lang.String getPath()
          Returns the request path with file name.
 int getPort()
          Returns the port number in the request.
 java.lang.String getProtocol()
          Returns the protocol name in the request, i.e.
 java.lang.String getRemoteAddr()
          Returns the IP address of the request sender.
 javax.servlet.ServletContext getServletContext()
          Returns the servlet context.
 java.lang.String getServletPath()
          Returns the servlet portion of the request path.
 RequestSession getSession()
          Returns the request session.
 java.lang.String getUrl()
          Returns the full request URL with protocol, hostname and path.
 User getUser()
          Returns the session user.
 boolean hasResponse()
          Checks if this request contains a response.
 void sendData(java.lang.String mimeType, java.lang.String data)
          Sends the specified data as the request response.
 void sendFile(java.io.File file, boolean limitCache)
          Sends the contents of a file as the request response.
 void sendRedirect(java.lang.String location)
          Redirects this request by sending a temporary redirection URL to the browser.
 void setAttribute(java.lang.String name, boolean value)
          Sets a request attribute value.
 void setAttribute(java.lang.String name, int value)
          Sets a request attribute value.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Sets a request attribute value.
 void setUser(User user)
          Sets the session user.
 java.lang.String toString()
          Returns a string representation of this request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Request

public Request(javax.servlet.ServletContext context,
               javax.servlet.http.HttpServletRequest request,
               javax.servlet.http.HttpServletResponse response)
Creates a new request.

Parameters:
context - the servlet context
request - the HTTP request
response - the HTTP response
Method Detail

toString

public java.lang.String toString()
Returns a string representation of this request.

Returns:
a string representation of this request

hasResponse

public boolean hasResponse()
Checks if this request contains a response.

Returns:
true if the request contains a response, or false otherwise

getProtocol

public java.lang.String getProtocol()
Returns the protocol name in the request, i.e. "http" or "https".

Returns:
the protocol name

getHost

public java.lang.String getHost()
Returns the host name in the request.

Returns:
the host name

getPort

public int getPort()
Returns the port number in the request.

Returns:
the port number

getPath

public java.lang.String getPath()
Returns the request path with file name. This will include the servlet portion of the path.

Returns:
the request path with file name

getServletContext

public javax.servlet.ServletContext getServletContext()
Returns the servlet context.

Returns:
the servlet context

getServletPath

public java.lang.String getServletPath()
Returns the servlet portion of the request path.

Returns:
the servlet portion of the request path

getUrl

public java.lang.String getUrl()
Returns the full request URL with protocol, hostname and path. No query parameters will be included in the URL, however.

Returns:
the full request URL

getRemoteAddr

public java.lang.String getRemoteAddr()
Returns the IP address of the request sender.

Returns:
the IP address of the request sender

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Returns the value of a request attribute.

Parameters:
name - the attribute name
Returns:
the attribute value, or null if no such attribute was found

getAttribute

public java.lang.Object getAttribute(java.lang.String name,
                                     java.lang.Object defVal)
Returns the value of a request attribute. If the specified attribute does not exist, a default value will be returned.

Parameters:
name - the attribute name
defVal - the default attribute value
Returns:
the attribute value, or the default value if no such attribute was found

getAllAttributes

public java.util.Map getAllAttributes()
Returns all the request attributes in a map.

Returns:
the map with request attribute names and values

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Sets a request attribute value.

Parameters:
name - the attribute name
value - the attribute value

setAttribute

public void setAttribute(java.lang.String name,
                         boolean value)
Sets a request attribute value.

Parameters:
name - the attribute name
value - the attribute value

setAttribute

public void setAttribute(java.lang.String name,
                         int value)
Sets a request attribute value.

Parameters:
name - the attribute name
value - the attribute value

getAllParameters

public java.util.Map getAllParameters()
Returns a map with all the request parameter names and values.

Returns:
the map with request parameter names and values

getParameter

public java.lang.String getParameter(java.lang.String name)
Returns the value of a request parameter.

Parameters:
name - the request parameter name
Returns:
the request parameter value, or null if no such parameter was found

getParameter

public java.lang.String getParameter(java.lang.String name,
                                     java.lang.String defVal)
Returns the value of a request parameter. If the specified parameter does not exits, a default value will be returned.

Parameters:
name - the request parameter name
defVal - the default parameter value
Returns:
the request parameter value, or the default value if no such parameter was found

getFileParameter

public Request.FileParameter getFileParameter(java.lang.String name)
Returns the specified file request parameter. The default request container doesn't support file parameters, and will return null on each call. Other request containers may override this method, however, if they are able to handle incoming files.

Parameters:
name - the request parameter name
Returns:
the request file parameter, or null if no such file parameter was found

getUser

public User getUser()
Returns the session user. The session user is null until it is set by the setUser() method. Normally the session user is not set until the user has been authenticated. If no sesssion existed, this method will return null.

Returns:
the session user, or null if no user has been set
See Also:
setUser(org.liquidsite.core.content.User)

setUser

public void setUser(User user)
Sets the session user. The session user is null until it is set by this method. Normally the session user is not set until the user has been authenticated. If the user is set to null, the whole session will be invalidated.

Parameters:
user - the new session user, or null to logout
See Also:
getUser()

getEnvironment

public RequestEnvironment getEnvironment()
Returns the request environment object. The request environment is used for storing references to objects that the request touches.

Returns:
the request environment object

getSession

public RequestSession getSession()
Returns the request session. If no session existed a new one will be created.

Returns:
the new or existing request session

sendData

public void sendData(java.lang.String mimeType,
                     java.lang.String data)
Sends the specified data as the request response.

Parameters:
mimeType - the data MIME type
data - the data to send

sendFile

public void sendFile(java.io.File file,
                     boolean limitCache)
Sends the contents of a file as the request response. The file name extension will be used for determining the MIME type for the file contents. The cache header for the file may be limited to private by setting the limit cache header.

Parameters:
file - the file containing the response
limitCache - the limited cache flag

sendRedirect

public void sendRedirect(java.lang.String location)
Redirects this request by sending a temporary redirection URL to the browser. The location specified may be either an absolute or a relative URL. This method will set a request response.

Parameters:
location - the destination location

dispose

public void dispose()
Disposes of all resources used by this request object. This method shouldn't be called until a response has been written.


commit

public void commit(javax.servlet.ServletContext context,
                   boolean content)
            throws java.io.IOException,
                   javax.servlet.ServletException
Sends the request response to the underlying HTTP response object. This method shouldn't be called more than once per request, and should not be called in case no response has been stored in the request. The response can be committed either completely or solely with the response headers.

Parameters:
context - the servlet context
content - the complete content response flag
Throws:
java.io.IOException - if an IO error occured while attempting to commit the response
javax.servlet.ServletException - if a configuration error was encountered while sending the response