Package org.apache.openejb.server.httpd
Class HttpResponseImpl
java.lang.Object
org.apache.openejb.server.httpd.HttpResponseImpl
- All Implemented Interfaces:
jakarta.servlet.http.HttpServletResponse,jakarta.servlet.ServletResponse,Serializable,HttpResponse
This class takes care of HTTP Responses. It sends data back to the browser.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringa line feed characterstatic final Stringa colon and spacestatic final Stringthe HTTP versionstatic Stringthe server to send data fromstatic final Stringa space characterFields inherited from interface jakarta.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
ConstructorsModifierConstructorDescriptionprotectedcreates a new instance of HttpResponseImpl with default valuesprotectedHttpResponseImpl(int code, String responseString, String contentType) Creates a new HttpResponseImpl with user provided parameters -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCookie(jakarta.servlet.http.Cookie cookie) voidaddDateHeader(String s, long l) voidvoidaddIntHeader(String s, int i) booleanprotected static HttpResponseImplcreateError(String message) This could be improved at some day in the future to also include a stack trace of the exceptionsprotected static HttpResponseImplcreateError(String message, Throwable t) creates an error with user defined variablesprotected static HttpResponseImplCreates a forbidden response to be sent to the browser using IP authenticationvoidFlushes the output buffer to the client.intintgetCode()gets the HTTP response codegets the content type that will be sent to the browserGets a header based on the name passed ingetHeaders(String s) jakarta.servlet.ServletOutputStreamgets the OutputStream to send data to the browsergets the name of the server being usedintbooleanvoidreset()resets the data to be sent to the browservoidresets the data to be sent to the browser with the response code and response stringvoidvoidsendError(int i) voidvoidsendRedirect(String path) voidsetBufferSize(int i) voidvoidsetCode(int code) sets the HTTP response code to be sent to the browser.voidsetContent(URLConnection content) voidsetContentLength(int i) voidsetContentLengthLong(long length) voidsetContentType(String type) sets the content type to be sent back to the browservoidsetDateHeader(String s, long l) voidsets a header to be sent back to the browservoidsetIntHeader(String s, int i) voidprotected voidsetRequest(HttpRequestImpl request) voidsetResponseString(String responseString) Sets the response string to be sent to the browservoidsetStatus(int i) voidsetStatusMessage(String responseString) Sets the response string to be sent to the browsertoString()Creates a string version of the response similar to: HTTP/1.1 200 OKprotected voidwriteMessage(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: closeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface jakarta.servlet.http.HttpServletResponse
getTrailerFields, setTrailerFields
-
Field Details
-
HTTP_VERSION
the HTTP version- See Also:
-
CRLF
a line feed character- See Also:
-
SP
a space character- See Also:
-
CSP
a colon and space- See Also:
-
server
the server to send data from
-
-
Constructor Details
-
HttpResponseImpl
protected HttpResponseImpl()creates a new instance of HttpResponseImpl with default values -
HttpResponseImpl
Creates a new HttpResponseImpl with user provided parameters- Parameters:
code- the HTTP Response code, see http://www.ietf.org/rfc/rfc2616.txt for these codesresponseString- the response string to be sent backcontentType- the content type to be sent back
-
-
Method Details
-
setRequest
-
setHeader
sets a header to be sent back to the browser- Specified by:
setHeaderin interfacejakarta.servlet.http.HttpServletResponse- Parameters:
name- the name of the headervalue- the value of the header
-
setIntHeader
- Specified by:
setIntHeaderin interfacejakarta.servlet.http.HttpServletResponse
-
setStatus
public void setStatus(int i) - Specified by:
setStatusin interfacejakarta.servlet.http.HttpServletResponse
-
addCookie
public void addCookie(jakarta.servlet.http.Cookie cookie) - Specified by:
addCookiein interfacejakarta.servlet.http.HttpServletResponse
-
addDateHeader
- Specified by:
addDateHeaderin interfacejakarta.servlet.http.HttpServletResponse
-
addHeader
- Specified by:
addHeaderin interfacejakarta.servlet.http.HttpServletResponse
-
addIntHeader
- Specified by:
addIntHeaderin interfacejakarta.servlet.http.HttpServletResponse
-
containsHeader
- Specified by:
containsHeaderin interfacejakarta.servlet.http.HttpServletResponse
-
encodeURL
- Specified by:
encodeURLin interfacejakarta.servlet.http.HttpServletResponse
-
encodeRedirectURL
- Specified by:
encodeRedirectURLin interfacejakarta.servlet.http.HttpServletResponse
-
getHeader
Gets a header based on the name passed in- Specified by:
getHeaderin interfacejakarta.servlet.http.HttpServletResponse- Parameters:
name- The name of the header- Returns:
- the value of the header
-
getHeaderNames
- Specified by:
getHeaderNamesin interfacejakarta.servlet.http.HttpServletResponse
-
getHeaders
- Specified by:
getHeadersin interfacejakarta.servlet.http.HttpServletResponse
-
getStatus
public int getStatus()- Specified by:
getStatusin interfacejakarta.servlet.http.HttpServletResponse
-
sendError
- Specified by:
sendErrorin interfacejakarta.servlet.http.HttpServletResponse- Throws:
IOException
-
sendError
- Specified by:
sendErrorin interfacejakarta.servlet.http.HttpServletResponse- Throws:
IOException
-
sendRedirect
- Specified by:
sendRedirectin interfacejakarta.servlet.http.HttpServletResponse- Throws:
IOException
-
setDateHeader
- Specified by:
setDateHeaderin interfacejakarta.servlet.http.HttpServletResponse
-
getOutputStream
public jakarta.servlet.ServletOutputStream getOutputStream()gets the OutputStream to send data to the browser- Specified by:
getOutputStreamin interfacejakarta.servlet.ServletResponse- Returns:
- the OutputStream to send data to the browser
-
getWriter
- Specified by:
getWriterin interfacejakarta.servlet.ServletResponse- Throws:
IOException
-
isCommitted
public boolean isCommitted()- Specified by:
isCommittedin interfacejakarta.servlet.ServletResponse
-
flushBuffer
Description copied from interface:HttpResponseFlushes the output buffer to the client.- Specified by:
flushBufferin interfaceHttpResponse- Specified by:
flushBufferin interfacejakarta.servlet.ServletResponse- Throws:
IOException
-
getBufferSize
public int getBufferSize()- Specified by:
getBufferSizein interfacejakarta.servlet.ServletResponse
-
getCharacterEncoding
- Specified by:
getCharacterEncodingin interfacejakarta.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
sets the content type to be sent back to the browser- Specified by:
setContentTypein interfaceHttpResponse- Specified by:
setContentTypein interfacejakarta.servlet.ServletResponse- Parameters:
type- the type to be sent to the browser (i.e. "text/html")
-
setLocale
- Specified by:
setLocalein interfacejakarta.servlet.ServletResponse
-
getContentType
gets the content type that will be sent to the browser- Specified by:
getContentTypein interfaceHttpResponse- Specified by:
getContentTypein interfacejakarta.servlet.ServletResponse- Returns:
- the content type (i.e. "text/html")
-
getLocale
- Specified by:
getLocalein interfacejakarta.servlet.ServletResponse
-
setResponseString
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:
resetin interfacejakarta.servlet.ServletResponse
-
resetBuffer
public void resetBuffer()- Specified by:
resetBufferin interfacejakarta.servlet.ServletResponse
-
setBufferSize
public void setBufferSize(int i) - Specified by:
setBufferSizein interfacejakarta.servlet.ServletResponse
-
setCharacterEncoding
- Specified by:
setCharacterEncodingin interfacejakarta.servlet.ServletResponse
-
setContentLength
public void setContentLength(int i) - Specified by:
setContentLengthin interfacejakarta.servlet.ServletResponse
-
setContentLengthLong
public void setContentLengthLong(long length) - Specified by:
setContentLengthLongin interfacejakarta.servlet.ServletResponse
-
reset
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 browserresponseString- the response string to be sent to the browser
-
writeMessage
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
Creates a string version of the response similar to: HTTP/1.1 200 OK -
getServerName
gets the name of the server being used- Returns:
- the name of the server
-
createError
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
creates an error with user defined variables- Parameters:
message- the message of the errort- a Throwable to print a stack trace to- Returns:
- the HttpResponseImpl that this error belongs to
-
createForbidden
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
- Parameters:
content- The content to set.
-
setStatusMessage
Description copied from interface:HttpResponseSets the response string to be sent to the browser- Specified by:
setStatusMessagein interfaceHttpResponse- Parameters:
responseString- the response string
-