use of org.prebid.mobile.rendering.networking.BaseNetworkTask in project prebid-mobile-android by prebid.
the class GetOriginalUrlTaskTest method testCustomParserWith200Code.
@Test
public void testCustomParserWith200Code() throws IOException {
mServer.enqueue(new MockResponse().setResponseCode(200).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("Content-Type", "text/html; charset=UTF-8");
BaseNetworkTask.GetUrlResult res = baseNetworkTask.customParser(200, con);
Assert.assertNull("should have content type as: null(for code:200), but got: " + res.contentType, res.contentType);
Assert.assertFalse("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]));
assertTrue("should have JSRedirectURI[2]: 'quit' but got: " + res.JSRedirectURI[2], "quit".equals(res.JSRedirectURI[2]));
}
use of org.prebid.mobile.rendering.networking.BaseNetworkTask in project prebid-mobile-android by prebid.
the class Requester method sendAdRequest.
protected void sendAdRequest(URLComponents jsonUrlComponents) {
BaseNetworkTask.GetUrlParams params = new BaseNetworkTask.GetUrlParams();
params.url = jsonUrlComponents.getBaseUrl();
params.queryParams = jsonUrlComponents.getQueryArgString();
params.requestType = "POST";
params.userAgent = AppInfoManager.getUserAgent();
params.name = mRequestName;
BaseNetworkTask networkTask = new BaseNetworkTask(mAdResponseCallBack);
mNetworkTask = networkTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
}
use of org.prebid.mobile.rendering.networking.BaseNetworkTask in project prebid-mobile-android by prebid.
the class AsyncVastLoader method loadVast.
public void loadVast(String vastUrl, BaseResponseHandler responseHandler) {
cancelTask();
BaseNetworkTask videoRequestTask = new BaseNetworkTask(responseHandler);
BaseNetworkTask.GetUrlParams params = Utils.parseUrl(vastUrl);
params.userAgent = AppInfoManager.getUserAgent();
if (vastUrl != null) {
params.requestType = "GET";
params.name = "videorequest";
}
mVideoRequestAsyncTask = videoRequestTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
}
use of org.prebid.mobile.rendering.networking.BaseNetworkTask in project prebid-mobile-android by prebid.
the class ServerConnection method fireWithResult.
public static void fireWithResult(String url, ResponseHandler responseHandler) {
BaseNetworkTask networkTask = new BaseNetworkTask(responseHandler);
BaseNetworkTask.GetUrlParams params = new BaseNetworkTask.GetUrlParams();
params.url = url;
params.requestType = "GET";
params.userAgent = AppInfoManager.getUserAgent();
params.name = "recordevents";
networkTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
}
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());
}
}
Aggregations