Пример #1
0
  /**
   * Parses the main adserver response for backfill information and returns an appropriate
   * BackfillData object if something was actually found
   *
   * @param data the main adserver response body
   * @return null if no backfill was detected, a valid BackfillData object otherwise
   * @de.guj.ems.mobile.sdk.controllers.BackfillDelegator.BackfillData
   */
  public static final BackfillData isBackfill(String adSpace, String data) {

    // TODO remove when Smartstream is fixed for 4.4
    if (Build.VERSION.SDK_INT >= 19) {
      return null;
    }
    if (data == null
        || data.startsWith("<div")
        || data.startsWith("<!DOC")
        || data.startsWith("<html")
        || data.startsWith("<VAST")
        || data.startsWith("<!-- <connectad>")) {
      return null;
    }
    SdkLog.d(TAG, "Checking string " + data + " for backfill...");
    for (int i = 0; i < BACK_FILL_OPEN.length; i++) {
      if (data.startsWith(BACK_FILL_OPEN[i])) {
        return new BackfillData(
            adSpace,
            data.substring(BACK_FILL_OPEN[i].length(), data.indexOf(BACK_FILL_CLOSE[i])),
            i);
      }
    }

    return null;
  }
Пример #2
0
 @Override
 protected IAdResponse httpGet(String url) {
   // from Gingerbread on it is recommended to use HttpUrlConnection
   if (TrackingRequest.USE_HTTPURLCONNECTION) {
     SdkLog.d(TAG, "Younger than Froyo - using HttpUrlConnection.");
     HttpURLConnection con = null;
     try {
       URL uUrl = new URL(url);
       con = (HttpURLConnection) uUrl.openConnection();
       con.setRequestProperty(USER_AGENT_HEADER_NAME, SdkUtil.getUserAgent());
       con.setReadTimeout(2500);
       con.setConnectTimeout(2500);
       BufferedInputStream in = new BufferedInputStream(con.getInputStream());
       if (con.getResponseCode() != 200) {
         throw new Exception("Server returned HTTP " + con.getResponseCode());
       }
       in.close();
     } catch (Exception e) {
       setLastError(e);
     } finally {
       if (con != null) {
         con.disconnect();
         SdkLog.d(TAG, "Request finished.");
       }
     }
   }
   // before Gingerbread, DefaultHttpClient should be used
   else {
     SdkLog.d(TAG, "Older than Gingerbread - using DefaultHttpClient.");
     HttpParams httpParameters = new BasicHttpParams();
     HttpConnectionParams.setConnectionTimeout(httpParameters, 500);
     HttpConnectionParams.setSoTimeout(httpParameters, 1000);
     DefaultHttpClient client = new DefaultHttpClient(httpParameters);
     HttpGet httpGet = new HttpGet(url);
     httpGet.setHeader(USER_AGENT_HEADER_NAME, SdkUtil.getUserAgent());
     try {
       HttpResponse execute = client.execute(httpGet);
       if (execute.getStatusLine().getStatusCode() != 200) {
         throw new Exception("Server returned HTTP " + execute.getStatusLine().getStatusCode());
       }
     } catch (Exception e) {
       setLastError(e);
     }
     SdkLog.d(TAG, "Request finished.");
   }
   return null;
 }