Class ServletRestfulResponse

java.lang.Object
ca.uhn.fhir.rest.server.BaseRestfulResponse<ServletRequestDetails>
ca.uhn.fhir.rest.server.servlet.ServletRestfulResponse
All Implemented Interfaces:
IRestfulResponse

  • Constructor Details

  • 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 calling IRestfulResponse.commitResponse(Closeable) later. This method should only be used for non-textual responses, for those use IRestfulResponse.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 a try 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 calling IRestfulResponse.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 a try 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

      public final Object commitResponse(@Nonnull Closeable theWriterOrOutputStream)
      Description copied from interface: IRestfulResponse
      Finalizes the response streaming using the writer that was returned by calling either IRestfulResponse.getResponseWriter(int, String, String, boolean) or IRestfulResponse.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 - The Writer or OutputStream 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.