Example usage for com.squareup.okhttp HttpUrl encodedPath

List of usage examples for com.squareup.okhttp HttpUrl encodedPath

Introduction

In this page you can find the example usage for com.squareup.okhttp HttpUrl encodedPath.

Prototype

public String encodedPath() 

Source Link

Document

Returns the entire path of this URL, encoded for use in HTTP resource resolution.

Usage

From source file:alberto.avengers.model.rest.utils.interceptors.HttpLoggingInterceptor.java

License:Apache License

private static String requestPath(HttpUrl url) {
    String path = url.encodedPath();
    String query = url.encodedQuery();
    return query != null ? (path + '?' + query) : path;
}

From source file:at.bitfire.dav4android.DavAddressBook.java

License:Open Source License

public void multiget(HttpUrl[] urls, boolean vCard4) throws IOException, HttpException, DavException {
    /* <!ELEMENT addressbook-multiget ((DAV:allprop |
                                    DAV:propname |
                                    DAV:prop)?,
                                    DAV:href+)>
    *//*from   w w  w  .j  av  a 2 s.c  o  m*/
    XmlSerializer serializer = XmlUtils.newSerializer();
    StringWriter writer = new StringWriter();
    serializer.setOutput(writer);
    serializer.startDocument("UTF-8", null);
    serializer.setPrefix("", XmlUtils.NS_WEBDAV);
    serializer.setPrefix("CARD", XmlUtils.NS_CARDDAV);
    serializer.startTag(XmlUtils.NS_CARDDAV, "addressbook-multiget");
    serializer.startTag(XmlUtils.NS_WEBDAV, "prop");
    serializer.startTag(XmlUtils.NS_WEBDAV, "getcontenttype"); // to determine the character set
    serializer.endTag(XmlUtils.NS_WEBDAV, "getcontenttype");
    serializer.startTag(XmlUtils.NS_WEBDAV, "getetag");
    serializer.endTag(XmlUtils.NS_WEBDAV, "getetag");
    serializer.startTag(XmlUtils.NS_CARDDAV, "address-data");
    if (vCard4) {
        serializer.attribute(null, "content-type", "text/vcard");
        serializer.attribute(null, "version", "4.0");
    }
    serializer.endTag(XmlUtils.NS_CARDDAV, "address-data");
    serializer.endTag(XmlUtils.NS_WEBDAV, "prop");
    for (HttpUrl url : urls) {
        serializer.startTag(XmlUtils.NS_WEBDAV, "href");
        serializer.text(url.encodedPath());
        serializer.endTag(XmlUtils.NS_WEBDAV, "href");
    }
    serializer.endTag(XmlUtils.NS_CARDDAV, "addressbook-multiget");
    serializer.endDocument();

    // redirects must not followed automatically (as it may rewrite REPORT requests to GET requests)
    httpClient.setFollowRedirects(false);

    Response response = httpClient.newCall(new Request.Builder().url(location)
            .method("REPORT", RequestBody.create(MIME_XML, writer.toString())).header("Depth", "0") // "The request MUST include a Depth: 0 header [...]"
            .build()).execute();

    checkStatus(response);
    assertMultiStatus(response);

    members.clear();
    processMultiStatus(response.body().charStream());
}

From source file:at.bitfire.dav4android.DavCalendar.java

License:Open Source License

public void multiget(HttpUrl[] urls) throws IOException, HttpException, DavException {
    /* <!ELEMENT calendar-multiget ((DAV:allprop |
                                DAV:propname |
                                DAV:prop)?, DAV:href+)>
    *///from   w w w  .  j  a  v a2s  .c  om
    XmlSerializer serializer = XmlUtils.newSerializer();
    StringWriter writer = new StringWriter();
    serializer.setOutput(writer);
    serializer.startDocument("UTF-8", null);
    serializer.setPrefix("", XmlUtils.NS_WEBDAV);
    serializer.setPrefix("CAL", XmlUtils.NS_CALDAV);
    serializer.startTag(XmlUtils.NS_CALDAV, "calendar-multiget");
    serializer.startTag(XmlUtils.NS_WEBDAV, "prop");
    serializer.startTag(XmlUtils.NS_WEBDAV, "getcontenttype"); // to determine the character set
    serializer.endTag(XmlUtils.NS_WEBDAV, "getcontenttype");
    serializer.startTag(XmlUtils.NS_WEBDAV, "getetag");
    serializer.endTag(XmlUtils.NS_WEBDAV, "getetag");
    serializer.startTag(XmlUtils.NS_CALDAV, "calendar-data");
    serializer.endTag(XmlUtils.NS_CALDAV, "calendar-data");
    serializer.endTag(XmlUtils.NS_WEBDAV, "prop");
    for (HttpUrl url : urls) {
        serializer.startTag(XmlUtils.NS_WEBDAV, "href");
        serializer.text(url.encodedPath());
        serializer.endTag(XmlUtils.NS_WEBDAV, "href");
    }
    serializer.endTag(XmlUtils.NS_CALDAV, "calendar-multiget");
    serializer.endDocument();

    // redirects must not followed automatically (as it may rewrite REPORT requests to GET requests)
    httpClient.setFollowRedirects(false);

    Response response = httpClient.newCall(new Request.Builder().url(location)
            .method("REPORT", RequestBody.create(MIME_XML, writer.toString())).build()).execute();

    checkStatus(response);
    assertMultiStatus(response);

    members.clear();
    processMultiStatus(response.body().charStream());
}

From source file:com.codenote.tikal.example.client.HttpLoggingInterceptor.java

License:Apache License

private static String requestPath(HttpUrl url) {
    String domain = url.scheme() + "://" + url.host();
    String path = url.encodedPath();
    String query = url.encodedQuery();
    return query != null ? domain.concat(path + '?' + query) : domain.concat(path);
}

From source file:io.minio.MinioClient.java

License:Apache License

/**
 * Creates Minio client object using given endpoint, port, access key, secret key and secure option.
 *
 * </p><b>Example:</b><br>
 * <pre>{@code MinioClient minioClient =
 *          new MinioClient("play.minio.io", 9000, "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", false);
 * }</pre>//from  w  ww .ja v a  2 s.co m
 *
 * @param endpoint  Request endpoint. Endpoint is an URL, domain name, IPv4 or IPv6 address.<pre>
 *              Valid endpoints:
 *              * https://s3.amazonaws.com
 *              * https://s3.amazonaws.com/
 *              * https://play.minio.io:9000
 *              * http://play.minio.io:9010/
 *              * localhost
 *              * localhost.localdomain
 *              * play.minio.io
 *              * 127.0.0.1
 *              * 192.168.1.60
 *              * ::1</pre>
 *
 * @param port      Valid port.  It should be in between 1 and 65535.  Unused if endpoint is an URL.
 * @param accessKey Access key to access service in endpoint.
 * @param secretKey Secret key to access service in endpoint.
 * @param secure    If true, access endpoint using HTTPS else access it using HTTP.
 *
 * @see #MinioClient(String endpoint)
 * @see #MinioClient(URL url)
 * @see #MinioClient(String endpoint, String accessKey, String secretKey)
 * @see #MinioClient(URL url, String accessKey, String secretKey)
 * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey)
 * @see #MinioClient(String endpoint, String accessKey, String secretKey, boolean secure)
 */
public MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean secure)
        throws InvalidEndpointException, InvalidPortException {
    if (endpoint == null) {
        throw new InvalidEndpointException(NULL_STRING, "null endpoint");
    }

    if (port < 0 || port > 65535) {
        throw new InvalidPortException(port, "port must be in range of 1 to 65535");
    }

    HttpUrl url = HttpUrl.parse(endpoint);
    if (url != null) {
        if (!"/".equals(url.encodedPath())) {
            throw new InvalidEndpointException(endpoint, "no path allowed in endpoint");
        }

        // treat Amazon S3 host as special case
        String amzHost = url.host();
        if (amzHost.endsWith(AMAZONAWS_COM) && !amzHost.equals(S3_AMAZONAWS_COM)) {
            throw new InvalidEndpointException(endpoint,
                    "for Amazon S3, host should be 's3.amazonaws.com' in endpoint");
        }

        HttpUrl.Builder urlBuilder = url.newBuilder();
        Scheme scheme = Scheme.HTTP;
        if (secure) {
            scheme = Scheme.HTTPS;
        }

        urlBuilder.scheme(scheme.toString());

        if (port > 0) {
            urlBuilder.port(port);
        }

        this.baseUrl = urlBuilder.build();
        this.accessKey = accessKey;
        this.secretKey = secretKey;

        return;
    }

    // endpoint may be a valid hostname, IPv4 or IPv6 address
    if (!this.isValidEndpoint(endpoint)) {
        throw new InvalidEndpointException(endpoint, "invalid host");
    }

    // treat Amazon S3 host as special case
    if (endpoint.endsWith(AMAZONAWS_COM) && !endpoint.equals(S3_AMAZONAWS_COM)) {
        throw new InvalidEndpointException(endpoint, "for amazon S3, host should be 's3.amazonaws.com'");
    }

    Scheme scheme = Scheme.HTTP;
    if (secure) {
        scheme = Scheme.HTTPS;
    }

    if (port == 0) {
        this.baseUrl = new HttpUrl.Builder().scheme(scheme.toString()).host(endpoint).build();
    } else {
        this.baseUrl = new HttpUrl.Builder().scheme(scheme.toString()).host(endpoint).port(port).build();
    }
    this.accessKey = accessKey;
    this.secretKey = secretKey;
}