Search in sources :

Example 61 with HttpUrl

use of okhttp3.HttpUrl in project connect-android-sdk by telenordigital.

the class ConnectUrlHelperTest method webViewBrowserTypeOnGetAuthorizeUriReturnsWebViewParam.

@Test
public void webViewBrowserTypeOnGetAuthorizeUriReturnsWebViewParam() {
    HttpUrl url = new HttpUrl.Builder().scheme("https").host("connect.telenordigital.com").build();
    ArrayList<String> locales = new ArrayList<>();
    locales.add(Locale.ENGLISH.getLanguage());
    HashMap<String, String> parameters = new HashMap<>();
    Uri authorizeUri = ConnectUrlHelper.getAuthorizeUriStem(parameters, "client-id-example", "redirect-url://here", locales, url, BrowserType.WEB_VIEW);
    assertThat(authorizeUri.getQueryParameter("telenordigital_sdk_version").endsWith("web-view"), is(true));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Uri(android.net.Uri) HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Example 62 with HttpUrl

use of okhttp3.HttpUrl in project nzbhydra2 by theotherp.

the class ReleaseMojoTest method testExecute.

public void testExecute() throws Exception {
    MockWebServer server = getMockWebServer();
    HttpUrl url = server.url("/repos/theotherp/nzbhydra2/releases");
    // Here the magic happens
    File pom = getTestFile("/src/test/resources/org/nzbhydra/github/mavenreleaseplugin/pomWithToken.xml");
    assertTrue(pom.exists());
    ReleaseMojo releaseMojo = new ReleaseMojo();
    releaseMojo = (ReleaseMojo) configureMojo(releaseMojo, extractPluginConfiguration("github-release-plugin", pom));
    releaseMojo.githubReleasesUrl = url.toString();
    releaseMojo.windowsAsset = getTestFile("src/test/resources/org/nzbhydra/github/mavenreleaseplugin/windowsAsset.txt");
    releaseMojo.linuxAsset = getTestFile("src/test/resources/org/nzbhydra/github/mavenreleaseplugin/linuxAsset.txt");
    releaseMojo.execute();
    verifyExecution(server);
}
Also used : MockWebServer(okhttp3.mockwebserver.MockWebServer) File(java.io.File) HttpUrl(okhttp3.HttpUrl)

Example 63 with HttpUrl

use of okhttp3.HttpUrl in project edx-app-android by edx.

the class NoCacheHeaderStrippingInterceptor method intercept.

@NonNull
@Override
public Response intercept(@NonNull final Chain chain) throws IOException {
    final Request request = chain.request();
    final Response response = chain.proceed(request);
    final Headers headers = response.headers();
    Headers.Builder strippedHeadersBuilder = null;
    List<String> headersToStrip = null;
    for (int i = 0, headersCount = headers.size(); i < headersCount; i++) {
        final String headerName = headers.name(i);
        final String headerValue = headers.value(i);
        if (headerName.equalsIgnoreCase("Cache-Control")) {
            Matcher directiveMatcher = PATTERN_NO_CACHE_HEADER.matcher(headerValue);
            if (directiveMatcher.find()) {
                if (strippedHeadersBuilder == null) {
                    strippedHeadersBuilder = new Headers.Builder();
                    for (int j = 0; j < i; j++) {
                        strippedHeadersBuilder.add(headers.name(j), headers.value(j));
                    }
                    headersToStrip = new ArrayList<>();
                }
                String newHeaderValue = headerValue;
                while (true) {
                    Collections.addAll(headersToStrip, directiveMatcher.group(GROUP_NO_CACHE_HEADERS).trim().split("\\s*,\\s*"));
                    final StringBuffer newHeaderValueBuffer = new StringBuffer();
                    directiveMatcher.appendReplacement(newHeaderValueBuffer, "$" + (directiveMatcher.group(GROUP_SEPARATOR_START).isEmpty() ? GROUP_SEPARATOR_END : GROUP_SEPARATOR_START));
                    directiveMatcher.appendTail(newHeaderValueBuffer);
                    newHeaderValue = newHeaderValueBuffer.toString();
                    directiveMatcher = PATTERN_NO_CACHE_HEADER.matcher(newHeaderValue);
                    if (!directiveMatcher.find())
                        break;
                }
                if (!newHeaderValue.isEmpty()) {
                    strippedHeadersBuilder.add(headerName, newHeaderValue);
                }
                continue;
            }
        }
        if (strippedHeadersBuilder != null) {
            strippedHeadersBuilder.add(headerName, headerValue);
        }
    }
    if (strippedHeadersBuilder == null) {
        return response;
    }
    final HttpUrl url = request.url();
    List<Cookie> cookies = null;
    for (final String headerToStrip : headersToStrip) {
        strippedHeadersBuilder.removeAll(headerToStrip);
        if (headerToStrip.equalsIgnoreCase("Set-Cookie")) {
            if (cookieJar != CookieJar.NO_COOKIES) {
                for (final String cookieString : headers.values(headerToStrip)) {
                    Cookie cookie = Cookie.parse(url, cookieString);
                    if (cookie != null) {
                        if (cookies == null) {
                            cookies = new ArrayList<>();
                        }
                        cookies.add(cookie);
                    }
                }
            }
        }
    }
    if (cookies != null) {
        cookieJar.saveFromResponse(url, cookies);
    }
    return response.newBuilder().headers(strippedHeadersBuilder.build()).build();
}
Also used : Cookie(okhttp3.Cookie) Matcher(java.util.regex.Matcher) Headers(okhttp3.Headers) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) Response(okhttp3.Response) NonNull(android.support.annotation.NonNull)

Example 64 with HttpUrl

use of okhttp3.HttpUrl in project java-sdk by watson-developer-cloud.

the class PaginationTypeAdapter method read.

/*
   * (non-Javadoc)
   * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
   */
@Override
public Pagination read(JsonReader reader) throws IOException {
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();
        return null;
    }
    reader.beginObject();
    Pagination pagination = new Pagination();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals(REFRESH_URL)) {
            pagination.setRefreshUrl(reader.nextString());
        } else if (name.equals(NEXT_URL)) {
            String nextUrl = reader.nextString();
            HttpUrl url = HttpUrl.parse(DEFAULT_ENDPOINT + nextUrl);
            pagination.setCursor(url.queryParameter(CURSOR));
            pagination.setNextUrl(nextUrl);
        } else if (name.equals(TOTAL)) {
            pagination.setTotal(reader.nextLong());
        } else if (name.equals(MATCHED)) {
            pagination.setMatched(reader.nextLong());
        } else {
            reader.skipValue();
        }
    }
    reader.endObject();
    return pagination;
}
Also used : Pagination(com.ibm.watson.developer_cloud.conversation.v1.model.Pagination) HttpUrl(okhttp3.HttpUrl)

Example 65 with HttpUrl

use of okhttp3.HttpUrl in project java-sdk by watson-developer-cloud.

the class WatsonCookieJar method loadForRequest.

/*
   * (non-Javadoc)
   *
   * @see okhttp3.CookieJar#loadForRequest(okhttp3.HttpUrl)
   */
@Override
public List<Cookie> loadForRequest(HttpUrl url) {
    List<Cookie> cookies = this.adapter.loadForRequest(url);
    // TODO: Removes the SESSIONID for speech to text session lest requests
    if (url.encodedPathSegments().contains(SPEECH_TO_TEXT) && !url.encodedPathSegments().contains(SESSIONS)) {
        List<Cookie> sessionLessCookies = new ArrayList<Cookie>();
        for (Cookie cookie : cookies) {
            if (!cookie.name().equalsIgnoreCase(SESSIONID)) {
                sessionLessCookies.add(cookie);
            }
        }
        cookies = sessionLessCookies;
    }
    return cookies;
}
Also used : Cookie(okhttp3.Cookie) ArrayList(java.util.ArrayList)

Aggregations

HttpUrl (okhttp3.HttpUrl)302 Request (okhttp3.Request)130 Test (org.junit.Test)86 Response (okhttp3.Response)69 IOException (java.io.IOException)61 MockResponse (okhttp3.mockwebserver.MockResponse)40 Cookie (okhttp3.Cookie)35 ArrayList (java.util.ArrayList)28 OkHttpClient (okhttp3.OkHttpClient)27 MockWebServer (okhttp3.mockwebserver.MockWebServer)26 InputStream (java.io.InputStream)21 InputStreamReader (java.io.InputStreamReader)20 HashMap (java.util.HashMap)19 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)19 RequestBody (okhttp3.RequestBody)18 JsonParseException (com.google.gson.JsonParseException)13 File (java.io.File)12 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)10 List (java.util.List)10 Test (org.junit.jupiter.api.Test)10