@RestResource(title="File System Explorer",description="Contents of $RA{path}",messages="nls/DirectoryResource",htmldoc=@HtmlDoc(navlinks={"up: request:/..","options: servlet:/?method=OPTIONS"}),allowedMethodParams="*",properties={@Property(name="HtmlSerializer.uriAnchorText.s",value="PROPERTY_NAME"),@Property(name="DirectoryResource.rootDir",value="")}) public class DirectoryResource extends BasicRestServlet
The root directory is specified in one of two ways:
getRootDir()
method.
Read/write access control is handled through the following properties:
Access can also be controlled by overriding the checkAccess(RestRequest)
method.
Modifier and Type | Class and Description |
---|---|
class |
DirectoryResource.FileResource
File POJO
|
Constructor and Description |
---|
DirectoryResource() |
Modifier and Type | Method and Description |
---|---|
protected void |
checkAccess(RestRequest req)
Verify that the specified request is allowed.
|
Object |
doDelete(RestRequest req)
[DELETE /*] - Delete a file on the file system.
|
Reader |
doDownload(RestRequest req,
RestResponse res)
[DOWNLOAD /*] - Download the contents of a file.
|
Object |
doGet(RestRequest req)
[GET /*] - On directories, returns a directory listing.
|
Object |
doPut(RestRequest req)
[PUT /*] - Add or overwrite a file on the file system.
|
Reader |
doView(RestRequest req,
RestResponse res)
[VIEW /*] - View the contents of a file.
|
protected File |
getRootDir()
Returns the root directory defined by the 'rootDir' init parameter.
|
void |
init() |
getOptions
destroy, getContext, getProperties, getServletConfig, init, log, log, log, log, logObjects, service
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
public DirectoryResource()
public void init() throws javax.servlet.ServletException
init
in class javax.servlet.GenericServlet
javax.servlet.ServletException
protected File getRootDir()
Subclasses can override this method to provide their own root directory.
@RestMethod(name="GET", path="/*", description="On directories, returns a directory listing.\nOn files, returns information about the file.", converters=Queryable.class) public Object doGet(RestRequest req) throws Exception
req
- The HTTP request.Exception
- If file could not be read or access was not granted.@RestMethod(name="DELETE", path="/*", description="Delete a file on the file system.") public Object doDelete(RestRequest req) throws Exception
req
- The HTTP request.Exception
- If file could not be read or access was not granted.@RestMethod(name="PUT", path="/*", description="Add or overwrite a file on the file system.") public Object doPut(RestRequest req) throws Exception
req
- The HTTP request.Exception
- If file could not be read or access was not granted.@RestMethod(name="VIEW", path="/*", description="View the contents of a file.\nApplies to files only.") public Reader doView(RestRequest req, RestResponse res) throws Exception
Applies to files only.
req
- The HTTP request.res
- The HTTP response.Exception
- If file could not be read or access was not granted.@RestMethod(name="DOWNLOAD", path="/*", description="Download the contents of a file.\nApplies to files only.") public Reader doDownload(RestRequest req, RestResponse res) throws Exception
Applies to files only.
req
- The HTTP request.res
- The HTTP response.Exception
- If file could not be read or access was not granted.protected void checkAccess(RestRequest req)
Subclasses can override this method to provide customized behavior.
Method should throw a RestException
if the request should be disallowed.
req
- The HTTP request.Copyright © 2018 Apache. All rights reserved.