Module cloud.piranha.webapp.impl
Package cloud.piranha.webapp.impl
Class DefaultWebApplicationResponse
java.lang.Object
java.io.OutputStream
javax.servlet.ServletOutputStream
cloud.piranha.webapp.impl.DefaultWebApplicationResponse
- All Implemented Interfaces:
WebApplicationResponse
,java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
,HttpServletResponse
,ServletResponse
- Direct Known Subclasses:
DefaultWebApplicationServerResponse
,EmbeddedResponse
,NanoResponse
public class DefaultWebApplicationResponse extends ServletOutputStream implements WebApplicationResponse
The default WebApplicationResponse.
- Author:
- Manfred Riem ([email protected])
-
Field Summary
Fields Modifier and Type Field Description protected boolean
bodyOnly
Stores the body only flag.protected byte[]
buffer
Stores the buffer.protected java.lang.String
characterEncoding
Stores the character encoding.protected boolean
characterEncodingSet
Stores if the character encoding has been set manually.protected boolean
committed
Stores the committed flag.protected long
contentLength
Stores the content length.protected java.lang.String
contentType
Stores the content type.protected boolean
contentTypeSet
Stores if the content type has been set manually.protected java.util.List<Cookie>
cookies
Stores the cookies.protected boolean
gotOutput
Stores if we acquired the output stream.protected boolean
gotWriter
Stores if we acquired the writer.protected DefaultHttpHeaderManager
headerManager
Stores the header manager.protected int
index
Stores the index.protected java.util.Locale
locale
Stores the locale.protected java.io.OutputStream
outputStream
Stores the output stream.protected int
status
Stores the status code.protected java.lang.String
statusMessage
Stores the status message.protected WebApplication
webApplication
Stores the web application.protected java.io.PrintWriter
writer
Stores the writer.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
Constructors Constructor Description DefaultWebApplicationResponse()
Constructor. -
Method Summary
Modifier and Type Method Description void
addCookie(Cookie cookie)
Add the cookie.void
addDateHeader(java.lang.String name, long date)
Add the date header.void
addHeader(java.lang.String name, java.lang.String value)
Add the header.void
addIntHeader(java.lang.String name, int value)
Add the integer header.void
close()
Close the output stream.void
closeAsyncResponse()
boolean
containsHeader(java.lang.String name)
Contains the given header.java.lang.String
encodeRedirectUrl(java.lang.String url)
Deprecated.java.lang.String
encodeRedirectURL(java.lang.String url)
Encode the redirect URL.java.lang.String
encodeUrl(java.lang.String url)
Deprecated.java.lang.String
encodeURL(java.lang.String url)
Encode the URL.void
flush()
Flush the output stream.void
flushBuffer()
Flush the buffer.int
getBufferSize()
Get the buffer size.java.lang.String
getCharacterEncoding()
Get the character encoding.long
getContentLength()
Get the content length.java.lang.String
getContentType()
Get the content type.java.util.Collection<Cookie>
getCookies()
Get the cookies.java.lang.String
getHeader(java.lang.String name)
Get the header.java.util.Collection<java.lang.String>
getHeaderNames()
Get the header names.java.util.Collection<java.lang.String>
getHeaders(java.lang.String name)
Get the headers.java.util.Locale
getLocale()
Get the locale.ServletOutputStream
getOutputStream()
Get the output stream.int
getStatus()
Get the status.java.lang.String
getStatusMessage()
Get the status message.java.io.OutputStream
getUnderlyingOutputStream()
Get the underlying output stream.WebApplication
getWebApplication()
Get the web application.java.io.PrintWriter
getWriter()
Get the writer.boolean
isBodyOnly()
Is body only.boolean
isCommitted()
Is committed.boolean
isReady()
Is the output stream ready?void
reset()
Reset the response.void
resetBuffer()
Reset the buffer.void
sendError(int status)
Send an error.void
sendError(int status, java.lang.String statusMessage)
Send the error.void
sendRedirect(java.lang.String location)
Send the redirect.void
setBodyOnly(boolean bodyOnly)
Set the body only flag.void
setBufferSize(int bufferSize)
Set the buffer size.void
setCharacterEncoding(java.lang.String characterEncoding)
Set the character encoding.void
setCommitted(boolean committed)
Set the committed.void
setContentLength(int contentLength)
Set the content length.void
setContentLengthLong(long contentLength)
Set the content length.void
setContentType(java.lang.String type)
Set the content type.void
setDateHeader(java.lang.String name, long date)
Set the date header.void
setHeader(java.lang.String name, java.lang.String value)
Set the header.void
setIntHeader(java.lang.String name, int value)
Set the int header.void
setLocale(java.util.Locale locale)
Set the locale.void
setOutputStream(ServletOutputStream outputStream)
Set the output stream.void
setStatus(int status)
Set the status.void
setStatus(int status, java.lang.String statusMessage)
Deprecated.void
setUnderlyingOutputStream(java.io.OutputStream outputStream)
Set the underlying output stream.void
setWebApplication(WebApplication webApplication)
Set the web application.void
setWriteListener(WriteListener listener)
Set the write listener.protected void
verifyNotCommitted(java.lang.String methodName)
Verify we are not committed.void
write(int integer)
Write the integer.Methods inherited from class javax.servlet.ServletOutputStream
print, print, print, print, print, print, print, println, println, println, println, println, println, println, println
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface javax.servlet.http.HttpServletResponse
getTrailerFields, setTrailerFields
-
Field Details
-
bodyOnly
protected boolean bodyOnlyStores the body only flag. -
buffer
protected byte[] bufferStores the buffer. -
characterEncoding
protected java.lang.String characterEncodingStores the character encoding. -
characterEncodingSet
protected boolean characterEncodingSetStores if the character encoding has been set manually. -
committed
protected boolean committedStores the committed flag. -
contentLength
protected long contentLengthStores the content length. -
contentType
protected java.lang.String contentTypeStores the content type. -
contentTypeSet
protected boolean contentTypeSetStores if the content type has been set manually. -
cookies
Stores the cookies. -
gotOutput
protected boolean gotOutputStores if we acquired the output stream. -
gotWriter
protected boolean gotWriterStores if we acquired the writer. -
headerManager
Stores the header manager. -
index
protected int indexStores the index. -
locale
protected java.util.Locale localeStores the locale. -
writer
protected java.io.PrintWriter writerStores the writer. -
outputStream
protected java.io.OutputStream outputStreamStores the output stream. -
status
protected int statusStores the status code. -
statusMessage
protected java.lang.String statusMessageStores the status message. -
webApplication
Stores the web application.
-
-
Constructor Details
-
DefaultWebApplicationResponse
public DefaultWebApplicationResponse()Constructor.
-
-
Method Details
-
addCookie
Add the cookie.- Specified by:
addCookie
in interfaceHttpServletResponse
- Parameters:
cookie
- the cookie.
-
addDateHeader
public void addDateHeader(java.lang.String name, long date)Add the date header.- Specified by:
addDateHeader
in interfaceHttpServletResponse
- Parameters:
name
- the header name.date
- the header date value.
-
addHeader
public void addHeader(java.lang.String name, java.lang.String value)Add the header.- Specified by:
addHeader
in interfaceHttpServletResponse
- Parameters:
name
- the name.value
- the value.
-
addIntHeader
public void addIntHeader(java.lang.String name, int value)Add the integer header.- Specified by:
addIntHeader
in interfaceHttpServletResponse
- Parameters:
name
- the name of the header.value
- the value of the header.
-
containsHeader
public boolean containsHeader(java.lang.String name)Contains the given header.- Specified by:
containsHeader
in interfaceHttpServletResponse
- Parameters:
name
- the header name.- Returns:
- true if there, false otherwise.
-
encodeRedirectURL
public java.lang.String encodeRedirectURL(java.lang.String url)Encode the redirect URL.- Specified by:
encodeRedirectURL
in interfaceHttpServletResponse
- Parameters:
url
- the url.- Returns:
- the encoded redirect url.
-
encodeRedirectUrl
@Deprecated public java.lang.String encodeRedirectUrl(java.lang.String url)Deprecated.Encode the redirect url.- Specified by:
encodeRedirectUrl
in interfaceHttpServletResponse
- Parameters:
url
- the url.- Returns:
- the encoded redirect url.
-
encodeURL
public java.lang.String encodeURL(java.lang.String url)Encode the URL.- Specified by:
encodeURL
in interfaceHttpServletResponse
- Parameters:
url
- the URL.- Returns:
- the encoded url.
-
encodeUrl
@Deprecated public java.lang.String encodeUrl(java.lang.String url)Deprecated.Encode the url.- Specified by:
encodeUrl
in interfaceHttpServletResponse
- Parameters:
url
- the url.- Returns:
- the encoded url.
-
flushBuffer
public void flushBuffer() throws java.io.IOExceptionFlush the buffer.- Specified by:
flushBuffer
in interfaceServletResponse
- Throws:
java.io.IOException
- when an I/O error occurs.
-
getCharacterEncoding
public java.lang.String getCharacterEncoding()Get the character encoding.- Specified by:
getCharacterEncoding
in interfaceServletResponse
- Returns:
- the character encoding.
-
getBufferSize
public int getBufferSize()Get the buffer size.- Specified by:
getBufferSize
in interfaceServletResponse
- Returns:
- the buffer size.
-
getContentLength
public long getContentLength()Get the content length.- Returns:
- the content length.
-
getContentType
public java.lang.String getContentType()Get the content type.- Specified by:
getContentType
in interfaceServletResponse
- Returns:
- the content type.
-
getHeader
public java.lang.String getHeader(java.lang.String name)Get the header.- Specified by:
getHeader
in interfaceHttpServletResponse
- Parameters:
name
- the header name.- Returns:
- the value.
-
getHeaderNames
public java.util.Collection<java.lang.String> getHeaderNames()Get the header names.- Specified by:
getHeaderNames
in interfaceHttpServletResponse
- Returns:
- the collection.
-
getHeaders
public java.util.Collection<java.lang.String> getHeaders(java.lang.String name)Get the headers.- Specified by:
getHeaders
in interfaceHttpServletResponse
- Parameters:
name
- the name of the header.- Returns:
- the collection.
-
getLocale
public java.util.Locale getLocale()Get the locale.- Specified by:
getLocale
in interfaceServletResponse
- Returns:
- the locale.
-
getOutputStream
Get the output stream.- Specified by:
getOutputStream
in interfaceServletResponse
- Returns:
- the output stream.
- Throws:
java.io.IOException
- when an I/O error occurs.
-
getStatus
public int getStatus()Get the status.- Specified by:
getStatus
in interfaceHttpServletResponse
- Returns:
- the status.
-
getStatusMessage
public java.lang.String getStatusMessage()Get the status message.- Returns:
- the status message.
-
getWebApplication
Get the web application.- Returns:
- the web application.
-
getWriter
public java.io.PrintWriter getWriter() throws java.io.IOExceptionGet the writer.- Specified by:
getWriter
in interfaceServletResponse
- Returns:
- the writer.
- Throws:
java.io.IOException
- when an I/O error occurs.
-
isBodyOnly
public boolean isBodyOnly()Is body only.- Returns:
- true if we are only sending the body, false otherwise.
-
isCommitted
public boolean isCommitted()Is committed.- Specified by:
isCommitted
in interfaceServletResponse
- Returns:
- the committed flag.
-
reset
public void reset()Reset the response.- Specified by:
reset
in interfaceServletResponse
-
resetBuffer
public void resetBuffer()Reset the buffer.- Specified by:
resetBuffer
in interfaceServletResponse
-
sendError
public void sendError(int status) throws java.io.IOExceptionSend an error.- Specified by:
sendError
in interfaceHttpServletResponse
- Parameters:
status
- the error code.- Throws:
java.io.IOException
- when an I/O error occurs.
-
sendError
public void sendError(int status, java.lang.String statusMessage) throws java.io.IOExceptionSend the error.- Specified by:
sendError
in interfaceHttpServletResponse
- Parameters:
status
- the status code.statusMessage
- the message.- Throws:
java.io.IOException
- when an I/O error occurs.
-
sendRedirect
public void sendRedirect(java.lang.String location) throws java.io.IOExceptionSend the redirect.- Specified by:
sendRedirect
in interfaceHttpServletResponse
- Parameters:
location
- the location.- Throws:
java.io.IOException
- when an I/O error occurs.
-
setBodyOnly
public void setBodyOnly(boolean bodyOnly)Set the body only flag.- Parameters:
bodyOnly
- flag.
-
setBufferSize
public void setBufferSize(int bufferSize)Set the buffer size.- Specified by:
setBufferSize
in interfaceServletResponse
- Parameters:
bufferSize
- the buffer size.
-
setCharacterEncoding
public void setCharacterEncoding(java.lang.String characterEncoding)Set the character encoding.- Specified by:
setCharacterEncoding
in interfaceServletResponse
- Parameters:
characterEncoding
- the character encoding.
-
setCommitted
public void setCommitted(boolean committed)Set the committed.- Parameters:
committed
- the committed flag.
-
setContentLength
public void setContentLength(int contentLength)Set the content length.- Specified by:
setContentLength
in interfaceServletResponse
- Parameters:
contentLength
- the content length.
-
setContentLengthLong
public void setContentLengthLong(long contentLength)Set the content length.- Specified by:
setContentLengthLong
in interfaceServletResponse
- Parameters:
contentLength
- the content length.
-
setContentType
public void setContentType(java.lang.String type)Set the content type.- Specified by:
setContentType
in interfaceServletResponse
- Parameters:
type
- the content type.
-
setDateHeader
public void setDateHeader(java.lang.String name, long date)Set the date header.- Specified by:
setDateHeader
in interfaceHttpServletResponse
- Parameters:
name
- the header name.date
- the date.
-
setHeader
public void setHeader(java.lang.String name, java.lang.String value)Set the header.- Specified by:
setHeader
in interfaceHttpServletResponse
- Parameters:
name
- the name.value
- the value.
-
setIntHeader
public void setIntHeader(java.lang.String name, int value)Set the int header.- Specified by:
setIntHeader
in interfaceHttpServletResponse
- Parameters:
name
- the header name.value
- the header value.
-
setLocale
public void setLocale(java.util.Locale locale)Set the locale.- Specified by:
setLocale
in interfaceServletResponse
- Parameters:
locale
- the locale.
-
setOutputStream
Set the output stream.- Parameters:
outputStream
- the output stream.
-
setStatus
public void setStatus(int status)Set the status.- Specified by:
setStatus
in interfaceHttpServletResponse
- Parameters:
status
- the status code.
-
setStatus
@Deprecated public void setStatus(int status, java.lang.String statusMessage)Deprecated.Set the status.- Specified by:
setStatus
in interfaceHttpServletResponse
- Parameters:
status
- the status.statusMessage
- the message
-
setWebApplication
Set the web application.- Parameters:
webApplication
- the web application.
-
verifyNotCommitted
protected void verifyNotCommitted(java.lang.String methodName)Verify we are not committed.- Parameters:
methodName
- the method we are checking for.
-
getCookies
Get the cookies.- Specified by:
getCookies
in interfaceWebApplicationResponse
- Returns:
- the cookies.
-
getUnderlyingOutputStream
public java.io.OutputStream getUnderlyingOutputStream()Get the underlying output stream.- Specified by:
getUnderlyingOutputStream
in interfaceWebApplicationResponse
- Returns:
- the underlying output stream.
-
setUnderlyingOutputStream
public void setUnderlyingOutputStream(java.io.OutputStream outputStream)Set the underlying output stream.- Specified by:
setUnderlyingOutputStream
in interfaceWebApplicationResponse
- Parameters:
outputStream
- the underlying output stream.
-
closeAsyncResponse
public void closeAsyncResponse()- Specified by:
closeAsyncResponse
in interfaceWebApplicationResponse
-
close
public void close() throws java.io.IOExceptionClose the output stream.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
- when an I/O error occurs.
-
flush
public void flush() throws java.io.IOExceptionFlush the output stream.- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
- Throws:
java.io.IOException
- when an I/O error occurs.
-
isReady
public boolean isReady()Is the output stream ready?- Specified by:
isReady
in classServletOutputStream
- Returns:
- true if it is, false otherwise.
-
setWriteListener
Set the write listener.- Specified by:
setWriteListener
in classServletOutputStream
- Parameters:
listener
- the write listener.
-
write
public void write(int integer) throws java.io.IOExceptionWrite the integer.- Specified by:
write
in classjava.io.OutputStream
- Parameters:
integer
- the integer.- Throws:
java.io.IOException
- when an I/O error occurs.
-