use of org.prebid.mobile.rendering.networking.BaseNetworkTask in project prebid-mobile-android by prebid.
the class GetOriginalUrlTaskTest method testCustomParserWith301Code.
@Test
public void testCustomParserWith301Code() throws IOException {
mServer.enqueue(new MockResponse().setResponseCode(301).setBody("this is a success response"));
GetOriginalUrlTask baseNetworkTask = new GetOriginalUrlTask(null);
HttpUrl baseUrl = mServer.url("/first");
URL uUrl = new URL(baseUrl.url().toString());
HttpURLConnection con = (HttpURLConnection) uUrl.openConnection();
con.setInstanceFollowRedirects(false);
con.setRequestProperty(ResourceUtils.USER_AGENT_HEADER, "Mozilla/5.0 (Linux; U; Android " + android.os.Build.VERSION.RELEASE + ";" + " ");
con.setRequestProperty(ResourceUtils.ACCEPT_LANGUAGE_HEADER, Locale.getDefault().toString());
con.setRequestProperty(ResourceUtils.ACCEPT_ENCODING_HEADER, "gzip");
con.setRequestProperty(ResourceUtils.ACCEPT_HEADER, ResourceUtils.ACCEPT_HEADER_VALUE);
con.setRequestProperty("Location", "www.MenloPark.com");
con.setRequestProperty("Content-Type", "text/html; charset=UTF-8");
BaseNetworkTask.GetUrlResult res = baseNetworkTask.customParser(301, con);
Assert.assertNull("should have content type as: null(for code:301), but got: " + res.contentType, res.contentType);
assertTrue("should have JSRedirectURI[0]: 'www.MenloPark.com' but got: " + res.JSRedirectURI[0], "www.MenloPark.com".equals(res.JSRedirectURI[0]));
assertTrue("should have JSRedirectURI[1]: 'text/html; charset=UTF-8' but got: " + res.JSRedirectURI[1], "text/html; charset=UTF-8".equals(res.JSRedirectURI[1]));
}
use of org.prebid.mobile.rendering.networking.BaseNetworkTask in project prebid-mobile-android by prebid.
the class MockServerTest method redirectResponseCodeTest.
@Test
public void redirectResponseCodeTest() throws Exception {
mServer.enqueue(new MockResponse().setResponseCode(302));
mServer.enqueue(new MockResponse().setResponseCode(307));
mServer.start();
BaseNetworkTask.GetUrlParams params = new BaseNetworkTask.GetUrlParams();
params.name = "foo";
params.requestType = "GET";
params.userAgent = "user-agent";
HttpUrl baseUrl = mServer.url("/test");
params.url = baseUrl.url().toString();
// HTTP 302
try {
BaseNetworkTask baseNetworkTask = new BaseNetworkTask(null);
baseNetworkTask.sendRequest(params);
} catch (Exception e) {
assertEquals("Bad server response - [HTTP Response code of 302]", e.getMessage());
}
// HTTP 307
try {
BaseNetworkTask baseNetworkTask = new BaseNetworkTask(null);
baseNetworkTask.sendRequest(params);
} catch (Exception e) {
assertEquals("Bad server response - [HTTP Response code of 307]", e.getMessage());
}
}
use of org.prebid.mobile.rendering.networking.BaseNetworkTask in project prebid-mobile-android by prebid.
the class ServerConnection method fireAndForgetImpressionUrl.
public static void fireAndForgetImpressionUrl(String impressionUrl) {
BaseNetworkTask.GetUrlParams params = new BaseNetworkTask.GetUrlParams();
params.url = impressionUrl;
params.requestType = "GET";
params.userAgent = AppInfoManager.getUserAgent();
params.name = BaseNetworkTask.REDIRECT_TASK;
BaseNetworkTask networkTask = new ImpressionUrlTask(null);
networkTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
}
Aggregations