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;
}
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);
}
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());
}
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());
}
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());
}
Aggregations