Example usage for com.squareup.okhttp HttpUrl toString

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

Introduction

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

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:com.murrayc.galaxyzoo.app.provider.test.ZooniverseClientTest.java

License:Open Source License

private static ZooniverseClient createZooniverseClient(final MockWebServer server) {
    final HttpUrl mockUrl = server.url("/");

    final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    final Context context = instrumentation.getTargetContext();

    return new ZooniverseClient(context, mockUrl.toString());
}

From source file:io.minio.MinioClient.java

License:Apache License

/**
 * Creates Minio client object with given HttpUrl object using anonymous access.
 *
 * </p><b>Example:</b><br>
 * <pre>{@code MinioClient minioClient = new MinioClient(new HttpUrl.parse("https://play.minio.io:9000")); }</pre>
 *
 * @param url Endpoint HttpUrl object.//  w  w  w . j av a 2 s. c o  m
 *
 * @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)
 * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean secure)
 */
public MinioClient(HttpUrl url) throws InvalidEndpointException, InvalidPortException {
    this(url.toString(), 0, null, null);
}

From source file:io.minio.MinioClient.java

License:Apache License

/**
 * Creates Minio client object with given URL object, access key and secret key.
 *
 * </p><b>Example:</b><br>
 * <pre>{@code MinioClient minioClient = new MinioClient(HttpUrl.parse("https://play.minio.io:9000"), "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY"); }</pre>
 *
 * @param url Endpoint HttpUrl object.//from  w w w. j  a va  2  s.c  o m
 * @param accessKey Access key to access service in endpoint.
 * @param secretKey Secret key to access service in endpoint.
 *
 * @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)
 * @see #MinioClient(String endpoint, int port, String accessKey, String secretKey, boolean secure)
 */
public MinioClient(HttpUrl url, String accessKey, String secretKey)
        throws InvalidEndpointException, InvalidPortException {
    this(url.toString(), 0, accessKey, secretKey);
}

From source file:io.minio.MinioClient.java

License:Apache License

/**
 * Returns an presigned URL to download the object in the bucket with given expiry time.
 *
 * </p><b>Example:</b><br>
 * <pre>{@code String url = minioClient.presignedGetObject("my-bucketname", "my-objectname", 60 * 60 * 24);
 * System.out.println(url); }</pre>
 *
 * @param bucketName  Bucket name./*from  w  w  w  .  j  av  a 2  s.c  o m*/
 * @param objectName  Object name in the bucket.
 * @param expires     Expiration time in seconds of presigned URL.
 *
 * @return string contains URL to download the object.
 *
 * @throws InvalidBucketNameException   upon an invalid bucket name
 * @throws InvalidKeyException          upon an invalid access key or secret key
 * @throws IOException                  upon signature calculation failure
 * @throws NoSuchAlgorithmException     upon requested algorithm was not found during signature calculation
 * @throws InvalidExpiresRangeException upon input expires is out of range
 */
public String presignedGetObject(String bucketName, String objectName, Integer expires)
        throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
        InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
        InternalException, InvalidExpiresRangeException {
    // Validate input.
    if (expires < 1 || expires > DEFAULT_EXPIRY_TIME) {
        throw new InvalidExpiresRangeException(expires,
                "expires must be in range of 1 to " + DEFAULT_EXPIRY_TIME);
    }

    updateRegionCache(bucketName);
    String region = BucketRegionCache.INSTANCE.region(bucketName);

    Request request = createRequest(Method.GET, bucketName, objectName, region, null, null, null, null, 0);
    HttpUrl url = Signer.presignV4(request, region, accessKey, secretKey, expires);
    return url.toString();
}

From source file:io.minio.MinioClient.java

License:Apache License

/**
 * Returns a presigned URL to upload an object in the bucket with given expiry time.
 *
 * </p><b>Example:</b><br>
 * <pre>{@code String url = minioClient.presignedPutObject("my-bucketname", "my-objectname", 60 * 60 * 24);
 * System.out.println(url); }</pre>
 *
 * @param bucketName  Bucket name//from  ww  w.j  a va2s  .  c  om
 * @param objectName  Object name in the bucket
 * @param expires     Expiration time in seconds to presigned URL.
 *
 * @return string contains URL to upload the object.
 *
 * @throws InvalidBucketNameException   upon an invalid bucket name
 * @throws InvalidKeyException          upon an invalid access key or secret key
 * @throws IOException                  upon signature calculation failure
 * @throws NoSuchAlgorithmException     upon requested algorithm was not found during signature calculation
 * @throws InvalidExpiresRangeException upon input expires is out of range
 */
public String presignedPutObject(String bucketName, String objectName, Integer expires)
        throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
        InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
        InternalException, InvalidExpiresRangeException {
    if (expires < 1 || expires > DEFAULT_EXPIRY_TIME) {
        throw new InvalidExpiresRangeException(expires,
                "expires must be in range of 1 to " + DEFAULT_EXPIRY_TIME);
    }

    updateRegionCache(bucketName);
    String region = BucketRegionCache.INSTANCE.region(bucketName);

    Request request = createRequest(Method.PUT, bucketName, objectName, region, null, null, null, "", 0);
    HttpUrl url = Signer.presignV4(request, region, accessKey, secretKey, expires);
    return url.toString();
}

From source file:it.analysis.ReportDumpTest.java

License:Open Source License

private void verifyUrl(String url) throws IOException {
    HttpUrl httpUrl = HttpUrl.parse(url);
    Request request = new Request.Builder().url(httpUrl).get().build();
    Response response = new OkHttpClient().newCall(request).execute();
    assertThat(response.isSuccessful()).as(httpUrl.toString()).isTrue();
    assertThat(response.body().string()).as(httpUrl.toString()).isNotEmpty();
}

From source file:jonas.tool.saveForOffline.FaviconFetcher.java

License:Open Source License

public List<String> getPotentialFaviconUrls(Document document) {
    List<String> iconUrls = new ArrayList<String>();
    HttpUrl base = HttpUrl.parse(document.baseUri());

    for (String cssQuery : htmlIconCssQueries) {
        for (Element e : document.select(cssQuery)) {
            if (e.hasAttr("href")) {
                iconUrls.add(e.attr("href"));
            }//from w ww. j a v a 2 s  .c  om

            if (e.hasAttr("content")) {
                iconUrls.add(e.attr("content"));
            }

            if (e.hasAttr("src")) {
                iconUrls.add(e.attr("src"));
            }
        }
    }

    for (String path : hardcodedIconPaths) {
        HttpUrl url = HttpUrl.parse("http://" + HttpUrl.parse(document.baseUri()).host() + path);
        iconUrls.add(url.toString());
    }

    for (ListIterator<String> i = iconUrls.listIterator(); i.hasNext();) {
        HttpUrl httpUrl = base.resolve(i.next());
        if (httpUrl != null) {
            i.set(httpUrl.toString());
        } else {
            i.remove();
        }
    }

    return iconUrls;

}

From source file:net.yatomiya.e4.services.image.ImageEntry.java

License:Open Source License

ImageEntry(ImageService service, HttpUrl url) {
    this.service = service;
    this.url = url;

    eData = service.getStorageManager().getEntryData(url.toString());

    storageFile = service.getStorageManager().getImageStorageFile(eData.filename);

    {//ww  w .  j  a  v  a 2  s.  c om
        typeMap = new HashMap<>();

        typeMap.put(ImageType.ORIGINAL, new ImageTypeProcessor(ImageType.ORIGINAL));
        typeMap.put(ImageType.THUMBNAIL, new ImageTypeProcessor(ImageType.THUMBNAIL) {
            @Override
            void allocateImages(ImageLoader loader) {
                animationMetaData = new AnimationMetaData(loader);

                int width = loader.logicalScreenWidth;
                int height = loader.logicalScreenHeight;
                if (width == 0 || height == 0) {
                    width = loader.data[0].width;
                    height = loader.data[0].height;
                }

                Point thumbSize = getService().getThumbnailSize();
                if (width < thumbSize.x && height < thumbSize.y) {
                    ImageTypeProcessor p = typeMap.get(ImageType.ORIGINAL);
                    if (!p.hasImages()) {
                        p.allocateImages(loader);
                    }
                    images = p.getImages();
                } else {
                    Point newSize = ImageUtils.fitTo(width, height, thumbSize.x, thumbSize.y);
                    images = ImageUtils.allocateImages(loader, newSize.x, newSize.y);
                }
            }
        });
    }
}

From source file:net.yatomiya.nicherry.ui.handlers.SearchWebHandler.java

License:Open Source License

@Execute
public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) TextSelection selection) {
    String query = selection.getText();
    query = HttpUtils.urlEncode(query);//w ww. j a  v a  2  s .co m
    String searchUrl = NUtils.getPreference(NPreferences.WEB_SEARCH_URL);
    searchUrl = searchUrl.replace(QUERY_REPLACE, query);
    HttpUrl url = HttpUrl.parse(searchUrl);

    Program.launch(url.toString());
}

From source file:org.mariotaku.twidere.util.OAuthPasswordAuthenticator.java

License:Open Source License

public OAuthPasswordAuthenticator(final TwitterOAuth oauth,
        final LoginVerificationCallback loginVerificationCallback, final String userAgent) {
    final RestClient restClient = RestAPIFactory.getRestClient(oauth);
    this.oauth = oauth;
    this.client = (OkHttpRestClient) restClient.getRestClient();
    final OkHttpClient okhttp = client.getClient();
    okhttp.setCookieHandler(new CookieManager());
    okhttp.networkInterceptors().add(new Interceptor() {
        @Override/*  w ww. j  av a2 s.  c o m*/
        public Response intercept(Chain chain) throws IOException {
            final Response response = chain.proceed(chain.request());
            if (!response.isRedirect()) {
                return response;
            }
            final String location = response.header("Location");
            final Response.Builder builder = response.newBuilder();
            if (!TextUtils.isEmpty(location) && !endpoint.checkEndpoint(location)) {
                final HttpUrl originalLocation = HttpUrl
                        .get(URI.create("https://api.twitter.com/").resolve(location));
                final HttpUrl.Builder locationBuilder = HttpUrl.parse(endpoint.getUrl()).newBuilder();
                for (String pathSegments : originalLocation.pathSegments()) {
                    locationBuilder.addPathSegment(pathSegments);
                }
                for (int i = 0, j = originalLocation.querySize(); i < j; i++) {
                    final String name = originalLocation.queryParameterName(i);
                    final String value = originalLocation.queryParameterValue(i);
                    locationBuilder.addQueryParameter(name, value);
                }
                final String encodedFragment = originalLocation.encodedFragment();
                if (encodedFragment != null) {
                    locationBuilder.encodedFragment(encodedFragment);
                }
                final HttpUrl newLocation = locationBuilder.build();
                builder.header("Location", newLocation.toString());
            }
            return builder.build();
        }
    });
    this.endpoint = restClient.getEndpoint();
    this.loginVerificationCallback = loginVerificationCallback;
    this.userAgent = userAgent;
}