Search in sources :

Example 6 with BaseNetworkTask

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]));
}
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 7 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)

Example 8 with BaseNetworkTask

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

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