Interface IInterceptorResponse
- All Known Implementing Classes:
ServerServicesInterceptorResponseWrapper
public interface IInterceptorResponse
The
IInterceptorResponse interface defines a contract for manipulating HTTP response data
in an interceptor context. It provides methods for setting status codes, headers, content type,
character encoding, and writing response data, as well as managing the response buffer and state.
Implementations of this interface allow interceptors to inspect, modify, and control HTTP responses in a framework-agnostic manner.
Typical usage includes:
- Setting response status codes and headers
- Writing binary or character data to the response
- Managing response buffer and commit state
- Setting content type and character encoding
- Sending error responses to the client
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a response header with the given name and value.voidForces any content in the buffer to be written to the client.intReturns the actual buffer size used for the responseReturns the name of the character encodingReturns a String that indicates the content-type of the responseReturns the value of the specified request header as a StringGets the names of the headers of this response.getHeaders(String name) Gets the values of the response header with the given name.jakarta.servlet.ServletOutputStreamReturns a ServletOutputStream suitable for writing binary data in the response.intReturns the current status code of this response.Returns a PrintWriter object that can send character text to the client.booleanReturns a boolean indicating if the response has been committed.voidClears the content of the underlying buffer in the response without clearing headers or status code.voidsendError(int sc) Sends an error response to the client using the specified status code and clears the buffer.voidSends an error response to the client using the specified status code and clears the buffer.voidsetContentLength(int len) Sets the length of the content body in the responsevoidsetContentLengthLong(long len) Sets the length of the content body in the responsevoidSets a response header with the given name and value.voidsetStatus(int sc) Sets the status code for this response.
-
Method Details
-
sendError
Sends an error response to the client using the specified status code and clears the buffer.- Parameters:
sc- - the error status codemsg- - the descriptive message- Throws:
IOException- If an input or output exception occurs
-
sendError
Sends an error response to the client using the specified status code and clears the buffer.- Parameters:
sc- - the error status code- Throws:
IOException- If an input or output exception occurs
-
setStatus
void setStatus(int sc) Sets the status code for this response.- Parameters:
sc- - the status code
-
getStatus
int getStatus()Returns the current status code of this response.- Returns:
- the current status code of this response
-
getHeader
Returns the value of the specified request header as a String- Parameters:
name- - the name of the response header whose value to return- Returns:
- the value of the response header with the given name, or null if no header with the given name has been set on this response
-
getHeaders
Gets the values of the response header with the given name.- Parameters:
name- - the name of the response header whose values to return- Returns:
- a Collection of the values of the response header with the given name
-
getHeaderNames
Collection<String> getHeaderNames()Gets the names of the headers of this response.- Returns:
- a Collection of the names of the headers of this response
-
setHeader
Sets a response header with the given name and value. If the header had already been set, the new value overwrites the previous one.- Parameters:
name- - the name of the headervalue- - the header value
-
addHeader
Adds a response header with the given name and value.- Parameters:
name- - the name of the headervalue- - the additional header value
-
getOutputStream
Returns a ServletOutputStream suitable for writing binary data in the response.- Returns:
- a ServletOutputStream for writing binary data
- Throws:
IOException- if the getWriter method has been called on this response
-
getWriter
Returns a PrintWriter object that can send character text to the client.- Returns:
- a PrintWriter object that can return character data to the client
- Throws:
IOException- if an input or output exception occurred
-
flushBuffer
Forces any content in the buffer to be written to the client. A call to this method automatically commits the response, meaning the status code and headers will be written.- Throws:
IOException
-
resetBuffer
void resetBuffer()Clears the content of the underlying buffer in the response without clearing headers or status code. -
getCharacterEncoding
String getCharacterEncoding()Returns the name of the character encoding -
isCommitted
boolean isCommitted()Returns a boolean indicating if the response has been committed. A committed response has already had its status code and headers written.- Returns:
- a boolean indicating if the response has been committed
-
getContentType
String getContentType()Returns a String that indicates the content-type of the response- Returns:
- String that indicates the content-type of the response
-
setContentLength
void setContentLength(int len) Sets the length of the content body in the response- Parameters:
len- - an int specifying the length of the content being returned to the client; sets the Content-Length header
-
setContentLengthLong
void setContentLengthLong(long len) Sets the length of the content body in the response- Parameters:
len- - a long specifying the length of the content being returned to the client; sets the Content-Length header
-
getBufferSize
int getBufferSize()Returns the actual buffer size used for the response- Returns:
- an int specifying the actual buffer size used for the response
-