не работает
parent
8a5c0e26e2
commit
30ddb6f34f
10
pom.xml
10
pom.xml
|
@ -15,7 +15,9 @@
|
|||
<description>TestSpringWebDav</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -41,6 +43,14 @@
|
|||
<artifactId>reactor-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/io.milton/milton-server-ce -->
|
||||
<dependency>
|
||||
<groupId>io.milton</groupId>
|
||||
<artifactId>milton-server-ce</artifactId>
|
||||
<version>4.0.1.1802</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package ru.ldeloff.testspringwebdav.config;
|
||||
|
||||
import io.milton.http.fs.NullSecurityManager;
|
||||
import io.milton.servlet.DefaultMiltonConfigurator;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class MiltonConfig extends DefaultMiltonConfigurator {
|
||||
private final NullSecurityManager securityManager;
|
||||
|
||||
public MiltonConfig() {
|
||||
this.securityManager = new NullSecurityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void build() {
|
||||
builder.setSecurityManager(securityManager);
|
||||
super.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
package ru.ldeloff.testspringwebdav.controller;
|
||||
|
||||
import io.milton.annotations.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.ldeloff.testspringwebdav.model.WebDavFile;
|
||||
import ru.ldeloff.testspringwebdav.model.WebDavFolder;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Slf4j
|
||||
@ResourceController
|
||||
public class HelloWorldController {
|
||||
|
||||
private static HashMap<String, WebDavFile> webDavFiles = new HashMap<>();
|
||||
|
||||
static {
|
||||
try {
|
||||
byte[] bytes = "Hello World".getBytes("UTF-8");
|
||||
webDavFiles.put("file1.txt", new WebDavFile("file1.txt", bytes));
|
||||
webDavFiles.put("file2.txt", new WebDavFile("file2.txt", bytes));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Root
|
||||
public HelloWorldController getRoot() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@ChildrenOf
|
||||
public List<WebDavFolder> getWebDavFolders(HelloWorldController root) {
|
||||
List<WebDavFolder> webDavFolders = new ArrayList<WebDavFolder>();
|
||||
webDavFolders.add(new WebDavFolder("folder1"));
|
||||
webDavFolders.add(new WebDavFolder("folder2"));
|
||||
return webDavFolders;
|
||||
}
|
||||
|
||||
@ChildrenOf
|
||||
public Collection<WebDavFile> getWebDavFiles(WebDavFolder webDavFolder) {
|
||||
return webDavFiles.values();
|
||||
}
|
||||
|
||||
@Get
|
||||
public InputStream getChild(WebDavFile webDavFile) {
|
||||
return new ByteArrayInputStream(webDavFiles.get(webDavFile.getName()).getBytes());
|
||||
}
|
||||
|
||||
@PutChild
|
||||
public void putChild(WebDavFile parent, String name, byte[] bytes) {
|
||||
if(name!=null) {
|
||||
webDavFiles.put(name, new WebDavFile(name, bytes));
|
||||
} else {
|
||||
parent.setBytes(bytes);
|
||||
webDavFiles.put(parent.getName(), parent);
|
||||
}
|
||||
}
|
||||
|
||||
@Delete
|
||||
public void delete(WebDavFile webDavFile) {
|
||||
webDavFiles.remove(webDavFile.getName());
|
||||
}
|
||||
|
||||
@Name
|
||||
public String getWebDavFile(WebDavFile webDavFile) {
|
||||
return webDavFile.getName();
|
||||
}
|
||||
|
||||
@DisplayName
|
||||
public String getDisplayName(WebDavFile webDavFile) {
|
||||
return webDavFile.getName();
|
||||
}
|
||||
|
||||
@UniqueId
|
||||
public String getUniqueId(WebDavFile webDavFile) {
|
||||
return webDavFile.getName();
|
||||
}
|
||||
|
||||
@ModifiedDate
|
||||
public Date getModifiedDate(WebDavFile webDavFile) {
|
||||
return webDavFile.getModifiedDate();
|
||||
}
|
||||
|
||||
@CreatedDate
|
||||
public Date getCreatedDate(WebDavFile webDavFile) {
|
||||
return webDavFile.getCreatedDate();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package ru.ldeloff.testspringwebdav.model;
|
||||
|
||||
import io.milton.annotations.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class WebDavFile {
|
||||
private String name;
|
||||
private Date createdDate;
|
||||
private Date modifiedDate;
|
||||
private Long contentLength;
|
||||
private byte[] bytes;
|
||||
|
||||
public WebDavFile(String name, byte[] bytes) {
|
||||
this.name = name;
|
||||
this.bytes = bytes;
|
||||
this.createdDate = new Date();
|
||||
this.modifiedDate= new Date();
|
||||
this.contentLength = (long) bytes.length;
|
||||
}
|
||||
|
||||
@Name
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@UniqueId
|
||||
public String getUniqueId() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@ModifiedDate
|
||||
public Date getModifiedDate() {
|
||||
return modifiedDate;
|
||||
}
|
||||
|
||||
@CreatedDate
|
||||
public Date getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
@ContentLength
|
||||
public Long getContentLength() {
|
||||
return (long) bytes.length;
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public void setBytes(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package ru.ldeloff.testspringwebdav.model;
|
||||
|
||||
import io.milton.annotations.CreatedDate;
|
||||
import io.milton.annotations.Name;
|
||||
import io.milton.annotations.UniqueId;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class WebDavFolder {
|
||||
private String name;
|
||||
private Date createdDate;
|
||||
|
||||
public WebDavFolder(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Name
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@UniqueId
|
||||
public String getUniqueId() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@CreatedDate
|
||||
public Date getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
}
|
|
@ -1 +1,10 @@
|
|||
# ==============================================================
|
||||
# = Server Settings
|
||||
# ==============================================================
|
||||
server.port=8084
|
||||
|
||||
# ==============================================================
|
||||
# = Log Level
|
||||
# ==============================================================
|
||||
logging.level.root=INFO
|
||||
logging.level.org.springframework=WARN
|
||||
|
|
Loading…
Reference in New Issue