Class ServletRestfulResponse
- All Implemented Interfaces:
IRestfulResponse
-
Constructor Summary
ConstructorDescriptionServletRestfulResponse
(ServletRequestDetails servletRequestDetails) Constructor -
Method Summary
Modifier and TypeMethodDescriptionfinal Object
commitResponse
(Closeable theWriterOrOutputStream) Finalizes the response streaming using the writer that was returned by calling eitherIRestfulResponse.getResponseWriter(int, String, String, boolean)
orIRestfulResponse.getResponseOutputStream(int, String, Integer)
.getResponseOutputStream
(int theStatusCode, String theContentType, Integer theContentLength) Initiate a new binary response.getResponseWriter
(int theStatusCode, String theContentType, String theCharset, boolean theRespondGzip) Initiate a new textual response.Methods inherited from class ca.uhn.fhir.rest.server.BaseRestfulResponse
addHeader, getHeaders, getRequestDetails, setRequestDetails
-
Constructor Details
-
ServletRestfulResponse
Constructor
-
-
Method Details
-
getResponseOutputStream
@Nonnull public OutputStream getResponseOutputStream(int theStatusCode, String theContentType, Integer theContentLength) throws IOException Description copied from interface:IRestfulResponse
Initiate a new binary response. The OutputStream returned by this method must be finalized by callingIRestfulResponse.commitResponse(Closeable)
later. This method should only be used for non-textual responses, for those useIRestfulResponse.getResponseWriter(int, String, String, boolean)
.Note that the caller should not close the returned object, but should instead just return it to
IRestfulResponse.commitResponse(Closeable)
upon successful completion. This is different from normal Java practice where you would request it in atry with resource
block, since in Servlets you are not actually required to close the writer/stream, and doing so automatically may prevent you from correctly handling exceptions.- Parameters:
theStatusCode
- The HTTP status code.theContentType
- The HTTP response content type.theContentLength
- If known, the number of bytes that will be written. null otherwise.- Returns:
- Returns an
OutputStream
that can accept the response body. - Throws:
IOException
-
getResponseWriter
@Nonnull public Writer getResponseWriter(int theStatusCode, String theContentType, String theCharset, boolean theRespondGzip) throws IOException Description copied from interface:IRestfulResponse
Initiate a new textual response. The Writer returned by this method must be finalized by callingIRestfulResponse.commitResponse(Closeable)
later.Note that the caller should not close the returned object, but should instead just return it to
IRestfulResponse.commitResponse(Closeable)
upon successful completion. This is different from normal Java practice where you would request it in atry with resource
block, since in Servlets you are not actually required to close the writer/stream, and doing so automatically may prevent you from correctly handling exceptions.- Parameters:
theStatusCode
- The HTTP status code.theContentType
- The HTTP response content type.theCharset
- The HTTP response charset.theRespondGzip
- Should the response be GZip encoded?- Returns:
- Returns a
Writer
that can accept the response body. - Throws:
IOException
-
commitResponse
Description copied from interface:IRestfulResponse
Finalizes the response streaming using the writer that was returned by calling eitherIRestfulResponse.getResponseWriter(int, String, String, boolean)
orIRestfulResponse.getResponseOutputStream(int, String, Integer)
. This method should only be called if the response writing/streaming actually completed successfully. If an error occurred you do not need to commit the response.- Parameters:
theWriterOrOutputStream
- TheWriter
orOutputStream
that was returned by this object, or a Writer/OutputStream which decorates the one returned by this object.- Returns:
- If the server style requires a returned response object (i.e. JAX-RS Server), this method
returns that object. If the server style does not require one (i.e.
RestfulServer
), this method returns null.
-