Class ResponseTemplate
- java.lang.Object
-
- com.aspectran.core.activity.response.ResponseTemplate
-
- All Implemented Interfaces:
Response,ResponseAdapter,Replicable<Response>
public class ResponseTemplate extends java.lang.Object implements Response, ResponseAdapter
The Class ResponseTemplate.Created: 2020/07/26
-
-
Constructor Summary
Constructors Constructor Description ResponseTemplate(ResponseAdapter responseAdapter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHeader(java.lang.String name, java.lang.String value)Add the given single header value to the current list of values for the given header.voidcommit(Activity activity)The result of the activity is processed into a specific response form and then sent to the client.booleancontainsHeader(java.lang.String name)Returns a boolean indicating whether the named response header has already been set.voidflush()Forces any content in the buffer to be written to the client.<T> TgetAdaptee()Returns the adaptee object to provide response information.java.lang.StringgetContentType()Gets the content type.java.lang.StringgetEncoding()Returns the name of the character encoding (MIME charset) used for the body sent in this response.java.lang.StringgetHeader(java.lang.String name)Returns the value of the response header with the given name.java.util.Collection<java.lang.String>getHeaderNames()Returns the names of the headers of this response.java.util.Collection<java.lang.String>getHeaders(java.lang.String name)Returns the values of the response header with the given name.java.io.OutputStreamgetOutputStream()Returns aOutputStreamsuitable for writing binary data in the response.ResponseTypegetResponseType()Gets the response type.intgetStatus()Returns the status code.java.io.WritergetWriter()Returns aWriterobject that can send character text to the client.java.lang.Stringredirect(RedirectRule redirectRule)Redirects a client to a new URL.voidredirect(java.lang.String location)Sends a temporary redirect response to the client using the specified redirect location.Responsereplicate()Replicates and returns this response.voidsetContentType(java.lang.String contentType)Sets the content type of the response being sent to the client, if the response has not been committed yet.voidsetEncoding(java.lang.String encoding)Sets the character encoding of the response being sent to the client.voidsetHeader(java.lang.String name, java.lang.String value)Set the given single header value under the given header name.voidsetStatus(int status)Sets the status code.
-
-
-
Constructor Detail
-
ResponseTemplate
public ResponseTemplate(@NonNull ResponseAdapter responseAdapter)
-
-
Method Detail
-
commit
public void commit(Activity activity) throws ResponseException
Description copied from interface:ResponseThe result of the activity is processed into a specific response form and then sent to the client.- Specified by:
commitin interfaceResponse- Parameters:
activity- the current Activity- Throws:
ResponseException- the response exception
-
getResponseType
public ResponseType getResponseType()
Description copied from interface:ResponseGets the response type.- Specified by:
getResponseTypein interfaceResponse- Returns:
- the response type
-
getAdaptee
public <T> T getAdaptee()
Description copied from interface:ResponseAdapterReturns the adaptee object to provide response information.- Specified by:
getAdapteein interfaceResponseAdapter- Type Parameters:
T- the type of the adaptee object- Returns:
- the adaptee object
-
getHeader
public java.lang.String getHeader(java.lang.String name)
Description copied from interface:ResponseAdapterReturns the value of the response header with the given name.If a response header with the given name exists and contains multiple values, the value that was added first will be returned.
- Specified by:
getHeaderin interfaceResponseAdapter- Parameters:
name- the name of the response header whose value to return- Returns:
- the value of the response header with the given name,
or
nullif no header with the given name has been set on this response
-
getHeaders
public java.util.Collection<java.lang.String> getHeaders(java.lang.String name)
Description copied from interface:ResponseAdapterReturns the values of the response header with the given name.- Specified by:
getHeadersin interfaceResponseAdapter- Parameters:
name- the name of the response header whose values to return- Returns:
- a (possibly empty)
Collectionof the values of the response header with the given name
-
getHeaderNames
public java.util.Collection<java.lang.String> getHeaderNames()
Description copied from interface:ResponseAdapterReturns the names of the headers of this response.- Specified by:
getHeaderNamesin interfaceResponseAdapter- Returns:
- a (possibly empty)
Collectionof the names of the headers of this response
-
containsHeader
public boolean containsHeader(java.lang.String name)
Description copied from interface:ResponseAdapterReturns a boolean indicating whether the named response header has already been set.- Specified by:
containsHeaderin interfaceResponseAdapter- Parameters:
name- the header name- Returns:
trueif the named response header has already been set;falseotherwise
-
setHeader
public void setHeader(java.lang.String name, java.lang.String value)Description copied from interface:ResponseAdapterSet the given single header value under the given header name. If the header had already been set, the new value overwrites the previous one.- Specified by:
setHeaderin interfaceResponseAdapter- Parameters:
name- the header namevalue- the header value to set
-
addHeader
public void addHeader(java.lang.String name, java.lang.String value)Description copied from interface:ResponseAdapterAdd the given single header value to the current list of values for the given header.- Specified by:
addHeaderin interfaceResponseAdapter- Parameters:
name- the header namevalue- the header value to be added
-
getEncoding
public java.lang.String getEncoding()
Description copied from interface:ResponseAdapterReturns the name of the character encoding (MIME charset) used for the body sent in this response.- Specified by:
getEncodingin interfaceResponseAdapter- Returns:
- a
Stringspecifying the name of the character encoding, for example, UTF-8
-
setEncoding
public void setEncoding(java.lang.String encoding) throws java.io.UnsupportedEncodingExceptionDescription copied from interface:ResponseAdapterSets the character encoding of the response being sent to the client.- Specified by:
setEncodingin interfaceResponseAdapter- Parameters:
encoding- aStringspecifying only the character set defined by IANA Character Sets (http://www.iana.org/assignments/character-sets)- Throws:
java.io.UnsupportedEncodingException- if character encoding is not supported
-
getContentType
public java.lang.String getContentType()
Description copied from interface:ResponseGets the content type.- Specified by:
getContentTypein interfaceResponse- Specified by:
getContentTypein interfaceResponseAdapter- Returns:
- the content type
-
setContentType
public void setContentType(java.lang.String contentType)
Description copied from interface:ResponseAdapterSets the content type of the response being sent to the client, if the response has not been committed yet.- Specified by:
setContentTypein interfaceResponseAdapter- Parameters:
contentType- aStringspecifying the MIME type of the content
-
getOutputStream
public java.io.OutputStream getOutputStream() throws java.io.IOExceptionDescription copied from interface:ResponseAdapterReturns aOutputStreamsuitable for writing binary data in the response.- Specified by:
getOutputStreamin interfaceResponseAdapter- Returns:
- a
OutputStreamfor writing binary data - Throws:
java.io.IOException- if an input or output exception occurs
-
getWriter
public java.io.Writer getWriter() throws java.io.IOExceptionDescription copied from interface:ResponseAdapterReturns aWriterobject that can send character text to the client.- Specified by:
getWriterin interfaceResponseAdapter- Returns:
- a
Writerobject that can return character data to the client - Throws:
java.io.IOException- if an input or output exception occurs
-
flush
public void flush() throws java.io.IOExceptionDescription copied from interface:ResponseAdapterForces any content in the buffer to be written to the client.- Specified by:
flushin interfaceResponseAdapter- Throws:
java.io.IOException- if an input or output exception occurs
-
redirect
public void redirect(java.lang.String location) throws java.io.IOExceptionDescription copied from interface:ResponseAdapterSends a temporary redirect response to the client using the specified redirect location.- Specified by:
redirectin interfaceResponseAdapter- Parameters:
location- the redirect location- Throws:
java.io.IOException- if an input or output exception occurs
-
redirect
public java.lang.String redirect(RedirectRule redirectRule) throws java.io.IOException
Description copied from interface:ResponseAdapterRedirects a client to a new URL.- Specified by:
redirectin interfaceResponseAdapter- Parameters:
redirectRule- the redirect rule- Returns:
- the redirect path
- Throws:
java.io.IOException- if an input or output exception occurs
-
getStatus
public int getStatus()
Description copied from interface:ResponseAdapterReturns the status code.- Specified by:
getStatusin interfaceResponseAdapter- Returns:
- the status
-
setStatus
public void setStatus(int status)
Description copied from interface:ResponseAdapterSets the status code.- Specified by:
setStatusin interfaceResponseAdapter- Parameters:
status- the status code
-
-