Search in sources :

Example 56 with HttpUrl

use of okhttp3.HttpUrl in project dhis2-android-sdk by dhis2.

the class ConfigurationManagerImpl method configure.

@NonNull
@Override
public ConfigurationModel configure(@NonNull HttpUrl serverUrl) {
    if (serverUrl == null) {
        throw new IllegalArgumentException("serverUrl == null");
    }
    List<String> pathSegments = serverUrl.pathSegments();
    if (!"".equals(pathSegments.get(pathSegments.size() - 1))) {
        throw new IllegalArgumentException("baseUrl must end in /: " + serverUrl);
    }
    HttpUrl baseUrl = canonizeBaseUrl(serverUrl);
    long configurationId = configurationStore.save(baseUrl.toString());
    return ConfigurationModel.builder().id(configurationId).serverUrl(baseUrl).build();
}
Also used : HttpUrl(okhttp3.HttpUrl) NonNull(android.support.annotation.NonNull)

Example 57 with HttpUrl

use of okhttp3.HttpUrl in project dhis2-android-sdk by dhis2.

the class ConfigurationManagerShould method thrown_illegal_argument_exception_when_configure_not_canonized_url.

@Test
public void thrown_illegal_argument_exception_when_configure_not_canonized_url() {
    HttpUrl baseUrlWithoutTrailingSlash = HttpUrl.parse("https://play.dhis2.org/demo");
    try {
        configurationManager.configure(baseUrlWithoutTrailingSlash);
        fail("illegalArgumentException was expected but nothing was thrown");
    } catch (IllegalArgumentException illegalArgumentException) {
        verify(configurationStore, never()).save(anyString());
    }
}
Also used : HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Example 58 with HttpUrl

use of okhttp3.HttpUrl in project dhis2-android-sdk by dhis2.

the class ConfigurationManagerShould method invoke_save_configuration_store_when_configuration_manager_configure_a_valid_base_url.

@Test
public void invoke_save_configuration_store_when_configuration_manager_configure_a_valid_base_url() {
    HttpUrl baseUrl = HttpUrl.parse("https://play.dhis2.org/demo/");
    ConfigurationModel configurationModel = configurationManager.configure(baseUrl);
    assertThat(configurationModel.serverUrl().toString()).isEqualTo("https://play.dhis2.org/demo/api/");
    verify(configurationStore).save("https://play.dhis2.org/demo/api/");
}
Also used : HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Example 59 with HttpUrl

use of okhttp3.HttpUrl in project incubator-skywalking by apache.

the class RealCallInterceptor method beforeMethod.

/**
 * Get the {@link okhttp3.Request} from {@link EnhancedInstance}, then create {@link AbstractSpan} and set host,
 * port, kind, component, url from {@link okhttp3.Request}.
 * Through the reflection of the way, set the http header of context data into {@link okhttp3.Request#headers}.
 *
 * @param method
 * @param result change this result, if you want to truncate the method.
 * @throws Throwable
 */
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    Request request = (Request) objInst.getSkyWalkingDynamicField();
    ContextCarrier contextCarrier = new ContextCarrier();
    HttpUrl requestUrl = request.url();
    AbstractSpan span = ContextManager.createExitSpan(requestUrl.uri().getPath(), contextCarrier, requestUrl.host() + ":" + requestUrl.port());
    span.setComponent(ComponentsDefine.OKHTTP);
    Tags.HTTP.METHOD.set(span, request.method());
    Tags.URL.set(span, requestUrl.uri().toString());
    SpanLayer.asHttp(span);
    Field headersField = Request.class.getDeclaredField("headers");
    Field modifiersField = Field.class.getDeclaredField("modifiers");
    modifiersField.setAccessible(true);
    modifiersField.setInt(headersField, headersField.getModifiers() & ~Modifier.FINAL);
    headersField.setAccessible(true);
    Headers.Builder headerBuilder = request.headers().newBuilder();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        headerBuilder.add(next.getHeadKey(), next.getHeadValue());
    }
    headersField.set(request, headerBuilder.build());
}
Also used : Field(java.lang.reflect.Field) ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) Headers(okhttp3.Headers) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 60 with HttpUrl

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

the class ConnectUrlHelperTest method chromeCustomTabBrowserTypeOnGetAuthorizeUriReturnsChromeCustomTabParam.

@Test
public void chromeCustomTabBrowserTypeOnGetAuthorizeUriReturnsChromeCustomTabParam() {
    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.CHROME_CUSTOM_TAB);
    assertThat(authorizeUri.getQueryParameter("telenordigital_sdk_version").endsWith("chrome-custom-tab"), is(true));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Uri(android.net.Uri) HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

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