Class ResourceRestEndpoint

    • Field Detail

      • resource

        protected String resource
        Path to embedded resource to serve.
    • Constructor Detail

      • ResourceRestEndpoint

        public ResourceRestEndpoint​(String uri,
                                    String resource)
        Creates a static resource end-point that responds to given URI and serves given resource.
        Parameters:
        uri - the end-point URI, cannot be null.
        resource - the resource to serve, cannot be null.
      • ResourceRestEndpoint

        public ResourceRestEndpoint​(String uri,
                                    String resource,
                                    String mimetype)
        Creates a static resource end-point that responds to given URI and serves given resource.
        Parameters:
        uri - the end-point URI, cannot be null.
        resource - the resource to serve, cannot be null.
        mimetype - the mime type of the resource, if null, the mimetype will be computed.
        See Also:
        MIMEUtils#getMIMEType(String)
    • Method Detail

      • getResourceAsStream

        protected InputStream getResourceAsStream()
        Gets the resource to serve as an input stream.
        Returns:
        an input stream on the resource to serve, or null if resource is not found.
      • getResourceResponse

        protected HTTPResponse getResourceResponse()
        Gets the resource to serve as an HTTP response. By default, it serves embedded resource with application/octet-stream content type.
        Returns:
        the HTTP response corresponding to the resource to serve.
        See Also:
        MIMEUtils#MIME_DEFAULT_BINARY
      • get

        public HTTPResponse get​(HTTPRequest request,
                                Map<String,​String> headers,
                                Map<String,​String> parameters)
        Description copied from class: RestEndpoint
        Handles GET request on this endpoint.

        Default implementation return a a status code 501

        Overrides:
        get in class RestEndpoint
        Parameters:
        request - the request to handle.
        headers - request headers.
        parameters - parsed query and body parameters.
        Returns:
        an HTTP response.
      • getMimetype

        public String getMimetype()
        Gets the mimetype.
        Returns:
        the mimetype, can be null.
      • setMimetype

        public void setMimetype​(String mimetype)
        Sets the mimetype.
        Parameters:
        mimetype - the mimetype to set, if null, the type will be computed.
        See Also:
        MIMEUtils#getMIMEType(String)