ok, NOW add WebDavServer...
This commit is contained in:
parent
6ed87b738f
commit
ef252f5a19
@ -0,0 +1,37 @@
|
||||
package net.monarchpass.piecannon.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import com.google.common.io.ByteSource;
|
||||
|
||||
import jodd.http.HttpRequest;
|
||||
import lombok.Data;
|
||||
import net.monarchpass.piecannon.Server;
|
||||
|
||||
@Data
|
||||
public class WebDavServer implements Server {
|
||||
private final String label;
|
||||
private final URI uri;
|
||||
|
||||
private final String username;
|
||||
private final String password;
|
||||
|
||||
@Override
|
||||
public URI upload (String name, ByteSource source) {
|
||||
try {
|
||||
final URI target = URI.create(uri.toString() + "/" + name.replace(" ", "%20"));
|
||||
final HttpRequest request = HttpRequest.put(target.toString())
|
||||
.body(source.read(), "");
|
||||
|
||||
if (username != null && password != null) {
|
||||
request.basicAuthentication(username, password);
|
||||
}
|
||||
|
||||
request.send();
|
||||
return target;
|
||||
} catch (final IOException exception) {
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user