Example usage for org.apache.http.client.utils URIUtils createURI

List of usage examples for org.apache.http.client.utils URIUtils createURI

Introduction

In this page you can find the example usage for org.apache.http.client.utils URIUtils createURI.

Prototype

@Deprecated
public static URI createURI(final String scheme, final String host, final int port, final String path,
        final String query, final String fragment) throws URISyntaxException 

Source Link

Document

Constructs a URI using all the parameters.

Usage

From source file:org.dataconservancy.ui.it.FileHttpAPIIT.java

/**
 * Builds an HttpGet to use for getting file.
 * //from   w w  w . j a  va  2  s . c  o  m
 * @param id
 *            id of the file to get
 * @return The completed http request that can be passed to HttpClient
 * @throws UnsupportedEncodingException
 * @throws URISyntaxException
 */
private HttpGet buildGetRequest(String id, boolean collections)
        throws UnsupportedEncodingException, URISyntaxException {
    HttpGet request = null;

    String arguments = "/file";

    if (id != null && !id.isEmpty()) {
        arguments += "/" + id;
    }

    URL baseUrl = urlConfig.getBaseUrl();

    URI uri = URIUtils.createURI(baseUrl.getProtocol(), baseUrl.getHost(), baseUrl.getPort(), arguments, null,
            null);

    request = new HttpGet(uri);
    return request;
}

From source file:org.dataconservancy.ui.it.HttpDataItemIT.java

/**
 * Builds an HttpGet to use for dataItem get calls.
 * //from   w ww .j a  v  a  2  s .co m
 * @param id
 *            The id of the project to update
 * @return The completed http request that can be passed to HttpClient
 * @throws UnsupportedEncodingException
 * @throws URISyntaxException
 */
private HttpGet buildGetRequest(String id, String acceptHeader, DateTime ifModifiedSinceDate,
        String ifMatchHeader, String ifNoneMatchHeader)
        throws UnsupportedEncodingException, URISyntaxException {
    HttpGet request = null;

    String arguments = "item/";

    if (id != null && !id.isEmpty()) {
        arguments += id;
    }

    URL baseUrl = urlConfig.getBaseUrl();

    URI uri = URIUtils.createURI(baseUrl.getProtocol(), baseUrl.getHost(), baseUrl.getPort(), arguments, null,
            null);

    request = new HttpGet(uri);

    if (acceptHeader != null && !acceptHeader.isEmpty()) {
        request.addHeader("Accept", acceptHeader);
    }

    if (ifModifiedSinceDate != null) {
        request.addHeader("If-Modified-Since", DateUtility.toRfc822(ifModifiedSinceDate));
    }

    if (ifMatchHeader != null && !ifMatchHeader.isEmpty()) {
        request.addHeader("If-Match", ifMatchHeader);
    }

    if (ifNoneMatchHeader != null && !ifNoneMatchHeader.isEmpty()) {
        request.addHeader("If-None-Match", ifNoneMatchHeader);
    }

    return request;
}