Search in sources :

Example 16 with AdException

use of org.prebid.mobile.rendering.errors.AdException in project prebid-mobile-android by prebid.

the class ImpressionUrlTask method openConnectionCheckRedirects.

private GetUrlResult openConnectionCheckRedirects(URLConnection urlConnection) throws IOException, AdException {
    GetUrlResult result = new GetUrlResult();
    boolean redir = true;
    int redirects = 0;
    String response = "";
    while (redir) {
        if (!(urlConnection instanceof HttpURLConnection)) {
            LogUtil.error(TAG, "Redirect fail for impression event");
            return null;
        }
        ((HttpURLConnection) urlConnection).setInstanceFollowRedirects(false);
        HttpURLConnection http = (HttpURLConnection) urlConnection;
        int httpResponseCode = http.getResponseCode();
        if (httpResponseCode >= 300 && httpResponseCode <= 307 && httpResponseCode != 306 && httpResponseCode != HttpURLConnection.HTTP_NOT_MODIFIED) {
            // Base url
            URL base = http.getURL();
            // new url to forward to
            String loc = http.getHeaderField("Location");
            URL target = null;
            if (loc != null) {
                target = new URL(base, loc);
            }
            http.disconnect();
            // TODO: check with iOS on the limitation
            if (target == null || !(target.getProtocol().equals("http") || target.getProtocol().equals("https")) || redirects >= MAX_REDIRECTS) {
                throw new SecurityException("illegal URL redirect");
            }
            redir = true;
            urlConnection = target.openConnection();
            redirects++;
        } else // We probably do not need to worry abt other status codes for tracking events, as we do not do any retry of these events, if it's !=200
        if (httpResponseCode == 200) {
            response = readResponse(urlConnection.getInputStream());
            redir = false;
        } else {
            String error = String.format("Redirect error - Bad server response - [HTTP Response code of %s]", httpResponseCode);
            LogUtil.error(TAG, error);
            // Don't set exception on result. But instead just bail out with an error log
            throw new AdException(AdException.SERVER_ERROR, error);
        }
    }
    // We do not even need to handle this response for tracking events. It's fire & forget.
    result.responseString = response;
    return result;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) URL(java.net.URL) AdException(org.prebid.mobile.rendering.errors.AdException)

Example 17 with AdException

use of org.prebid.mobile.rendering.errors.AdException in project prebid-mobile-android by prebid.

the class Requester method sendAdException.

private void sendAdException(String logMsg, String exceptionMsg) {
    LogUtil.warn(TAG, logMsg);
    AdException adException = new AdException(AdException.INIT_ERROR, exceptionMsg);
    mAdResponseCallBack.onErrorWithException(adException, 0);
}
Also used : AdException(org.prebid.mobile.rendering.errors.AdException)

Example 18 with AdException

use of org.prebid.mobile.rendering.errors.AdException in project prebid-mobile-android by prebid.

the class HTMLCreativeTest method loadTest.

@Test
public void loadTest() throws Exception {
    PrebidWebViewBanner mockPrebidWebViewBanner = mock(PrebidWebViewBanner.class);
    ViewPool mockViewPool = mock(ViewPool.class);
    when(mockViewPool.getUnoccupiedView(any(Context.class), any(), any(AdConfiguration.AdUnitIdentifierType.class), any(InterstitialManager.class))).thenReturn(mockPrebidWebViewBanner);
    WhiteBox.field(ViewPool.class, "sInstance").set(null, mockViewPool);
    // Test null context
    try {
        WhiteBox.field(HTMLCreative.class, "mContextReference").set(mHtmlCreative, null);
        mHtmlCreative.load();
        fail("AdException was NOT thrown");
    } catch (AdException e) {
    }
    mHtmlCreative = new HTMLCreative(mContext, mMockModel, mMockOmAdSessionManager, mMockInterstitialManager);
    // Test null adType
    try {
        mHtmlCreative.load();
        fail("AdException was NOT thrown");
    } catch (AdException e) {
    }
    // Test empty html
    try {
        when(mMockConfig.getAdUnitIdentifierType()).thenReturn(AdConfiguration.AdUnitIdentifierType.BANNER);
        mHtmlCreative = new HTMLCreative(mContext, mMockModel, mMockOmAdSessionManager, mMockInterstitialManager);
        mHtmlCreative.load();
        fail("AdException was NOT thrown");
    } catch (AdException e) {
    }
    // Test non-empty html
    when(mMockConfig.getAdUnitIdentifierType()).thenReturn(AdConfiguration.AdUnitIdentifierType.BANNER);
    when(mMockModel.getHtml()).thenReturn("foo");
    mHtmlCreative = new HTMLCreative(mContext, mMockModel, mMockOmAdSessionManager, mMockInterstitialManager);
    mHtmlCreative.load();
    verify(mockPrebidWebViewBanner).loadHTML(any(), anyInt(), anyInt());
    assertEquals(mockPrebidWebViewBanner, mHtmlCreative.getCreativeView());
}
Also used : Context(android.content.Context) InterstitialManager(org.prebid.mobile.rendering.views.interstitial.InterstitialManager) PrebidWebViewBanner(org.prebid.mobile.rendering.views.webview.PrebidWebViewBanner) AdException(org.prebid.mobile.rendering.errors.AdException) Test(org.junit.Test)

Example 19 with AdException

use of org.prebid.mobile.rendering.errors.AdException in project prebid-mobile-android by prebid.

the class BaseInterstitialAdUnitTest method setUp.

@Before
public void setUp() throws Exception {
    Context context = Robolectric.buildActivity(Activity.class).create().get();
    mBaseInterstitialAdUnit = new BaseInterstitialAdUnit(context) {

        @Override
        void requestAdWithBid(@Nullable Bid bid) {
        }

        @Override
        void showGamAd() {
        }

        @Override
        void notifyAdEventListener(AdListenerEvent adListenerEvent) {
        }

        @Override
        void notifyErrorListener(AdException exception) {
        }
    };
    final AdConfiguration adUnitConfiguration = new AdConfiguration();
    mBaseInterstitialAdUnit.init(adUnitConfiguration);
    assertEquals(AdPosition.FULLSCREEN.getValue(), adUnitConfiguration.getAdPositionValue());
}
Also used : Context(android.content.Context) AdConfiguration(org.prebid.mobile.rendering.models.AdConfiguration) Bid(org.prebid.mobile.rendering.bidding.data.bid.Bid) AdException(org.prebid.mobile.rendering.errors.AdException) Before(org.junit.Before)

Example 20 with AdException

use of org.prebid.mobile.rendering.errors.AdException in project prebid-mobile-android by prebid.

the class RewardedAdUnitTest method onFailedAndWithWinnerBid_ExecuteInterstitialControllerLoadAd.

@Test
public void onFailedAndWithWinnerBid_ExecuteInterstitialControllerLoadAd() throws IllegalAccessException {
    final BidResponse mockBidResponse = mock(BidResponse.class);
    final InterstitialController mockInterstitialController = mock(InterstitialController.class);
    final Bid mockBid = mock(Bid.class);
    final RewardedVideoEventListener spyEventListener = spy(getEventListener());
    when(mockBidResponse.getWinningBid()).thenReturn(mockBid);
    WhiteBox.setInternalState(mRewardedAdUnit, "mBidResponse", mockBidResponse);
    WhiteBox.setInternalState(mRewardedAdUnit, "mInterstitialController", mockInterstitialController);
    spyEventListener.onAdFailed(new AdException(AdException.INTERNAL_ERROR, "Test"));
    verify(spyEventListener, times(1)).onPrebidSdkWin();
    verify(mockInterstitialController, times(1)).loadAd(any(), any());
}
Also used : InterstitialController(org.prebid.mobile.rendering.bidding.display.InterstitialController) BidResponse(org.prebid.mobile.rendering.bidding.data.bid.BidResponse) Bid(org.prebid.mobile.rendering.bidding.data.bid.Bid) RewardedVideoEventListener(org.prebid.mobile.rendering.bidding.listeners.RewardedVideoEventListener) AdException(org.prebid.mobile.rendering.errors.AdException) Test(org.junit.Test)

Aggregations

AdException (org.prebid.mobile.rendering.errors.AdException)54 Test (org.junit.Test)25 InterstitialController (org.prebid.mobile.rendering.bidding.display.InterstitialController)7 AdConfiguration (org.prebid.mobile.rendering.models.AdConfiguration)6 AdError (com.google.android.gms.ads.AdError)5 BidResponse (org.prebid.mobile.rendering.bidding.data.bid.BidResponse)5 Bid (org.prebid.mobile.rendering.bidding.data.bid.Bid)4 InterstitialControllerListener (org.prebid.mobile.rendering.bidding.interfaces.InterstitialControllerListener)4 CreativeModel (org.prebid.mobile.rendering.models.CreativeModel)4 InterstitialManager (org.prebid.mobile.rendering.views.interstitial.InterstitialManager)4 Context (android.content.Context)2 Bundle (android.os.Bundle)2 NonNull (androidx.annotation.NonNull)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 InterstitialView (org.prebid.mobile.rendering.bidding.display.InterstitialView)2 BannerEventListener (org.prebid.mobile.rendering.bidding.listeners.BannerEventListener)2 InterstitialEventListener (org.prebid.mobile.rendering.bidding.listeners.InterstitialEventListener)2 RewardedVideoEventListener (org.prebid.mobile.rendering.bidding.listeners.RewardedVideoEventListener)2 VastExtractorResult (org.prebid.mobile.rendering.models.internal.VastExtractorResult)2