Search in sources :

Example 1 with VastParseError

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

the class VastParserExtractor method performVastUnwrap.

private void performVastUnwrap(String vast) {
    if (!vast.contains("VAST version")) {
        final AdException adException = new AdException(AdException.INTERNAL_ERROR, VASTErrorCodes.VAST_SCHEMA_ERROR.toString());
        mListener.onResult(createExtractorFailureResult(adException));
        return;
    }
    mVastWrapperCount++;
    // A new response has come back, either from the initial VAST request or a wrapper request.
    // Parse the response.
    AdResponseParserVast adResponseParserVast;
    try {
        adResponseParserVast = new AdResponseParserVast(vast);
    } catch (VastParseError e) {
        LogUtil.error(TAG, "AdResponseParserVast creation failed: " + Log.getStackTraceString(e));
        final AdException adException = new AdException(AdException.INTERNAL_ERROR, e.getMessage());
        mListener.onResult(createExtractorFailureResult(adException));
        return;
    }
    // Check if this is the response from the initial request or from unwrapping a wrapper
    if (mRootVastParser == null) {
        // If mRootVastParser doesn't exist then it is the initial VAST request
        LogUtil.debug(TAG, "Initial VAST Request");
        mRootVastParser = adResponseParserVast;
    } else {
        // Otherwise, this is the result of unwrapping a Wrapper.
        LogUtil.debug(TAG, "Unwrapping VAST Wrapper");
        mLatestVastWrapperParser.setWrapper(adResponseParserVast);
    }
    mLatestVastWrapperParser = adResponseParserVast;
    // Check if this response is a wrapper
    String vastUrl = mLatestVastWrapperParser.getVastUrl();
    if (!TextUtils.isEmpty(vastUrl)) {
        if (mVastWrapperCount >= WRAPPER_NESTING_LIMIT) {
            final AdException adException = new AdException(AdException.INTERNAL_ERROR, VASTErrorCodes.WRAPPER_LIMIT_REACH_ERROR.toString());
            final VastExtractorResult extractorFailureResult = createExtractorFailureResult(adException);
            mListener.onResult(extractorFailureResult);
            mVastWrapperCount = 0;
            return;
        }
        mAsyncVastLoader.loadVast(vastUrl, mResponseHandler);
    } else {
        final AdResponseParserBase[] parserArray = { mRootVastParser, mLatestVastWrapperParser };
        mListener.onResult(new VastExtractorResult(parserArray));
    }
}
Also used : VastParseError(org.prebid.mobile.rendering.errors.VastParseError) AdResponseParserBase(org.prebid.mobile.rendering.parser.AdResponseParserBase) AdResponseParserVast(org.prebid.mobile.rendering.parser.AdResponseParserVast) VastExtractorResult(org.prebid.mobile.rendering.models.internal.VastExtractorResult) AdException(org.prebid.mobile.rendering.errors.AdException)

Example 2 with VastParseError

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

the class AdResponseParserVastTest method testWrongVastThrowError.

@Test
public void testWrongVastThrowError() throws IOException {
    String wrongvast = ResourceUtils.convertResourceToString(WRONG_VAST);
    AdResponseParserVastHelper vast = null;
    VastParseError error = null;
    try {
        vast = new AdResponseParserVastHelper(wrongvast);
    } catch (VastParseError vastParseError) {
        vastParseError.printStackTrace();
        error = vastParseError;
    }
    assertNotNull("Syntax error for inline->impressoin", error);
    assertTrue(error instanceof VastParseError);
    assertNull(vast);
}
Also used : VastParseError(org.prebid.mobile.rendering.errors.VastParseError) Test(org.junit.Test)

Example 3 with VastParseError

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

the class AdResponseParserVastTest method testVastWithNoVersion.

@Test
public void testVastWithNoVersion() {
    String vast = "<VAST > </VAST>";
    AdResponseParserVastHelper vastParserHelper = null;
    VastParseError error = null;
    try {
        vastParserHelper = new AdResponseParserVastHelper(vast);
    } catch (VastParseError vastParseError) {
        vastParseError.printStackTrace();
        error = vastParseError;
    }
    assertNull(vastParserHelper.getVast().getVersion());
    assertNull(error);
}
Also used : VastParseError(org.prebid.mobile.rendering.errors.VastParseError) Test(org.junit.Test)

Example 4 with VastParseError

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

the class AdResponseParserVastTest method testVastWithNoAd.

@Test
public void testVastWithNoAd() throws IOException {
    String vast_noad = ResourceUtils.convertResourceToString(WRONG_VAST_WITH_NO_AD);
    AdResponseParserVastHelper vastParserHelper = null;
    VastParseError error = null;
    try {
        vastParserHelper = new AdResponseParserVastHelper(vast_noad);
    } catch (VastParseError vastParseError) {
        vastParseError.printStackTrace();
        error = vastParseError;
    }
    assertNull(vastParserHelper.getVast().getAds());
    assertNull(error);
}
Also used : VastParseError(org.prebid.mobile.rendering.errors.VastParseError) Test(org.junit.Test)

Aggregations

VastParseError (org.prebid.mobile.rendering.errors.VastParseError)4 Test (org.junit.Test)3 AdException (org.prebid.mobile.rendering.errors.AdException)1 VastExtractorResult (org.prebid.mobile.rendering.models.internal.VastExtractorResult)1 AdResponseParserBase (org.prebid.mobile.rendering.parser.AdResponseParserBase)1 AdResponseParserVast (org.prebid.mobile.rendering.parser.AdResponseParserVast)1