org.apache.openejb.server.httpd
Class HttpResponseImpl

java.lang.Object
  extended by org.apache.openejb.server.httpd.HttpResponseImpl
All Implemented Interfaces:
Serializable, javax.servlet.http.HttpServletResponse, javax.servlet.ServletResponse, HttpResponse

public class HttpResponseImpl
extends Object
implements HttpResponse

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

See Also:
Serialized Form

Field Summary
static String CRLF
          a line feed character
static String CSP
          a colon and space
static String HTTP_VERSION
          the HTTP version
static String server
          the server to send data from
static String SP
          a space character
 
Fields inherited from interface javax.servlet.http.HttpServletResponse
SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CONFLICT, SC_CONTINUE, SC_CREATED, SC_EXPECTATION_FAILED, SC_FORBIDDEN, SC_FOUND, SC_GATEWAY_TIMEOUT, SC_GONE, SC_HTTP_VERSION_NOT_SUPPORTED, SC_INTERNAL_SERVER_ERROR, SC_LENGTH_REQUIRED, SC_METHOD_NOT_ALLOWED, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_MULTIPLE_CHOICES, SC_NO_CONTENT, SC_NON_AUTHORITATIVE_INFORMATION, SC_NOT_ACCEPTABLE, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_PARTIAL_CONTENT, SC_PAYMENT_REQUIRED, SC_PRECONDITION_FAILED, SC_PROXY_AUTHENTICATION_REQUIRED, SC_REQUEST_ENTITY_TOO_LARGE, SC_REQUEST_TIMEOUT, SC_REQUEST_URI_TOO_LONG, SC_REQUESTED_RANGE_NOT_SATISFIABLE, SC_RESET_CONTENT, SC_SEE_OTHER, SC_SERVICE_UNAVAILABLE, SC_SWITCHING_PROTOCOLS, SC_TEMPORARY_REDIRECT, SC_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE, SC_USE_PROXY
 
Constructor Summary
protected HttpResponseImpl()
          creates a new instance of HttpResponseImpl with default values
protected HttpResponseImpl(int code, String responseString, String contentType)
          Creates a new HttpResponseImpl with user provided parameters
 
Method Summary
 void addCookie(javax.servlet.http.Cookie cookie)
           
 void addDateHeader(String s, long l)
           
 void addHeader(String s, String s1)
           
 void addIntHeader(String s, int i)
           
 boolean containsHeader(String s)
           
protected static HttpResponseImpl createError(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(String message, Throwable t)
          creates an error with user defined variables
protected static HttpResponseImpl createForbidden(String ip)
          Creates a forbidden response to be sent to the browser using IP authentication
 String encodeRedirectUrl(String s)
           
 String encodeRedirectURL(String s)
           
 String encodeUrl(String s)
           
 String encodeURL(String s)
           
 void flushBuffer()
          Flushes the output buffer to the client.
 int getBufferSize()
           
 String getCharacterEncoding()
           
 int getCode()
          gets the HTTP response code
 String getContentType()
          gets the content type that will be sent to the browser
 String getHeader(String name)
          Gets a header based on the name passed in
 Collection<String> getHeaderNames()
           
 Collection<String> getHeaders(String s)
           
 Locale getLocale()
           
 javax.servlet.ServletOutputStream getOutputStream()
          gets the OutputStream to send data to the browser
 String getServerName()
          gets the name of the server being used
 int getStatus()
           
 PrintWriter getWriter()
           
 boolean isCommitted()
           
 void reset()
          resets the data to be sent to the browser
 void reset(int code, String responseString)
          resets the data to be sent to the browser with the response code and response string
 void resetBuffer()
           
 void sendError(int i)
           
 void sendError(int i, String s)
           
 void sendRedirect(String s)
           
 void setBufferSize(int i)
           
 void setCharacterEncoding(String s)
           
 void setCode(int code)
          sets the HTTP response code to be sent to the browser.
 void setContent(URLConnection content)
           
 void setContentLength(int i)
           
 void setContentType(String type)
          sets the content type to be sent back to the browser
 void setDateHeader(String s, long l)
           
 void setHeader(String name, String value)
          sets a header to be sent back to the browser
 void setIntHeader(String s, int i)
           
 void setLocale(Locale loc)
           
protected  void setRequest(HttpRequestImpl request)
           
 void setResponseString(String responseString)
          Sets the response string to be sent to the browser
 void setStatus(int i)
           
 void setStatus(int i, String s)
           
 void setStatusMessage(String responseString)
          Sets the response string to be sent to the browser
 String toString()
          Creates a string version of the response similar to:

HTTP/1.1 200 OK

protected  void writeMessage(OutputStream output, boolean indent)
          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 String HTTP_VERSION
the HTTP version

See Also:
Constant Field Values

CRLF

public static final String CRLF
a line feed character

See Also:
Constant Field Values

SP

public static final String SP
a space character

See Also:
Constant Field Values

CSP

public static final String CSP
a colon and space

See Also:
Constant Field Values

server

public static 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,
                           String responseString,
                           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(String name,
                      String value)
sets a header to be sent back to the browser

Specified by:
setHeader in interface javax.servlet.http.HttpServletResponse
Parameters:
name - the name of the header
value - the value of the header

setIntHeader

public void setIntHeader(String s,
                         int i)
Specified by:
setIntHeader in interface javax.servlet.http.HttpServletResponse

setStatus

public void setStatus(int i)
Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse

setStatus

public void setStatus(int i,
                      String s)
Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse

addCookie

public void addCookie(javax.servlet.http.Cookie cookie)
Specified by:
addCookie in interface javax.servlet.http.HttpServletResponse

addDateHeader

public void addDateHeader(String s,
                          long l)
Specified by:
addDateHeader in interface javax.servlet.http.HttpServletResponse

addHeader

public void addHeader(String s,
                      String s1)
Specified by:
addHeader in interface javax.servlet.http.HttpServletResponse

addIntHeader

public void addIntHeader(String s,
                         int i)
Specified by:
addIntHeader in interface javax.servlet.http.HttpServletResponse

containsHeader

public boolean containsHeader(String s)
Specified by:
containsHeader in interface javax.servlet.http.HttpServletResponse

encodeURL

public String encodeURL(String s)
Specified by:
encodeURL in interface javax.servlet.http.HttpServletResponse

encodeRedirectURL

public String encodeRedirectURL(String s)
Specified by:
encodeRedirectURL in interface javax.servlet.http.HttpServletResponse

encodeUrl

public String encodeUrl(String s)
Specified by:
encodeUrl in interface javax.servlet.http.HttpServletResponse

encodeRedirectUrl

public String encodeRedirectUrl(String s)
Specified by:
encodeRedirectUrl in interface javax.servlet.http.HttpServletResponse

getHeader

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

Specified by:
getHeader in interface javax.servlet.http.HttpServletResponse
Parameters:
name - The name of the header
Returns:
the value of the header

getHeaderNames

public Collection<String> getHeaderNames()
Specified by:
getHeaderNames in interface javax.servlet.http.HttpServletResponse

getHeaders

public Collection<String> getHeaders(String s)
Specified by:
getHeaders in interface javax.servlet.http.HttpServletResponse

getStatus

public int getStatus()
Specified by:
getStatus in interface javax.servlet.http.HttpServletResponse

sendError

public void sendError(int i)
               throws IOException
Specified by:
sendError in interface javax.servlet.http.HttpServletResponse
Throws:
IOException

sendError

public void sendError(int i,
                      String s)
               throws IOException
Specified by:
sendError in interface javax.servlet.http.HttpServletResponse
Throws:
IOException

sendRedirect

public void sendRedirect(String s)
                  throws IOException
Specified by:
sendRedirect in interface javax.servlet.http.HttpServletResponse
Throws:
IOException

setDateHeader

public void setDateHeader(String s,
                          long l)
Specified by:
setDateHeader in interface javax.servlet.http.HttpServletResponse

getOutputStream

public javax.servlet.ServletOutputStream getOutputStream()
gets the OutputStream to send data to the browser

Specified by:
getOutputStream in interface javax.servlet.ServletResponse
Returns:
the OutputStream to send data to the browser

getWriter

public PrintWriter getWriter()
                      throws IOException
Specified by:
getWriter in interface javax.servlet.ServletResponse
Throws:
IOException

isCommitted

public boolean isCommitted()
Specified by:
isCommitted in interface javax.servlet.ServletResponse

flushBuffer

public void flushBuffer()
                 throws IOException
Description copied from interface: HttpResponse
Flushes the output buffer to the client.

Specified by:
flushBuffer in interface javax.servlet.ServletResponse
Specified by:
flushBuffer in interface HttpResponse
Throws:
IOException

getBufferSize

public int getBufferSize()
Specified by:
getBufferSize in interface javax.servlet.ServletResponse

getCharacterEncoding

public String getCharacterEncoding()
Specified by:
getCharacterEncoding in interface javax.servlet.ServletResponse

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(String type)
sets the content type to be sent back to the browser

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

setLocale

public void setLocale(Locale loc)
Specified by:
setLocale in interface javax.servlet.ServletResponse

getContentType

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

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

getLocale

public Locale getLocale()
Specified by:
getLocale in interface javax.servlet.ServletResponse

setResponseString

public void setResponseString(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

Specified by:
reset in interface javax.servlet.ServletResponse

resetBuffer

public void resetBuffer()
Specified by:
resetBuffer in interface javax.servlet.ServletResponse

setBufferSize

public void setBufferSize(int i)
Specified by:
setBufferSize in interface javax.servlet.ServletResponse

setCharacterEncoding

public void setCharacterEncoding(String s)
Specified by:
setCharacterEncoding in interface javax.servlet.ServletResponse

setContentLength

public void setContentLength(int i)
Specified by:
setContentLength in interface javax.servlet.ServletResponse

reset

public void reset(int code,
                  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(OutputStream output,
                            boolean indent)
                     throws 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:
IOException - if an exception is thrown

toString

public String toString()
Creates a string version of the response similar to:

HTTP/1.1 200 OK

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

getServerName

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

Returns:
the name of the server

createError

protected static HttpResponseImpl createError(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(String message,
                                              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(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(URLConnection content)
Parameters:
content - The content to set.

setStatusMessage

public void setStatusMessage(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–2015 The Apache Software Foundation. All rights reserved.