RequestManager.java 13.8 KB
package com.arellomobile.android.push.request;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import com.arellomobile.android.push.utils.PreferenceUtils;
import java.util.Map;
import org.json.JSONObject;

public class RequestManager
{
  public static final int MAX_TRIES = 1;
  public static boolean useSSL = false;
  
  /* Error */
  private static NetworkResult a(Context paramContext, Map<String, Object> paramMap, String paramString)
    throws Exception
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore 6
    //   3: new 6	com/arellomobile/android/push/request/RequestManager$NetworkResult
    //   6: dup
    //   7: sipush 500
    //   10: iconst_0
    //   11: aconst_null
    //   12: invokespecial 27	com/arellomobile/android/push/request/RequestManager$NetworkResult:<init>	(IILorg/json/JSONObject;)V
    //   15: astore 7
    //   17: aload_0
    //   18: invokestatic 33	com/arellomobile/android/push/utils/PreferenceUtils:getBaseUrl	(Landroid/content/Context;)Ljava/lang/String;
    //   21: astore 5
    //   23: aload 5
    //   25: astore 4
    //   27: aload 5
    //   29: invokestatic 39	android/text/TextUtils:isEmpty	(Ljava/lang/CharSequence;)Z
    //   32: ifeq +9 -> 41
    //   35: aload_0
    //   36: invokestatic 41	com/arellomobile/android/push/request/RequestManager:a	(Landroid/content/Context;)Ljava/lang/String;
    //   39: astore 4
    //   41: aload 4
    //   43: astore 5
    //   45: aload 4
    //   47: ldc 43
    //   49: invokevirtual 49	java/lang/String:endsWith	(Ljava/lang/String;)Z
    //   52: ifne +25 -> 77
    //   55: new 51	java/lang/StringBuilder
    //   58: dup
    //   59: invokespecial 52	java/lang/StringBuilder:<init>	()V
    //   62: aload 4
    //   64: invokevirtual 56	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   67: ldc 43
    //   69: invokevirtual 56	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   72: invokevirtual 60	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   75: astore 5
    //   77: aload_0
    //   78: aload 5
    //   80: invokestatic 64	com/arellomobile/android/push/utils/PreferenceUtils:setBaseUrl	(Landroid/content/Context;Ljava/lang/String;)V
    //   83: new 66	java/net/URL
    //   86: dup
    //   87: new 51	java/lang/StringBuilder
    //   90: dup
    //   91: invokespecial 52	java/lang/StringBuilder:<init>	()V
    //   94: aload 5
    //   96: invokevirtual 56	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   99: aload_2
    //   100: invokevirtual 56	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   103: invokevirtual 60	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   106: invokespecial 69	java/net/URL:<init>	(Ljava/lang/String;)V
    //   109: invokevirtual 73	java/net/URL:openConnection	()Ljava/net/URLConnection;
    //   112: checkcast 75	java/net/HttpURLConnection
    //   115: astore 4
    //   117: aload 4
    //   119: ldc 77
    //   121: invokevirtual 80	java/net/HttpURLConnection:setRequestMethod	(Ljava/lang/String;)V
    //   124: aload 4
    //   126: ldc 82
    //   128: ldc 84
    //   130: invokevirtual 88	java/net/HttpURLConnection:setRequestProperty	(Ljava/lang/String;Ljava/lang/String;)V
    //   133: aload 4
    //   135: iconst_1
    //   136: invokevirtual 92	java/net/HttpURLConnection:setDoOutput	(Z)V
    //   139: new 94	org/json/JSONObject
    //   142: dup
    //   143: invokespecial 95	org/json/JSONObject:<init>	()V
    //   146: astore_2
    //   147: aload_2
    //   148: ldc 97
    //   150: aload_1
    //   151: invokestatic 103	com/arellomobile/android/push/utils/JsonUtils:mapToJson	(Ljava/util/Map;)Lorg/json/JSONObject;
    //   154: invokevirtual 107	org/json/JSONObject:put	(Ljava/lang/String;Ljava/lang/Object;)Lorg/json/JSONObject;
    //   157: pop
    //   158: aload 4
    //   160: ldc 109
    //   162: aload_2
    //   163: invokevirtual 110	org/json/JSONObject:toString	()Ljava/lang/String;
    //   166: invokevirtual 114	java/lang/String:getBytes	()[B
    //   169: arraylength
    //   170: invokestatic 118	java/lang/String:valueOf	(I)Ljava/lang/String;
    //   173: invokevirtual 88	java/net/HttpURLConnection:setRequestProperty	(Ljava/lang/String;Ljava/lang/String;)V
    //   176: aload 4
    //   178: invokevirtual 122	java/net/HttpURLConnection:getOutputStream	()Ljava/io/OutputStream;
    //   181: astore_1
    //   182: aload_1
    //   183: aload_2
    //   184: invokevirtual 110	org/json/JSONObject:toString	()Ljava/lang/String;
    //   187: invokevirtual 114	java/lang/String:getBytes	()[B
    //   190: invokevirtual 128	java/io/OutputStream:write	([B)V
    //   193: aload_1
    //   194: invokevirtual 131	java/io/OutputStream:flush	()V
    //   197: aload_1
    //   198: invokevirtual 134	java/io/OutputStream:close	()V
    //   201: new 136	java/io/BufferedInputStream
    //   204: dup
    //   205: aload 4
    //   207: invokevirtual 140	java/net/HttpURLConnection:getInputStream	()Ljava/io/InputStream;
    //   210: invokespecial 143	java/io/BufferedInputStream:<init>	(Ljava/io/InputStream;)V
    //   213: astore_2
    //   214: new 145	java/io/ByteArrayOutputStream
    //   217: dup
    //   218: invokespecial 146	java/io/ByteArrayOutputStream:<init>	()V
    //   221: astore 5
    //   223: sipush 1024
    //   226: newarray <illegal type>
    //   228: astore 6
    //   230: aload_2
    //   231: aload 6
    //   233: invokevirtual 152	java/io/InputStream:read	([B)I
    //   236: istore_3
    //   237: iload_3
    //   238: iflt +34 -> 272
    //   241: aload 5
    //   243: aload 6
    //   245: iconst_0
    //   246: iload_3
    //   247: invokevirtual 155	java/io/ByteArrayOutputStream:write	([BII)V
    //   250: goto -20 -> 230
    //   253: astore_0
    //   254: aload_2
    //   255: ifnull +7 -> 262
    //   258: aload_2
    //   259: invokevirtual 156	java/io/InputStream:close	()V
    //   262: aload_1
    //   263: ifnull +7 -> 270
    //   266: aload_1
    //   267: invokevirtual 134	java/io/OutputStream:close	()V
    //   270: aload_0
    //   271: athrow
    //   272: aload 5
    //   274: invokevirtual 157	java/io/ByteArrayOutputStream:close	()V
    //   277: new 45	java/lang/String
    //   280: dup
    //   281: aload 5
    //   283: invokevirtual 160	java/io/ByteArrayOutputStream:toByteArray	()[B
    //   286: invokespecial 162	java/lang/String:<init>	([B)V
    //   289: invokevirtual 165	java/lang/String:trim	()Ljava/lang/String;
    //   292: astore 5
    //   294: ldc -89
    //   296: new 51	java/lang/StringBuilder
    //   299: dup
    //   300: ldc -87
    //   302: invokespecial 170	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   305: aload 5
    //   307: invokevirtual 56	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   310: invokevirtual 60	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   313: invokestatic 176	android/util/Log:w	(Ljava/lang/String;Ljava/lang/String;)I
    //   316: pop
    //   317: new 94	org/json/JSONObject
    //   320: dup
    //   321: aload 5
    //   323: invokespecial 177	org/json/JSONObject:<init>	(Ljava/lang/String;)V
    //   326: astore 5
    //   328: aload 7
    //   330: aload 5
    //   332: invokevirtual 181	com/arellomobile/android/push/request/RequestManager$NetworkResult:setData	(Lorg/json/JSONObject;)V
    //   335: aload 7
    //   337: aload 4
    //   339: invokevirtual 185	java/net/HttpURLConnection:getResponseCode	()I
    //   342: invokevirtual 189	com/arellomobile/android/push/request/RequestManager$NetworkResult:setCode	(I)V
    //   345: aload 7
    //   347: aload 5
    //   349: ldc -65
    //   351: invokevirtual 195	org/json/JSONObject:getInt	(Ljava/lang/String;)I
    //   354: invokevirtual 198	com/arellomobile/android/push/request/RequestManager$NetworkResult:setPushwooshCode	(I)V
    //   357: aload_2
    //   358: invokevirtual 156	java/io/InputStream:close	()V
    //   361: aload_1
    //   362: ifnull +7 -> 369
    //   365: aload_1
    //   366: invokevirtual 134	java/io/OutputStream:close	()V
    //   369: aload 7
    //   371: areturn
    //   372: astore 4
    //   374: aload_0
    //   375: aload_0
    //   376: invokestatic 41	com/arellomobile/android/push/request/RequestManager:a	(Landroid/content/Context;)Ljava/lang/String;
    //   379: invokestatic 64	com/arellomobile/android/push/utils/PreferenceUtils:setBaseUrl	(Landroid/content/Context;Ljava/lang/String;)V
    //   382: aload 4
    //   384: athrow
    //   385: astore_0
    //   386: aconst_null
    //   387: astore_1
    //   388: aload 6
    //   390: astore_2
    //   391: goto -137 -> 254
    //   394: astore_0
    //   395: aload 6
    //   397: astore_2
    //   398: goto -144 -> 254
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	401	0	paramContext	Context
    //   0	401	1	paramMap	Map<String, Object>
    //   0	401	2	paramString	String
    //   236	11	3	i	int
    //   25	313	4	localObject1	Object
    //   372	11	4	localException	Exception
    //   21	327	5	localObject2	Object
    //   1	395	6	arrayOfByte	byte[]
    //   15	355	7	localNetworkResult	NetworkResult
    // Exception table:
    //   from	to	target	type
    //   214	230	253	finally
    //   230	237	253	finally
    //   241	250	253	finally
    //   272	317	253	finally
    //   317	357	253	finally
    //   374	385	253	finally
    //   317	357	372	java/lang/Exception
    //   17	23	385	finally
    //   27	41	385	finally
    //   45	77	385	finally
    //   77	182	385	finally
    //   182	214	394	finally
  }
  
  private static String a(Context paramContext)
  {
    localObject1 = null;
    Object localObject2 = paramContext.getPackageManager();
    try
    {
      localObject2 = ((PackageManager)localObject2).getApplicationInfo(paramContext.getPackageName(), 128).metaData;
      paramContext = (Context)localObject1;
      if (localObject2 != null) {
        paramContext = ((Bundle)localObject2).getString("PushwooshUrl");
      }
    }
    catch (PackageManager.NameNotFoundException paramContext)
    {
      for (;;)
      {
        paramContext = (Context)localObject1;
      }
    }
    localObject1 = paramContext;
    if (TextUtils.isEmpty(paramContext))
    {
      if (useSSL) {
        localObject1 = "https://cp.pushwoosh.com/json/1.3/";
      }
    }
    else {
      return (String)localObject1;
    }
    return "http://cp.pushwoosh.com/json/1.3/";
  }
  
  public static void sendRequest(Context paramContext, PushRequest paramPushRequest)
    throws Exception
  {
    Map localMap = paramPushRequest.getParams(paramContext);
    Log.w("Pushwoosh: Request manager", "Try To sent: " + paramPushRequest.getMethod());
    Object localObject = new NetworkResult(500, 0, null);
    JSONObject localJSONObject = null;
    int i = 0;
    for (;;)
    {
      if (i <= 0) {}
      for (;;)
      {
        try
        {
          NetworkResult localNetworkResult = a(paramContext, localMap, paramPushRequest.getMethod());
          localObject = localNetworkResult;
          if (200 != localNetworkResult.getResultCode())
          {
            localObject = localNetworkResult;
            break;
          }
          localObject = localNetworkResult;
          int j = localNetworkResult.getPushwooshCode();
          if (200 != j)
          {
            paramContext = localNetworkResult;
            paramPushRequest = localJSONObject;
            if (localJSONObject == null)
            {
              paramPushRequest = "";
              if (paramContext.getResultData() != null) {
                paramPushRequest = paramContext.getResultData().toString();
              }
              paramPushRequest = new Exception(paramPushRequest);
            }
            Log.e("Pushwoosh: Request manager", "ERROR: " + paramPushRequest.getMessage() + ". Response = " + paramContext.getResultData(), paramPushRequest);
            throw paramPushRequest;
          }
          localObject = localNetworkResult;
          Log.w("Pushwoosh: Request manager", paramPushRequest.getMethod() + " response success");
          localObject = localNetworkResult;
          localJSONObject = localNetworkResult.getResultData();
          if (localJSONObject != null)
          {
            localObject = localNetworkResult;
            if (localJSONObject.has("base_url"))
            {
              localObject = localNetworkResult;
              PreferenceUtils.setBaseUrl(paramContext, localJSONObject.optString("base_url"));
            }
            localObject = localNetworkResult;
            paramPushRequest.parseResponse(localJSONObject);
          }
          return;
        }
        catch (Exception localException) {}
        paramContext = (Context)localObject;
      }
      i += 1;
    }
  }
  
  public static class NetworkResult
  {
    private int a;
    private int b;
    private JSONObject c;
    
    public NetworkResult(int paramInt1, int paramInt2, JSONObject paramJSONObject)
    {
      this.b = paramInt1;
      this.a = paramInt2;
      this.c = paramJSONObject;
    }
    
    public int getPushwooshCode()
    {
      return this.a;
    }
    
    public int getResultCode()
    {
      return this.b;
    }
    
    public JSONObject getResultData()
    {
      return this.c;
    }
    
    public void setCode(int paramInt)
    {
      this.b = paramInt;
    }
    
    public void setData(JSONObject paramJSONObject)
    {
      this.c = paramJSONObject;
    }
    
    public void setPushwooshCode(int paramInt)
    {
      this.a = paramInt;
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/arellomobile/android/push/request/RequestManager.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */