Search in sources :

Example 1 with SimpleFileContentService

use of io.milton.http.fs.SimpleFileContentService in project lobcder by skoulouzis.

the class MemoryLockManagerTest method testLockUnLock.

public void testLockUnLock() throws NotAuthorizedException {
    LockTimeout timeout = new LockTimeout(100l);
    LockInfo lockInfo = new LockInfo(LockInfo.LockScope.NONE, LockInfo.LockType.READ, "me", LockInfo.LockDepth.ZERO);
    SimpleFileContentService contentService = new SimpleFileContentService();
    FsResource resource = new FsFileResource(null, null, new File(File.pathSeparator), contentService);
    // lock it
    LockResult res = lockManager.lock(timeout, lockInfo, resource);
    assertNotNull(res);
    assertTrue(res.isSuccessful());
    // check is locked
    LockToken token = lockManager.getCurrentToken(resource);
    assertNotNull(token);
    assertEquals(token.tokenId, res.getLockToken().tokenId);
    // unlock
    lockManager.unlock(token.tokenId, resource);
    // check removed
    token = lockManager.getCurrentToken(resource);
    assertNull(token);
}
Also used : FsResource(io.milton.http.fs.FsResource) LockResult(io.milton.http.LockResult) FsFileResource(io.milton.http.fs.FsFileResource) LockToken(io.milton.http.LockToken) LockInfo(io.milton.http.LockInfo) SimpleFileContentService(io.milton.http.fs.SimpleFileContentService) File(java.io.File) LockTimeout(io.milton.http.LockTimeout)

Example 2 with SimpleFileContentService

use of io.milton.http.fs.SimpleFileContentService in project lobcder by skoulouzis.

the class RestletFileserver method main.

public static void main(String[] args) throws Exception {
    Component component = new Component();
    component.getServers().add(Protocol.HTTP, 8080);
    // Restlet logs requests by default
    // component.getLogService().setEnabled(false);
    component.getDefaultHost().attach(new Application() {

        @Override
        public Restlet createInboundRoot() {
            FileSystemResourceFactory factory = new FileSystemResourceFactory(new File(System.getProperty("user.home")), new NullSecurityManager());
            factory.setContentService(new SimpleFileContentService());
            factory.setLockManager(new FsMemoryLockManager());
            return new WebDavRestlet(factory);
        }
    });
    component.start();
    System.out.println("Restlet demo fileserver started, open http://localhost:8080 in your browser or WebDAV client...");
}
Also used : Restlet(org.restlet.Restlet) WebDavRestlet(io.milton.restlet.WebDavRestlet) NullSecurityManager(io.milton.http.fs.NullSecurityManager) FileSystemResourceFactory(io.milton.http.fs.FileSystemResourceFactory) FsMemoryLockManager(io.milton.http.fs.FsMemoryLockManager) WebDavRestlet(io.milton.restlet.WebDavRestlet) Component(org.restlet.Component) SimpleFileContentService(io.milton.http.fs.SimpleFileContentService) Application(org.restlet.Application) File(java.io.File)

Aggregations

SimpleFileContentService (io.milton.http.fs.SimpleFileContentService)2 File (java.io.File)2 LockInfo (io.milton.http.LockInfo)1 LockResult (io.milton.http.LockResult)1 LockTimeout (io.milton.http.LockTimeout)1 LockToken (io.milton.http.LockToken)1 FileSystemResourceFactory (io.milton.http.fs.FileSystemResourceFactory)1 FsFileResource (io.milton.http.fs.FsFileResource)1 FsMemoryLockManager (io.milton.http.fs.FsMemoryLockManager)1 FsResource (io.milton.http.fs.FsResource)1 NullSecurityManager (io.milton.http.fs.NullSecurityManager)1 WebDavRestlet (io.milton.restlet.WebDavRestlet)1 Application (org.restlet.Application)1 Component (org.restlet.Component)1 Restlet (org.restlet.Restlet)1