Beispiel #1
0
 /**
  * Custom constructor
  *
  * @param site id of the app/site
  * @param zone id of the ad placement
  * @param data data retrieved from the main adserver
  * @param id id of the backfill partner (0 = Smartstream)
  */
 public BackfillData(String site, String zone, String data, int id) {
   this.data = data;
   this.userAgent = SdkUtil.getUserAgent();
   this.siteId = site;
   this.zoneId = zone;
   this.id = id;
 }
Beispiel #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;
 }