Search in sources :

Example 1 with BaseNetworkTask

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]));
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) HttpURLConnection(java.net.HttpURLConnection) GetUrlResult(org.prebid.mobile.rendering.networking.BaseNetworkTask.GetUrlResult) BaseNetworkTask(org.prebid.mobile.rendering.networking.BaseNetworkTask) HttpUrl(okhttp3.HttpUrl) URL(java.net.URL) Test(org.junit.Test)

Example 2 with BaseNetworkTask

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);
}
Also used : BaseNetworkTask(org.prebid.mobile.rendering.networking.BaseNetworkTask)

Example 3 with BaseNetworkTask

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);
}
Also used : BaseNetworkTask(org.prebid.mobile.rendering.networking.BaseNetworkTask)

Example 4 with BaseNetworkTask

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);
}
Also used : BaseNetworkTask(org.prebid.mobile.rendering.networking.BaseNetworkTask)

Example 5 with BaseNetworkTask

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());
    }
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) BaseNetworkTask(org.prebid.mobile.rendering.networking.BaseNetworkTask) HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Aggregations

BaseNetworkTask (org.prebid.mobile.rendering.networking.BaseNetworkTask)8 HttpUrl (okhttp3.HttpUrl)4 MockResponse (okhttp3.mockwebserver.MockResponse)4 Test (org.junit.Test)4 HttpURLConnection (java.net.HttpURLConnection)3 URL (java.net.URL)3 GetUrlResult (org.prebid.mobile.rendering.networking.BaseNetworkTask.GetUrlResult)3