org.openejb.server.httpd
Class HttpResponseImpl

java.lang.Object
  extended by org.openejb.server.httpd.HttpResponseImpl
All Implemented Interfaces:
java.io.Serializable, HttpResponse

public class HttpResponseImpl
extends java.lang.Object
implements HttpResponse

This class takes care of HTTP Responses. It sends data back to the browser.

See Also:
Serialized Form

Field Summary
static java.lang.String CRLF
          a line feed character
static java.lang.String CSP
          a colon and space
static java.lang.String HTTP_VERSION
          the HTTP version
static java.lang.String server
          the server to send data from
static java.lang.String SP
          a space character
 
Constructor Summary
protected HttpResponseImpl()
          creates a new instance of HttpResponseImpl with default values
protected HttpResponseImpl(int code, java.lang.String responseString, java.lang.String contentType)
          Creates a new HttpResponseImpl with user provided parameters
 
Method Summary
protected static HttpResponseImpl createError(java.lang.String message)
          This could be improved at some day in the future to also include a stack trace of the exceptions
protected static HttpResponseImpl createError(java.lang.String message, java.lang.Throwable t)
          creates an error with user defined variables
protected static HttpResponseImpl createForbidden(java.lang.String ip)
          Creates a forbidden response to be sent to the browser using IP authentication
 int getCode()
          gets the HTTP response code
 java.lang.String getContentType()
          gets the content type that will be sent to the browser
 java.lang.String getHeader(java.lang.String name)
          Gets a header based on the name passed in
 java.io.OutputStream getOutputStream()
          gets the OutputStream to send data to the browser
 java.io.PrintWriter getPrintWriter()
          Gets the PrintWriter to send data to the browser
 java.lang.String getServerName()
          gets the name of the server being used
 int getStatusCode()
          gets the HTTP response code
 void reset()
          resets the data to be sent to the browser
 void reset(int code, java.lang.String responseString)
          resets the data to be sent to the browser with the response code and response string
 void setCode(int code)
          sets the HTTP response code to be sent to the browser.
 void setContent(java.net.URLConnection content)
           
 void setContentType(java.lang.String type)
          sets the content type to be sent back to the browser
 void setHeader(java.lang.String name, java.lang.String value)
          sets a header to be sent back to the browser
protected  void setRequest(HttpRequestImpl request)
           
 void setResponseString(java.lang.String responseString)
          Sets the response string to be sent to the browser
 void setStatusCode(int code)
          sets the HTTP response code to be sent to the browser.
 void setStatusMessage(java.lang.String responseString)
          Sets the response string to be sent to the browser
 java.lang.String toString()
          Creates a string version of the response similar to: HTTP/1.1 200 OK
protected  void writeMessage(java.io.OutputStream output)
          Takes care of sending the response line, headers and body HTTP/1.1 200 OK Server: Netscape-Enterprise/3.6 SP3 Date: Thu, 07 Jun 2001 17:30:42 GMT Content-Type: text/html Connection: close
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HTTP_VERSION

public static final java.lang.String HTTP_VERSION
the HTTP version

See Also:
Constant Field Values

CRLF

public static final java.lang.String CRLF
a line feed character

See Also:
Constant Field Values

SP

public static final java.lang.String SP
a space character

See Also:
Constant Field Values

CSP

public static final java.lang.String CSP
a colon and space

See Also:
Constant Field Values

server

public static java.lang.String server
the server to send data from

Constructor Detail

HttpResponseImpl

protected HttpResponseImpl()
creates a new instance of HttpResponseImpl with default values


HttpResponseImpl

protected HttpResponseImpl(int code,
                           java.lang.String responseString,
                           java.lang.String contentType)
Creates a new HttpResponseImpl with user provided parameters

Parameters:
code - the HTTP Response code, see http://www.ietf.org/rfc/rfc2616.txt for these codes
responseString - the response string to be sent back
contentType - the content type to be sent back
Method Detail

setRequest

protected void setRequest(HttpRequestImpl request)

setHeader

public void setHeader(java.lang.String name,
                      java.lang.String value)
sets a header to be sent back to the browser

Specified by:
setHeader in interface HttpResponse
Parameters:
name - the name of the header
value - the value of the header

getHeader

public java.lang.String getHeader(java.lang.String name)
Gets a header based on the name passed in

Specified by:
getHeader in interface HttpResponse
Parameters:
name - The name of the header
Returns:
the value of the header

getPrintWriter

public java.io.PrintWriter getPrintWriter()
Gets the PrintWriter to send data to the browser

Specified by:
getPrintWriter in interface HttpResponse
Returns:
the PrintWriter to send data to the browser

getOutputStream

public java.io.OutputStream getOutputStream()
gets the OutputStream to send data to the browser

Specified by:
getOutputStream in interface HttpResponse
Returns:
the OutputStream to send data to the browser

setCode

public void setCode(int code)
sets the HTTP response code to be sent to the browser. These codes are: OPTIONS = 0 GET = 1 HEAD = 2 POST = 3 PUT = 4 DELETE = 5 TRACE = 6 CONNECT = 7 UNSUPPORTED = 8

Parameters:
code - the code to be sent to the browser

getCode

public int getCode()
gets the HTTP response code

Returns:
the HTTP response code

setContentType

public void setContentType(java.lang.String type)
sets the content type to be sent back to the browser

Specified by:
setContentType in interface HttpResponse
Parameters:
type - the type to be sent to the browser (i.e. "text/html")

getContentType

public java.lang.String getContentType()
gets the content type that will be sent to the browser

Specified by:
getContentType in interface HttpResponse
Returns:
the content type (i.e. "text/html")

setResponseString

public void setResponseString(java.lang.String responseString)
Sets the response string to be sent to the browser

Parameters:
responseString - the response string

reset

public void reset()
resets the data to be sent to the browser


reset

public void reset(int code,
                  java.lang.String responseString)
resets the data to be sent to the browser with the response code and response string

Parameters:
code - the code to be sent to the browser
responseString - the response string to be sent to the browser

writeMessage

protected void writeMessage(java.io.OutputStream output)
                     throws java.io.IOException
Takes care of sending the response line, headers and body HTTP/1.1 200 OK Server: Netscape-Enterprise/3.6 SP3 Date: Thu, 07 Jun 2001 17:30:42 GMT Content-Type: text/html Connection: close

Parameters:
output - the output to send the response to
Throws:
java.io.IOException - if an exception is thrown

toString

public java.lang.String toString()
Creates a string version of the response similar to: HTTP/1.1 200 OK

Overrides:
toString in class java.lang.Object
Returns:
the string value of this HttpResponseImpl

getServerName

public java.lang.String getServerName()
gets the name of the server being used

Returns:
the name of the server

createError

protected static HttpResponseImpl createError(java.lang.String message)
This could be improved at some day in the future to also include a stack trace of the exceptions

Parameters:
message - the error message to be sent
Returns:
the HttpResponseImpl that this error belongs to

createError

protected static HttpResponseImpl createError(java.lang.String message,
                                              java.lang.Throwable t)
creates an error with user defined variables

Parameters:
message - the message of the error
t - a Throwable to print a stack trace to
Returns:
the HttpResponseImpl that this error belongs to

createForbidden

protected static HttpResponseImpl createForbidden(java.lang.String ip)
Creates a forbidden response to be sent to the browser using IP authentication

Parameters:
ip - the ip that is forbidden
Returns:
the HttpResponseImpl that this error belongs to

setContent

public void setContent(java.net.URLConnection content)
Parameters:
content - The content to set.

setStatusCode

public void setStatusCode(int code)
Description copied from interface: HttpResponse
sets the HTTP response code to be sent to the browser. These codes are: OPTIONS = 0 GET = 1 HEAD = 2 POST = 3 PUT = 4 DELETE = 5 TRACE = 6 CONNECT = 7 UNSUPPORTED = 8

Specified by:
setStatusCode in interface HttpResponse
Parameters:
code - the code to be sent to the browser

getStatusCode

public int getStatusCode()
Description copied from interface: HttpResponse
gets the HTTP response code

Specified by:
getStatusCode in interface HttpResponse
Returns:
the HTTP response code

setStatusMessage

public void setStatusMessage(java.lang.String responseString)
Description copied from interface: HttpResponse
Sets the response string to be sent to the browser

Specified by:
setStatusMessage in interface HttpResponse
Parameters:
responseString - the response string


Copyright © 1999-2011 OpenEJB. All Rights Reserved.