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();
}
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());
}
}
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/");
}
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());
}
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));
}
Aggregations