package com.worklight.wlclient;

import com.worklight.common.Logger;
import java.io.IOException;
import java.net.URI;
import java.util.Date;
import java.util.UUID;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
import org.json.JSONObject;

class HttpPostRequestSender
  implements Runnable
{
  private static Logger logger = Logger.getInstance("HttpPostRequestSender");
  HttpPost httpRequest;
  HttpPostListener listener;
  int requestTimeoutMs;

  protected HttpPostRequestSender(HttpPost paramHttpPost, int paramInt, HttpPostListener paramHttpPostListener)
  {
    this.httpRequest = paramHttpPost;
    this.requestTimeoutMs = paramInt;
    this.listener = paramHttpPostListener;
  }

  private void logInboundResponse(String paramString, HttpEntity paramHttpEntity)
  {
    try
    {
      new JSONObject();
      long l1 = new Date().getTime();
      JSONObject localJSONObject = new JSONObject();
      localJSONObject.put("$path", this.httpRequest.getURI().getPath());
      localJSONObject.put("$category", "network");
      localJSONObject.put("$trackingid", paramString);
      localJSONObject.put("$type", "response");
      localJSONObject.put("$time", l1);
      if (paramHttpEntity == null);
      long l2;
      for (long l3 = 0L; ; l3 = l2)
      {
        if (l3 != -1L)
          localJSONObject.put("$bytes", l3);
        logger.analytics("InternalRequestSender inbound", localJSONObject);
        return;
        l2 = paramHttpEntity.getContentLength();
      }
    }
    catch (Exception localException)
    {
    }
  }

  private void logOutboundRequest(String paramString)
  {
    try
    {
      long l = new Date().getTime();
      JSONObject localJSONObject = new JSONObject();
      localJSONObject.put("$path", this.httpRequest.getURI().getPath());
      localJSONObject.put("$category", "network");
      localJSONObject.put("$trackingid", paramString);
      localJSONObject.put("$type", "request");
      localJSONObject.put("$time", l);
      logger.analytics("InternalRequestSender outbound", localJSONObject);
      return;
    }
    catch (Exception localException)
    {
    }
  }

  public void run()
  {
    logger.debug("Sending request " + this.httpRequest.getURI());
    try
    {
      DefaultHttpClient localDefaultHttpClient = HttpClientManager.getInstance().getHttpClient();
      HttpContext localHttpContext = HttpClientManager.getInstance().getHttpContext();
      HttpConnectionParams.setSoTimeout(localDefaultHttpClient.getParams(), this.requestTimeoutMs);
      HttpConnectionParams.setConnectionTimeout(localDefaultHttpClient.getParams(), this.requestTimeoutMs);
      localDefaultHttpClient.getParams().setParameter("http.useragent", HttpClientManager.getInstance().getWebViewUserAgent());
      String str = UUID.randomUUID().toString();
      this.httpRequest.addHeader("x-wl-analytics-tracking-id", str);
      logOutboundRequest(str);
      HttpResponse localHttpResponse = localDefaultHttpClient.execute(this.httpRequest, localHttpContext);
      logInboundResponse(str, localHttpResponse.getEntity());
      this.listener.onResponse(localHttpResponse);
      return;
    }
    catch (ClientProtocolException localClientProtocolException)
    {
      this.listener.onException(localClientProtocolException);
      return;
    }
    catch (IOException localIOException)
    {
      this.listener.onException(localIOException);
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.worklight.wlclient.HttpPostRequestSender
 * JD-Core Version:    0.6.2
 */