Java Code Examples for org.apache.commons.httpclient.HttpMethod#setPath()

The following examples show how to use org.apache.commons.httpclient.HttpMethod#setPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RESTMetadataProvider.java    From vind with Apache License 2.0 5 votes vote down vote up
@Override
public Document getDocument(Document document, DocumentFactory factory) throws IOException {

    HttpMethod request = new GetMethod(baseURL);

    request.addRequestHeader("Authorization", String.format("Bearer %s", bearerToken)); //TODO
    request.setPath(path + document.getId());

    int status = client.executeMethod(request);

    if(status == 200) {

        JsonNode json = mapper.readValue(request.getResponseBody(), JsonNode.class);

        for(FieldDescriptor descriptor : factory.listFields()) {

            try {
                Object value = getValue(json, descriptor);
                if(value != null) {
                    document.setValue(descriptor, value);
                } else LOG.warn("No data found for id {}", document.getId());
            } catch (IOException e) {
                LOG.warn("Cannot use data for id {}: {}", document.getId(), e.getMessage());
            }
        }

        return document;

    } else throw new IOException(request.getStatusText());
}
 
Example 2
Source File: WebdavFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Prepares a Method object.
 *
 * @param method the HttpMethod.
 * @throws FileSystemException if an error occurs encoding the uri.
 * @throws URIException if the URI is in error.
 */
@Override
protected void setupMethod(final HttpMethod method) throws FileSystemException, URIException {
    final String pathEncoded = ((URLFileName) getName()).getPathQueryEncoded(this.getUrlCharset());
    method.setPath(pathEncoded);
    method.setFollowRedirects(this.getFollowRedirect());
    method.setRequestHeader("User-Agent", "Jakarta-Commons-VFS");
    method.addRequestHeader("Cache-control", "no-cache");
    method.addRequestHeader("Cache-store", "no-store");
    method.addRequestHeader("Pragma", "no-cache");
    method.addRequestHeader("Expires", "0");
}
 
Example 3
Source File: HttpFileObject.java    From commons-vfs with Apache License 2.0 3 votes vote down vote up
/**
 * Prepares a HttpMethod object.
 *
 * @param method The object which gets prepared to access the file object.
 * @throws FileSystemException if an error occurs.
 * @throws URIException if path cannot be represented.
 * @since 2.0 (was package)
 */
protected void setupMethod(final HttpMethod method) throws FileSystemException, URIException {
    final String pathEncoded = ((URLFileName) getName()).getPathQueryEncoded(this.getUrlCharset());
    method.setPath(pathEncoded);
    method.setFollowRedirects(this.getFollowRedirect());
    method.setRequestHeader("User-Agent", this.getUserAgent());
}