List of usage examples for com.squareup.okhttp HttpUrl parse
public static HttpUrl parse(String url)
From source file:com.ibm.watson.developer_cloud.service.WatsonService.java
License:Open Source License
/** * Gets an authorization token that can be use to authorize API calls. * /*from w w w. ja v a2 s . c om*/ * * @return the token */ public String getToken() { HttpUrl url = HttpUrl.parse(getEndPoint()).newBuilder().setPathSegment(0, "authorization").build(); Request request = RequestBuilder.get(url + "/v1/token").withQuery("url", getEndPoint()).build(); Response response = execute(request); return ResponseUtil.getJsonObject(response).get("token").getAsString(); }
From source file:com.jaspersoft.android.jaspermobile.webview.intercept.okhttp.OkRequestMapper.java
License:Open Source License
@Nullable public Request toOkHttpRequest(WebRequest request) { String url = request.getUrl(); HttpUrl proxyUrl = HttpUrl.parse(url); if (proxyUrl == null) { return null; }//from w w w. j a va 2 s .c o m Request.Builder requestBuilder = new Request.Builder().get().url(proxyUrl); Map<String, String> requestHeaders = extractRequestHeaders(request); for (Map.Entry<String, String> entry : requestHeaders.entrySet()) { requestBuilder.addHeader(entry.getKey(), entry.getValue()); } return requestBuilder.build(); }
From source file:com.kubeiwu.easyandroid.easyhttp.core.retrofit.Response.java
License:Apache License
/** * TODO/* www . j a v a 2s .c o m*/ */ public static <T> Response<T> success(T body) { return success(body, new com.squareup.okhttp.Response.Builder() // .code(200).protocol(Protocol.HTTP_1_1) .request(new com.squareup.okhttp.Request.Builder().url(HttpUrl.parse("http://localhost")).build()) .build()); }
From source file:com.kubeiwu.easyandroid.easyhttp.core.retrofit.Response.java
License:Apache License
/** * TODO//www . j a v a2s . com */ public static <T> Response<T> error(int code, ResponseBody body) { return error(body, new com.squareup.okhttp.Response.Builder() // .code(code).protocol(Protocol.HTTP_1_1) .request(new com.squareup.okhttp.Request.Builder().url(HttpUrl.parse("http://localhost")).build()) .build()); }
From source file:com.liferay.mobile.android.http.client.OkHttpClientImpl.java
License:Open Source License
@Override public String encodeURL(String url) { return HttpUrl.parse(url).toString(); }
From source file:com.liferay.mobile.sdk.file.DownloadUtil.java
License:Open Source License
protected static String getWebDAVFileURL(Config config, int portalVersion, String groupFriendlyURL, String folderPath, String fileTitle) throws Exception { StringBuilder sb = new StringBuilder(); sb.append(config.server());/*from www .j a va 2 s . c om*/ if (portalVersion < PortalVersion.V_6_2) { sb.append("/api/secure"); } sb.append("/webdav"); sb.append(prependSlash(groupFriendlyURL)); sb.append("/document_library"); sb.append(prependSlash(folderPath)); sb.append(prependSlash(fileTitle)); return HttpUrl.parse(sb.toString()).toString(); }
From source file:com.mcxiaoke.next.http.NextRequest.java
License:Apache License
private HttpUrl parseUrlAndQueryString(final String fullUrl) { final String[] urlParts = fullUrl.split("\\?"); String url = urlParts[0];/* w w w.j ava 2s . c o m*/ if (urlParts.length > 1) { this.params.queries(StringUtils.parseQueryString(urlParts[1])); } return HttpUrl.parse(url); }
From source file:com.netflix.spinnaker.clouddriver.artifacts.config.BaseHttpArtifactCredentials.java
License:Apache License
protected HttpUrl parseUrl(String stringUrl) { HttpUrl httpUrl = HttpUrl.parse(stringUrl); if (httpUrl == null) { throw new IllegalArgumentException("Malformed URL: " + stringUrl); }//from ww w. j a v a 2 s .co m return httpUrl; }
From source file:com.netflix.spinnaker.clouddriver.artifacts.config.SimpleHttpArtifactCredentials.java
License:Apache License
protected HttpUrl getDownloadUrl(Artifact artifact) throws IOException { HttpUrl url = HttpUrl.parse(artifact.getReference()); if (url == null) { throw new IllegalArgumentException("Malformed content URL in reference: " + artifact.getReference() + ". Read more here https://www.spinnaker.io/reference/artifacts/types/"); }// ww w . j av a2s .c o m return url; }
From source file:com.netflix.spinnaker.clouddriver.artifacts.github.GitHubArtifactCredentials.java
License:Apache License
public InputStream download(Artifact artifact) throws IOException { HttpUrl.Builder metadataUrlBuilder = HttpUrl.parse(artifact.getReference()).newBuilder(); String version = artifact.getVersion(); if (StringUtils.isEmpty(version)) { log.info("No version specified for artifact {}, using 'master'.", version); version = "master"; }//from w ww. ja v a 2 s .c om metadataUrlBuilder.addQueryParameter("ref", version); Request metadataRequest = requestBuilder.url(metadataUrlBuilder.build().toString()).build(); Response metadataResponse; try { metadataResponse = okHttpClient.newCall(metadataRequest).execute(); } catch (IOException e) { throw new FailedDownloadException( "Unable to determine the download URL of artifact " + artifact + ": " + e.getMessage(), e); } String body = metadataResponse.body().string(); ContentMetadata metadata = objectMapper.readValue(body, ContentMetadata.class); if (StringUtils.isEmpty(metadata.downloadUrl)) { throw new FailedDownloadException( "Failed to retrieve your github artifact's download URL. This is likely due to incorrect auth setup. Artifact: " + artifact); } Request downloadRequest = requestBuilder.url(metadata.getDownloadUrl()).build(); try { Response downloadResponse = okHttpClient.newCall(downloadRequest).execute(); return downloadResponse.body().byteStream(); } catch (IOException e) { throw new FailedDownloadException( "Unable to download the contents of artifact " + artifact + ": " + e.getMessage(), e); } }