Created
February 23, 2017 13:50
-
-
Save TomasKulhanek/4b6798fe117e9e62a165cfae80d37357 to your computer and use it in GitHub Desktop.
Java webdav server demo based on milton.io library.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set root logger level to DEBUG and its only appender to A1. | |
log4j.rootLogger=WARN, A1 | |
# A1 is set to be a ConsoleAppender. | |
log4j.appender.A1=org.apache.log4j.ConsoleAppender | |
log4j.appender.A1.layout=org.apache.log4j.PatternLayout | |
log4j.appender.A1.layout.ConversionPattern=%-5p %c %x - %m%n | |
log4j.logger.io.milton=INFO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<actions> | |
<action> | |
<actionName>CUSTOM-jetty:run</actionName> | |
<displayName>jetty:run</displayName> | |
<goals> | |
<goal>jetty:run</goal> | |
</goals> | |
</action> | |
</actions> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>eu.westlife</groupId> | |
<artifactId>webdavconector</artifactId> | |
<version>1</version> | |
<packaging>war</packaging> | |
<name>WebDavConnector</name> | |
<properties> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<milton.version>2.7.2.0</milton.version> | |
</properties> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.mortbay.jetty</groupId> | |
<artifactId>maven-jetty-plugin</artifactId> | |
<configuration> | |
<contextPath>/</contextPath> | |
<connectors> | |
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> | |
<!--<port>8085</port>--> | |
<port>8080</port> | |
<maxIdleTime>60000</maxIdleTime> | |
</connector> | |
</connectors> | |
<stopKey>stop</stopKey> | |
<stopPort>8089</stopPort> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> | |
<repositories> | |
<repository> | |
<snapshots> | |
<enabled>false</enabled> | |
</snapshots> | |
<id>bintray-milton-Milton</id> | |
<name>bintray</name> | |
<url>http://dl.bintray.com/milton/Milton</url> | |
</repository> | |
<repository> | |
<id>ettrema-repo</id> | |
<url>http://milton.io/maven/</url> | |
</repository> | |
</repositories> | |
<dependencies> | |
<dependency> | |
<groupId>org.slf4j</groupId> | |
<artifactId>slf4j-log4j12</artifactId> | |
<version>1.6.1</version> | |
</dependency> | |
<dependency> | |
<groupId>io.milton</groupId> | |
<artifactId>milton-server-ce</artifactId> | |
<version>${milton.version}</version> | |
</dependency> | |
</dependencies> | |
</project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package eu.westlife; | |
import io.milton.annotations.ChildrenOf; | |
import io.milton.annotations.PutChild; | |
import io.milton.annotations.ResourceController; | |
import io.milton.annotations.Root; | |
import io.milton.annotations.Get; | |
import java.util.ArrayList; | |
import java.util.List; | |
@ResourceController | |
public class ScratchController { | |
private static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(ScratchController.class); | |
private List<ArtifactType> artifactTypes = new ArrayList<ArtifactType>(); | |
public ScratchController(){ | |
artifactTypes.add(new ArtifactType("EUDAT B2Drop")); | |
artifactTypes.add((new ArtifactType("Google Drive"))); | |
artifactTypes.add((new ArtifactType("DropBox"))); | |
artifactTypes.add((new ArtifactType("Amazon S3"))); | |
} | |
@Root | |
public ScratchController getRoot() { | |
return this; | |
} | |
@ChildrenOf | |
public List<ArtifactType> getProducts(ScratchController root) { | |
return artifactTypes; | |
} | |
@ChildrenOf | |
public List<Artifact> getProductFiles(ArtifactType artifactType) { | |
return artifactType.getArtifacts(); | |
} | |
@PutChild | |
public Artifact upload(ArtifactType artifactType, String newName, byte[] bytes) { | |
Artifact af = new Artifact(newName, bytes); | |
artifactType.getArtifacts().add(af); | |
return af; | |
} | |
@Get | |
public byte[] download(Artifact artifact) { | |
return artifact.bytes; | |
} | |
public class ArtifactType { | |
private String name; | |
public ArtifactType(String name) { | |
this.name = name; | |
} | |
public String getName() { | |
return name; | |
} | |
private List<Artifact> artifacts = new ArrayList<Artifact>(); | |
public List<Artifact> getArtifacts() { | |
return artifacts; | |
} | |
} | |
public class Artifact { | |
private String name; | |
private byte[] bytes; | |
public Artifact(String name, byte[] bytes) { | |
this.name = name; | |
this.bytes = bytes; | |
} | |
public String getName() { | |
return name; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<settings> | |
<proxies> | |
<proxy> | |
<id>wwwcache</id> | |
<active>true</active> | |
<protocol>http</protocol> | |
<host>wwwcache.dl.ac.uk</host> | |
<port>8080</port> | |
<nonProxyHosts>localhost</nonProxyHosts> | |
</proxy> | |
<proxy> | |
<id>wwwcache2</id> | |
<active>true</active> | |
<protocol>https</protocol> | |
<host>wwwcache.dl.ac.uk</host> | |
<port>8080</port> | |
<nonProxyHosts>localhost</nonProxyHosts> | |
</proxy> | |
</proxies> | |
</settings> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" | |
version="2.4"> | |
<filter> | |
<filter-name>MiltonFilter</filter-name> | |
<filter-class>io.milton.servlet.MiltonFilter</filter-class> | |
<init-param> | |
<param-name>resource.factory.class</param-name> | |
<param-value>io.milton.http.annotated.AnnotationResourceFactory</param-value> | |
</init-param> | |
<init-param> | |
<param-name>controllerPackagesToScan</param-name> | |
<param-value>eu.westlife</param-value> | |
</init-param> | |
<!-- These paths will "fall through" the filter and be handled as normal servlet resources --> | |
<init-param> | |
<param-name>milton.exclude.paths</param-name> | |
<param-value>/myExcludedPaths,/moreExcludedPaths</param-value> | |
</init-param> | |
<!-- | |
<init-param> | |
<param-name>contextPath</param-name> | |
<param-value>/webdav</param-value> | |
</init-param> | |
--> | |
</filter> | |
<filter-mapping> | |
<filter-name>MiltonFilter</filter-name> | |
<url-pattern>/*</url-pattern> | |
</filter-mapping> | |
<session-config> | |
<session-timeout> | |
30 | |
</session-timeout> | |
</session-config> | |
<welcome-file-list> | |
<welcome-file> | |
index.jsp | |
</welcome-file> | |
</welcome-file-list> | |
</web-app> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment