Package ej.restserver.endpoint
Class ResourceRestEndpoint
- java.lang.Object
-
- ej.restserver.RestEndpoint
-
- ej.restserver.endpoint.ResourceRestEndpoint
-
- Direct Known Subclasses:
GzipResourceEndpoint
public class ResourceRestEndpoint extends RestEndpoint
A static resource end-point to serve all kind of files.
-
-
Field Summary
Fields Modifier and Type Field Description protected StringresourcePath to embedded resource to serve.-
Fields inherited from class ej.restserver.RestEndpoint
uri
-
-
Constructor Summary
Constructors Constructor Description ResourceRestEndpoint(String uri, String resource)Creates a static resource end-point that responds to given URI and serves given resource.ResourceRestEndpoint(String uri, String resource, String mimetype)Creates a static resource end-point that responds to given URI and serves given resource.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HTTPResponseget(HTTPRequest request, Map<String,String> headers, Map<String,String> parameters)HandlesGETrequest on this endpoint.StringgetMimetype()Gets the mimetype.protected InputStreamgetResourceAsStream()Gets the resource to serve as an input stream.protected HTTPResponsegetResourceResponse()Gets the resource to serve as an HTTP response.voidsetMimetype(String mimetype)Sets the mimetype.-
Methods inherited from class ej.restserver.RestEndpoint
delete, getURI, post, put
-
-
-
-
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 benull.resource- the resource to serve, cannot benull.
-
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 benull.resource- the resource to serve, cannot benull.mimetype- the mime type of the resource, ifnull, 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
nullif resource is not found.
-
getResourceResponse
protected HTTPResponse getResourceResponse()
Gets the resource to serve as an HTTP response. By default, it serves embedded resource withapplication/octet-streamcontent 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:RestEndpointHandlesGETrequest on this endpoint.Default implementation return a a status code
501- Overrides:
getin classRestEndpoint- 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, ifnull, the type will be computed.- See Also:
MIMEUtils#getMIMEType(String)
-
-