Package io.milton.httpclient
Class Host
java.lang.Object
io.milton.httpclient.Resource
io.milton.httpclient.Folder
io.milton.httpclient.Host
- Author:
- mcevoyb
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal Stringfinal Integerfinal Stringfinal Stringfinal StringFields inherited from class io.milton.httpclient.Resource
displayName, name, parent -
Constructor Summary
ConstructorsConstructorDescriptionHost(String server, Integer port, String user, String password, ProxyDetails proxyDetails, Map<Folder, List<Resource>> cache) Host(String server, String rootPath, Integer port, String user, String password, ProxyDetails proxyDetails, int timeoutMillis, Map<Folder, List<Resource>> cache, FileSyncer fileSyncer) Host(String server, String rootPath, Integer port, String user, String password, ProxyDetails proxyDetails, Map<Folder, List<Resource>> cache) -
Method Summary
Modifier and TypeMethodDescription_doPropFind(String url, int depth, List<QName> fields) static ResourcevoidvoidbaseHref()buildEncodedUrl(Path path) voidbuildResponses(org.jdom2.Document document, Date serverDate, List<PropFindResponse> responses, int depth) intintDeletes the item at the given path, relative to the root path of this hostintbyte[]voiddoGet(Path path, File file, ProgressListener listener) voidbyte[]voiddoGet(String url, StreamReceiver receiver, List<Range> rangeList, ProgressListener listener) Attempts to lock a resource with infinite timeout and returns the lock token, which must be retained to unlock the resourceAttempts to lock a resource with the specified timeout and returns the lock token, which must be retained to unlock the resourceintCreate a collection at the given absolute path.intintvoidPOSTs the variables and returns the bodydoPut(Path remotePath, File file, IfMatchCheck matchCheck, ProgressListener listener) doPut(Path path, InputStream content, Long contentLength, String contentType, IfMatchCheck matchCheck) doPut(String newUri, InputStream content, Long contentLength, String contentType, IfMatchCheck matchCheck, ProgressListener listener) Uploads the data.intFinds the resource by iterating through the path parts resolving collections as it goes.byte[]GET the contents of the given path.byte[]Retrieve the bytes at the specified path.org.apache.http.client.HttpClientFind a folder at the given path.Returns the fully qualified URL for the given pathstatic org.jdom2.DocumentgetOrCreateFolder(Path remoteParentPath, boolean create) org.jdom2.Documentinthost()href()Returns the UN-encoded urlbooleanisSecure()booleanbooleanprotected org.apache.http.protocol.HttpContextvoidvoidsetSecure(boolean secure) voidsetTimeout(int timeout) voidsetUseDigestForPreemptiveAuth(boolean useDigestForPreemptiveAuth) voidsetUsePreemptiveAuth(boolean usePreemptiveAuth) Methods inherited from class io.milton.httpclient.Folder
addListener, child, children, createFolder, downloadTo, flush, getChild, hasChildren, numChildren, post, removeListener, toString, upload, upload, upload, upload, upload, uploadFile, uploadFile, uploadFile, uploadFolderMethods inherited from class io.milton.httpclient.Resource
addListener, copyTo, copyTo, decodePath, delete, encodedName, finalize, getCount, getCreatedDate, getLockOwner, getLockToken, getModifiedDate, lock, lock, moveTo, moveTo, path, post, removeListener, rename, unlock
-
Field Details
-
defaultFields
-
server
-
port
-
user
-
password
-
rootPath
-
-
Constructor Details
-
Host
-
Host
-
Host
-
Host
-
-
Method Details
-
getJDomDocument
- Throws:
org.jdom2.JDOMException
-
find
public Resource find(String path) throws IOException, HttpException, NotAuthorizedException, BadRequestException Finds the resource by iterating through the path parts resolving collections as it goes. If any path component is not founfd returns null- Parameters:
path-- Returns:
- Throws:
IOExceptionHttpExceptionNotAuthorizedExceptionBadRequestException
-
find
public Resource find(String path, boolean invalidateCache) throws IOException, HttpException, NotAuthorizedException, BadRequestException -
_find
public static Resource _find(Folder parent, String[] arr, int i, boolean invalidateCache) throws IOException, HttpException, NotAuthorizedException, BadRequestException -
getFolder
public Folder getFolder(String path) throws IOException, HttpException, NotAuthorizedException, BadRequestException Find a folder at the given path. Is much the same as find(path), except that it throws an exception if the resource is not a folder- Parameters:
path-- Returns:
- Throws:
IOExceptionHttpExceptionNotAuthorizedExceptionBadRequestException
-
doMkCol
public int doMkCol(Path newUri) throws HttpException, NotAuthorizedException, ConflictException, BadRequestException, NotFoundException, URISyntaxException Create a collection at the given absolute path. This path is NOT relative to the host's base path- Parameters:
newUri-- Returns:
- Throws:
HttpExceptionNotAuthorizedExceptionConflictExceptionBadRequestExceptionNotFoundExceptionURISyntaxException
-
doMkCol
public int doMkCol(String newUri) throws HttpException, NotAuthorizedException, ConflictException, BadRequestException, NotFoundException, URISyntaxException - Parameters:
newUri- - must be fully qualified and correctly encoded- Returns:
- Throws:
HttpExceptionNotAuthorizedExceptionConflictExceptionBadRequestExceptionNotFoundExceptionURISyntaxException
-
doLock
public String doLock(String uri) throws HttpException, NotAuthorizedException, ConflictException, BadRequestException, NotFoundException, URISyntaxException Attempts to lock a resource with infinite timeout and returns the lock token, which must be retained to unlock the resource- Parameters:
uri- - must be encoded- Returns:
- Throws:
HttpExceptionNotAuthorizedExceptionConflictExceptionBadRequestExceptionNotFoundExceptionURISyntaxException
-
doLock
public String doLock(String uri, int timeout) throws HttpException, NotAuthorizedException, ConflictException, BadRequestException, NotFoundException, URISyntaxException Attempts to lock a resource with the specified timeout and returns the lock token, which must be retained to unlock the resource- Parameters:
uri- - must be encodedtimeout- lock timeout in seconds, or -1 if infinite- Returns:
- Throws:
HttpExceptionNotAuthorizedExceptionConflictExceptionBadRequestExceptionNotFoundExceptionURISyntaxException
-
doUnLock
public int doUnLock(String uri, String lockToken) throws HttpException, NotAuthorizedException, ConflictException, BadRequestException, NotFoundException, URISyntaxException - Parameters:
uri- - must be encodedlockToken-- Returns:
- Throws:
HttpExceptionNotAuthorizedExceptionConflictExceptionBadRequestExceptionNotFoundExceptionURISyntaxException
-
doPut
public HttpResult doPut(Path path, InputStream content, Long contentLength, String contentType, IfMatchCheck matchCheck) - Parameters:
path- - an Un-encoded path. Eg /a/b c/ = /a/b%20c/content-contentLength-contentType-- Returns:
-
doPut
-
doPut
public HttpResult doPut(Path remotePath, File file, IfMatchCheck matchCheck, ProgressListener listener) throws FileNotFoundException, HttpException, Utils.CancelledException, NotAuthorizedException, ConflictException - Parameters:
remotePath-file-listener-- Returns:
- - the result code
- Throws:
FileNotFoundExceptionHttpExceptionUtils.CancelledExceptionNotAuthorizedExceptionConflictException
-
doPut
public HttpResult doPut(String newUri, InputStream content, Long contentLength, String contentType, IfMatchCheck matchCheck, ProgressListener listener) Uploads the data. Does not do any file syncronisation- Parameters:
newUri- - encoded full URLcontent-contentLength-contentType-- Returns:
- - the result code
-
doCopy
public int doCopy(String from, String newUri) throws HttpException, NotAuthorizedException, ConflictException, BadRequestException, NotFoundException, URISyntaxException - Parameters:
from- - encoded source urlnewUri- - encoded destination- Returns:
- Throws:
HttpExceptionNotAuthorizedExceptionConflictExceptionBadRequestExceptionNotFoundExceptionURISyntaxException
-
doDelete
public int doDelete(Path path) throws IOException, HttpException, NotAuthorizedException, ConflictException, BadRequestException, NotFoundException Deletes the item at the given path, relative to the root path of this host- Parameters:
path- - unencoded and relative to Host's rootPath- Returns:
- Throws:
IOExceptionHttpExceptionNotAuthorizedExceptionConflictExceptionBadRequestExceptionNotFoundException
-
doDelete
public int doDelete(String url) throws IOException, HttpException, NotAuthorizedException, ConflictException, BadRequestException, NotFoundException - Parameters:
url- - encoded url- Returns:
- Throws:
IOExceptionHttpExceptionNotAuthorizedExceptionConflictExceptionBadRequestExceptionNotFoundException
-
doMove
public int doMove(String sourceUrl, String newUri) throws IOException, HttpException, NotAuthorizedException, ConflictException, BadRequestException, NotFoundException, URISyntaxException - Parameters:
sourceUrl- - encoded source urlnewUri- - encoded destination url- Returns:
- Throws:
IOExceptionHttpExceptionNotAuthorizedExceptionConflictExceptionBadRequestExceptionNotFoundExceptionURISyntaxException
-
propFind
public List<PropFindResponse> propFind(Path path, int depth, QName... fields) throws IOException, HttpException, NotAuthorizedException, BadRequestException -
propFind
public List<PropFindResponse> propFind(String path, int depth, QName... fields) throws IOException, HttpException, NotAuthorizedException, BadRequestException -
propFind
public List<PropFindResponse> propFind(Path path, int depth, List<QName> fields) throws IOException, HttpException, NotAuthorizedException, BadRequestException - Parameters:
path- - unencoded path, which will be evaluated relative to this Host's basePathdepth- - 1 is to find immediate children, 2 includes their children, etcfields- - the list of fields to get, or null to use default fields- Returns:
- Throws:
IOExceptionHttpExceptionNotAuthorizedExceptionBadRequestException
-
_doPropFind
public List<PropFindResponse> _doPropFind(String url, int depth, List<QName> fields) throws IOException, HttpException, NotAuthorizedException, BadRequestException - Parameters:
url- - the encoded absolute URL to query. This method does not apply basePathdepth- - depth to generate responses for. Zero means only the specified url, 1 means it and its direct children, etc- Returns:
- Throws:
IOExceptionHttpExceptionNotAuthorizedExceptionBadRequestException
-
buildResponses
public void buildResponses(org.jdom2.Document document, Date serverDate, List<PropFindResponse> responses, int depth) -
getResponseAsDocument
- Throws:
IOException
-
doGet
public void doGet(String url, StreamReceiver receiver, List<Range> rangeList, ProgressListener listener) throws HttpException, Utils.CancelledException, NotAuthorizedException, BadRequestException, ConflictException, NotFoundException - Parameters:
url- - fully qualified and encoded URLreceiver-rangeList- - if null does a normal GET request- Throws:
HttpExceptionUtils.CancelledExceptionNotAuthorizedExceptionBadRequestExceptionConflictExceptionNotFoundException
-
doGet
public void doGet(Path path, File file, ProgressListener listener) throws IOException, NotFoundException, HttpException, Utils.CancelledException, NotAuthorizedException, BadRequestException, ConflictException - Parameters:
path- - the path to get, relative to the base path of the hostfile- - the file to write content tolistener-- Throws:
IOExceptionNotFoundExceptionHttpExceptionUtils.CancelledExceptionNotAuthorizedExceptionBadRequestExceptionConflictException
-
doGet
public byte[] doGet(Path path) throws IOException, NotFoundException, HttpException, NotAuthorizedException, BadRequestException, ConflictException -
doGet
public byte[] doGet(Path path, Map<String, String> queryParams) throws IOException, NotFoundException, HttpException, NotAuthorizedException, BadRequestException, ConflictException -
doGet
public void doGet(Path path, OutputStream out, Map<String, String> queryParams) throws IOException, NotFoundException, HttpException, NotAuthorizedException, BadRequestException, ConflictException -
options
public void options(String path) throws ConnectException, NotAuthorizedException, UnknownHostException, SocketTimeoutException, IOException, HttpException, NotFoundException - Parameters:
path- - encoded path, but not fully qualified. Must not be prefixed with a slash, as it will be appended to the host's URL- Throws:
ConnectExceptionNotAuthorizedExceptionUnknownHostExceptionSocketTimeoutExceptionIOExceptionHttpExceptionNotFoundException
-
doOptions
public void doOptions(Path path) throws NotFoundException, NotAuthorizedException, IOException, HttpException -
get
public byte[] get(Path path) throws HttpException, NotAuthorizedException, BadRequestException, ConflictException, NotFoundException GET the contents of the given path. The path is non-encoded, and it relative to the host's root.- Parameters:
path-- Returns:
- Throws:
HttpExceptionNotAuthorizedExceptionBadRequestExceptionConflictExceptionNotFoundException
-
get
public byte[] get(String path) throws HttpException, NotAuthorizedException, BadRequestException, ConflictException, NotFoundException Retrieve the bytes at the specified path.- Parameters:
path- - encoded and relative to host's rootPath. Must NOT be slash prefixed as it will be appended to the host's url- Returns:
- Throws:
HttpExceptionNotAuthorizedExceptionBadRequestExceptionConflictExceptionNotFoundException
-
doPost
public String doPost(String url, Map<String, String> params) throws HttpException, NotAuthorizedException, ConflictException, BadRequestException, NotFoundExceptionPOSTs the variables and returns the body- Parameters:
url- - fully qualified and encoded URL to post toparams-- Returns:
- - the body of the response
- Throws:
HttpExceptionNotAuthorizedExceptionConflictExceptionBadRequestExceptionNotFoundException
-
host
-
href
Description copied from class:ResourceReturns the UN-encoded url -
baseHref
-
getHref
Returns the fully qualified URL for the given path- Parameters:
path-- Returns:
-
encodedUrl
- Overrides:
encodedUrlin classFolder
-
getOrCreateFolder
public Folder getOrCreateFolder(Path remoteParentPath, boolean create) throws HttpException, IOException, NotAuthorizedException, ConflictException, BadRequestException, NotFoundException -
getTimeout
public int getTimeout()- Returns:
- the timeout
-
setTimeout
public void setTimeout(int timeout) - Parameters:
timeout- the timeout to set
-
getCookies
-
addCookie
-
addConnectionListener
-
buildEncodedUrl
-
isSecure
public boolean isSecure() -
setSecure
public void setSecure(boolean secure) -
getClient
public org.apache.http.client.HttpClient getClient() -
isUseDigestForPreemptiveAuth
public boolean isUseDigestForPreemptiveAuth() -
setUseDigestForPreemptiveAuth
public void setUseDigestForPreemptiveAuth(boolean useDigestForPreemptiveAuth) -
isUsePreemptiveAuth
public boolean isUsePreemptiveAuth() -
setUsePreemptiveAuth
public void setUsePreemptiveAuth(boolean usePreemptiveAuth) -
newContext
protected org.apache.http.protocol.HttpContext newContext()
-