Class RestOutput


  • public class RestOutput
    extends java.lang.Object
    Output for a call to the REST API of Orthanc
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected RestOutput​(long self)
      Construct a Java object wrapping a C object that is managed by Orthanc.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void answerBuffer​(byte[] answer, java.lang.String mimeType)
      Answer to a REST request.
      void compressAndAnswerJpegImage​(PixelFormat format, int width, int height, int pitch, byte[] buffer, byte quality)
      Answer to a REST request with a JPEG image.
      void compressAndAnswerPngImage​(PixelFormat format, int width, int height, int pitch, byte[] buffer)
      Answer to a REST request with a PNG image.
      protected long getSelf()
      Return the C object that is associated with this Java wrapper.
      void redirect​(java.lang.String redirection)
      Redirect a REST request.
      void sendHttpStatus​(short status, byte[] body)
      Send a HTTP status, with a custom body.
      void sendHttpStatusCode​(short status)
      Send a HTTP status code.
      void sendMethodNotAllowed​(java.lang.String allowedMethods)
      Signal that this URI does not support this HTTP method.
      void sendMultipartItem​(byte[] answer)
      Send an item as a part of some HTTP multipart answer.
      void sendUnauthorized​(java.lang.String realm)
      Signal that a REST request is not authorized.
      void setCookie​(java.lang.String cookie, java.lang.String value)
      Set a cookie.
      void setHttpErrorDetails​(java.lang.String details, byte log)
      Provide a detailed description for an HTTP error.
      void setHttpHeader​(java.lang.String key, java.lang.String value)
      Set some HTTP header.
      void startMultipartAnswer​(java.lang.String subType, java.lang.String contentType)
      Start an HTTP multipart answer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RestOutput

        protected RestOutput​(long self)
        Construct a Java object wrapping a C object that is managed by Orthanc.
        Parameters:
        self - Pointer to the C object.
    • Method Detail

      • getSelf

        protected long getSelf()
        Return the C object that is associated with this Java wrapper.
        Returns:
        Pointer to the C object.
      • answerBuffer

        public void answerBuffer​(byte[] answer,
                                 java.lang.String mimeType)
        Answer to a REST request. This function answers to a REST request with the content of a memory buffer.
        Parameters:
        answer - Pointer to the memory buffer containing the answer.
        mimeType - The MIME type of the answer.
      • compressAndAnswerPngImage

        public void compressAndAnswerPngImage​(PixelFormat format,
                                              int width,
                                              int height,
                                              int pitch,
                                              byte[] buffer)
        Answer to a REST request with a PNG image. This function answers to a REST request with a PNG image. The parameters of this function describe a memory buffer that contains an uncompressed image. The image will be automatically compressed as a PNG image by the core system of Orthanc.
        Parameters:
        format - The memory layout of the uncompressed image.
        width - The width of the image.
        height - The height of the image.
        pitch - The pitch of the image (i.e. the number of bytes between 2 successive lines of the image in the memory buffer).
        buffer - The memory buffer containing the uncompressed image.
      • redirect

        public void redirect​(java.lang.String redirection)
        Redirect a REST request. This function answers to a REST request by redirecting the user to another URI using HTTP status 301.
        Parameters:
        redirection - Where to redirect.
      • sendHttpStatusCode

        public void sendHttpStatusCode​(short status)
        Send a HTTP status code. This function answers to a REST request by sending a HTTP status code (such as "400 - Bad Request"). Note that: - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer(). - Redirections (status 301) must use ::OrthancPluginRedirect(). - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized(). - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed().
        Parameters:
        status - The HTTP status code to be sent.
      • sendUnauthorized

        public void sendUnauthorized​(java.lang.String realm)
        Signal that a REST request is not authorized. This function answers to a REST request by signaling that it is not authorized.
        Parameters:
        realm - The realm for the authorization process.
      • sendMethodNotAllowed

        public void sendMethodNotAllowed​(java.lang.String allowedMethods)
        Signal that this URI does not support this HTTP method. This function answers to a REST request by signaling that the queried URI does not support this method.
        Parameters:
        allowedMethods - The allowed methods for this URI (e.g. "GET,POST" after a PUT or a POST request).
      • setCookie

        public void setCookie​(java.lang.String cookie,
                              java.lang.String value)
        Set a cookie. This function sets a cookie in the HTTP client.
        Parameters:
        cookie - The cookie to be set.
        value - The value of the cookie.
      • setHttpHeader

        public void setHttpHeader​(java.lang.String key,
                                  java.lang.String value)
        Set some HTTP header. This function sets a HTTP header in the HTTP answer.
        Parameters:
        key - The HTTP header to be set.
        value - The value of the HTTP header.
      • startMultipartAnswer

        public void startMultipartAnswer​(java.lang.String subType,
                                         java.lang.String contentType)
        Start an HTTP multipart answer. Initiates a HTTP multipart answer, as the result of a REST request.
        Parameters:
        subType - The sub-type of the multipart answer ("mixed" or "related").
        contentType - The MIME type of the items in the multipart answer.
      • sendMultipartItem

        public void sendMultipartItem​(byte[] answer)
        Send an item as a part of some HTTP multipart answer. This function sends an item as a part of some HTTP multipart answer that was initiated by OrthancPluginStartMultipartAnswer().
        Parameters:
        answer - Pointer to the memory buffer containing the item.
      • sendHttpStatus

        public void sendHttpStatus​(short status,
                                   byte[] body)
        Send a HTTP status, with a custom body. This function answers to a HTTP request by sending a HTTP status code (such as "400 - Bad Request"), together with a body describing the error. The body will only be returned if the configuration option "HttpDescribeErrors" of Orthanc is set to "true". Note that: - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer(). - Redirections (status 301) must use ::OrthancPluginRedirect(). - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized(). - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed().
        Parameters:
        status - The HTTP status code to be sent.
        body - The body of the answer.
      • compressAndAnswerJpegImage

        public void compressAndAnswerJpegImage​(PixelFormat format,
                                               int width,
                                               int height,
                                               int pitch,
                                               byte[] buffer,
                                               byte quality)
        Answer to a REST request with a JPEG image. This function answers to a REST request with a JPEG image. The parameters of this function describe a memory buffer that contains an uncompressed image. The image will be automatically compressed as a JPEG image by the core system of Orthanc.
        Parameters:
        format - The memory layout of the uncompressed image.
        width - The width of the image.
        height - The height of the image.
        pitch - The pitch of the image (i.e. the number of bytes between 2 successive lines of the image in the memory buffer).
        buffer - The memory buffer containing the uncompressed image.
        quality - The quality of the JPEG encoding, between 1 (worst quality, best compression) and 100 (best quality, worst compression).
      • setHttpErrorDetails

        public void setHttpErrorDetails​(java.lang.String details,
                                        byte log)
        Provide a detailed description for an HTTP error. This function sets the detailed description associated with an HTTP error. This description will be displayed in the "Details" field of the JSON body of the HTTP answer. It is only taken into consideration if the REST callback returns an error code that is different from "OrthancPluginErrorCode_Success", and if the "HttpDescribeErrors" configuration option of Orthanc is set to "true".
        Parameters:
        details - The details of the error message.
        log - Whether to also write the detailed error to the Orthanc logs.