百度手机卫士 v8.4.5版本的 MD5 值为:c65ef854a40bb6200c4d8c4603c58403
以下内容为反编译后的 CMSFrontRestService.java 源代码,内容仅作参考
package com.dianxinos.cms.front.client;
import android.content.Context;
import com.baidu.mobads.interfaces.error.XAdErrorCode;
import com.baidu.mobads.interfaces.utils.IXAdIOUtils;
import com.baidu.security.plugin.alarm.AlarmUtil;
import com.quickbird.mini.vpn.vpn.VpnWatchdogThread;
import com.quickbird.sdk.internal.HttpsClient;
import dxoptimizer.aab;
import dxoptimizer.aad;
import dxoptimizer.abp;
import dxoptimizer.abq;
import dxoptimizer.abr;
import dxoptimizer.abs;
import dxoptimizer.abt;
import dxoptimizer.abv;
import dxoptimizer.abw;
import dxoptimizer.aby;
import dxoptimizer.abz;
import dxoptimizer.aca;
import dxoptimizer.acc;
import dxoptimizer.acd;
import dxoptimizer.acr;
import dxoptimizer.acv;
import dxoptimizer.acw;
import dxoptimizer.acx;
import dxoptimizer.acy;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.security.PublicKey;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.CharArrayBuffer;
import org.json.JSONException;
import org.json.JSONObject;
public class CMSFrontRestService {
private abz i;
private String j;
private Context k;
private String l;
private abw m;
private long n;
private static final String d = CMSFrontRestService.class.getName();
private static final PublicKey e = acw.a("91984037215497453715695537150101136180891052789697033543194092619618648264321686995125910645918307527361902207937849374278999247610081485346792920961341041235187112556183400885916498929543480156108595411929206248207390582439108464025592253754008974647620342386179132598251271296121068499378920392705867355039", "65537");
private static final Header f = new BasicHeader("Content-Encoding", "gzip");
private static final Header g = new BasicHeader("Accept-Encoding", "gzip");
public static String a = "10.18.102.104";
public static int b = 3724;
public static String c = "cms";
private static CMSFrontRestService h = null;
public enum Sort {
DEFAULT("sort"),
UPDATE("modifiedTime"),
DOWNLOAD("downloadCount");
private String field;
Sort(String str) {
this.field = str;
}
public String getField() {
return this.field;
}
public void setField(String str) {
this.field = str;
}
@Override
public String toString() {
return this.field;
}
}
public static void a(String str) {
if ("dev".equals(str)) {
a = "10.18.102.104";
b = 3724;
c = "cms";
acd.a = 2;
return;
}
if ("test".equals(str)) {
a = "sandbox.sjws.baidu.com";
b = 8080;
c = "cms";
acd.a = 2;
return;
}
if ("prod".equals(str)) {
a = "mk.jccjd.com";
b = 80;
c = "cf";
acd.a = 5;
return;
}
throw new IllegalArgumentException("bad env:" + str);
}
public static synchronized CMSFrontRestService a(Context context) {
CMSFrontRestService cMSFrontRestService;
synchronized (CMSFrontRestService.class) {
if (h == null) {
h = new CMSFrontRestService(context);
}
cMSFrontRestService = h;
}
return cMSFrontRestService;
}
private CMSFrontRestService(Context context) {
this(aca.a(context), context);
}
private CMSFrontRestService(abz abzVar, Context context) {
this.j = "862fe64a3f627a61727cd443ca79f1bf";
this.n = AlarmUtil.DAY;
this.i = abzVar;
this.k = context;
this.l = aab.a(context);
this.m = new abw(2, 4, 60L, TimeUnit.SECONDS, new PriorityBlockingQueue(100), new ThreadPoolExecutor.DiscardOldestPolicy());
acv.a(acv.b(), acv.a(context));
}
public int a(URI uri, List list, acc accVar, aby abyVar, boolean z) {
FileOutputStream fileOutputStream;
InputStream inputStream = null;
HttpResponse a2 = a(uri, list, false);
try {
int statusCode = a2.getStatusLine().getStatusCode();
if (statusCode != 200 && statusCode != 304) {
accVar.a(statusCode, "NETWORK_FAIL");
} else if (statusCode == 200) {
abyVar.b = b(a2);
HttpEntity entity = a2.getEntity();
if (z) {
try {
File file = new File(abz.b, abyVar.a);
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
fileOutputStream = new FileOutputStream(file);
} catch (Throwable th) {
th = th;
fileOutputStream = null;
}
try {
inputStream = entity.getContent();
Header contentEncoding = entity.getContentEncoding();
if (contentEncoding != null && contentEncoding.getValue().indexOf("gzip") != -1) {
inputStream = new GZIPInputStream(inputStream);
}
acy.a(inputStream, fileOutputStream);
acy.a(inputStream);
acy.a(fileOutputStream);
} catch (Throwable th2) {
th = th2;
acy.a(inputStream);
acy.a(fileOutputStream);
throw th;
}
} else {
accVar.a(statusCode, entity.getContent());
}
}
return statusCode;
} finally {
a(a2);
}
}
public String b(String str) {
return str.substring(0, 2) + "/" + str.substring(2) + ".png";
}
public void a(String str, acc accVar) {
accVar.a(this.m.submit(new abp(this, str, accVar)));
}
public int a(URI uri, List list, acc accVar, abt abtVar, int i) {
if (i > 2) {
throw new IOException("Too much recursion:2");
}
HttpResponse a2 = a(uri, list, true);
try {
int statusCode = a2.getStatusLine().getStatusCode();
if (statusCode != 200 && statusCode != 304) {
accVar.a(statusCode, "NETWORK_FAIL");
} else if (statusCode == 200) {
JSONObject c2 = c(a2);
JSONObject jSONObject = c2.getJSONObject("responseHeader");
abtVar.b = jSONObject;
statusCode = jSONObject.getInt(VpnWatchdogThread.VPN_WATCHDOG_STATUS);
if (statusCode == 200) {
abtVar.a = c2.getJSONObject("response");
abtVar.c = b(a2);
} else {
if (statusCode == 403) {
c();
int i2 = i + 1;
statusCode = a(uri, list, accVar, abtVar, i);
return statusCode;
}
accVar.a(statusCode, jSONObject.optString(XAdErrorCode.ERROR_CODE_MESSAGE));
}
}
return statusCode;
} finally {
a(a2);
}
}
private void a(HttpResponse httpResponse) {
if (httpResponse != null && httpResponse.getEntity() != null) {
try {
httpResponse.getEntity().consumeContent();
} catch (Exception e2) {
acd.a(d, "failed to cosume entity", e2);
}
}
}
public void a(long j, long j2, long[] jArr, int i, acc accVar) {
accVar.a(this.m.submit(new abq(this, j, j2, i, jArr, accVar)));
}
public int b(URI uri, List list, acc accVar, abt abtVar, int i) {
if (i > 2) {
throw new IOException("Too much recursion:2");
}
HttpResponse a2 = a(uri, list, true);
try {
int statusCode = a2.getStatusLine().getStatusCode();
if (statusCode != 200 && statusCode != 304) {
accVar.a(statusCode, "NETWORK_FAIL");
} else if (statusCode == 200) {
JSONObject c2 = c(a2);
JSONObject jSONObject = c2.getJSONObject("responseHeader");
abtVar.b = jSONObject;
statusCode = jSONObject.getInt(VpnWatchdogThread.VPN_WATCHDOG_STATUS);
if (statusCode == 200) {
abtVar.a = c2.getJSONObject("response");
abtVar.c = b(a2);
} else {
if (statusCode == 403) {
c();
int i2 = i + 1;
statusCode = b(uri, list, accVar, abtVar, i);
return statusCode;
}
accVar.a(statusCode, jSONObject.optString(XAdErrorCode.ERROR_CODE_MESSAGE));
}
}
return statusCode;
} finally {
a(a2);
}
}
public void a(long j, long j2, long j3, int i, int i2, Sort sort, acc accVar) {
accVar.a(this.m.submit(new abr(this, j, j2, j3, i, i2, sort, accVar)));
}
public int c(URI uri, List list, acc accVar, abt abtVar, int i) {
if (i > 2) {
throw new IOException("Too much recursion:2");
}
HttpResponse a2 = a(uri, list, true);
try {
int statusCode = a2.getStatusLine().getStatusCode();
if (statusCode != 200 && statusCode != 304) {
accVar.a(statusCode, "NETWORK_FAIL");
} else if (statusCode == 200) {
JSONObject c2 = c(a2);
JSONObject jSONObject = c2.getJSONObject("responseHeader");
abtVar.b = jSONObject;
statusCode = jSONObject.getInt(VpnWatchdogThread.VPN_WATCHDOG_STATUS);
if (statusCode == 200) {
abtVar.a = c2.getJSONObject("response");
abtVar.c = b(a2);
} else {
if (statusCode == 403) {
c();
int i2 = i + 1;
statusCode = c(uri, list, accVar, abtVar, i);
return statusCode;
}
accVar.a(statusCode, jSONObject.optString(XAdErrorCode.ERROR_CODE_MESSAGE));
}
}
return statusCode;
} finally {
a(a2);
}
}
public void a(long j, long j2, long j3, long j4, int i, acc accVar) {
a(j, j2, j3, j4, i, (String) null, accVar);
}
public void a(long j, long j2, long j3, long j4, int i, String str, acc accVar) {
accVar.a(this.m.submit(new abs(this, j, j2, j3, j4, i, str, accVar)));
}
public int d(URI uri, List list, acc accVar, abt abtVar, int i) {
if (i > 2) {
throw new IOException("Too much recursion:2");
}
HttpResponse a2 = a(uri, list, true);
try {
int statusCode = a2.getStatusLine().getStatusCode();
if (statusCode != 200 && statusCode != 304) {
accVar.a(statusCode, "NETWORK_FAIL");
} else if (statusCode == 200) {
JSONObject c2 = c(a2);
JSONObject jSONObject = c2.getJSONObject("responseHeader");
abtVar.b = jSONObject;
statusCode = jSONObject.getInt(VpnWatchdogThread.VPN_WATCHDOG_STATUS);
if (statusCode == 200) {
abtVar.a = c2.getJSONObject("response");
abtVar.c = b(a2);
} else {
if (statusCode == 403) {
c();
int i2 = i + 1;
statusCode = d(uri, list, accVar, abtVar, i);
return statusCode;
}
accVar.a(statusCode, jSONObject.optString(XAdErrorCode.ERROR_CODE_MESSAGE));
}
}
return statusCode;
} finally {
a(a2);
}
}
private synchronized void c() {
URI createURI = URIUtils.createURI("http", a, b, c + "/rs", this.l, null);
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("ms", System.currentTimeMillis());
jSONObject.put("tk", aad.a(this.k));
} catch (JSONException e2) {
e2.printStackTrace();
}
HttpResponse a2 = a(createURI, new String(acr.b(acw.a(jSONObject.toString(), e), 0)), (List) null);
try {
int statusCode = a2.getStatusLine().getStatusCode();
if (statusCode == 200) {
JSONObject c2 = c(a2);
JSONObject jSONObject2 = c2.getJSONObject("responseHeader");
int i = jSONObject2.getInt(VpnWatchdogThread.VPN_WATCHDOG_STATUS);
if (i == 200) {
this.j = new JSONObject(new String(acw.a(acr.a(c2.getJSONObject("response").getString("session"), 0), e))).getString("sid");
} else {
throw new IOException("failed to get sid,status:" + i + ",msg:" + jSONObject2.optString(XAdErrorCode.ERROR_CODE_MESSAGE));
}
} else {
throw new IOException("failed to get sid,status:" + statusCode);
}
} finally {
a(a2);
}
}
public void a() {
acv.a();
this.m.shutdownNow();
this.i.a();
d();
}
private static synchronized void d() {
synchronized (CMSFrontRestService.class) {
h = null;
}
}
private static long b(HttpResponse httpResponse) {
Header firstHeader = httpResponse.getFirstHeader("Last-Modified");
if (firstHeader != null) {
return acy.b(firstHeader.getValue()).getTime();
}
return 0L;
}
public static Header b(long j) {
return new BasicHeader("If-Modified-Since", acy.a(new Date(j)));
}
private static JSONObject c(HttpResponse httpResponse) {
int i = IXAdIOUtils.BUFFER_SIZE;
HttpEntity entity = httpResponse.getEntity();
InputStream content = entity.getContent();
int contentLength = (int) entity.getContentLength();
if (contentLength >= 0) {
i = contentLength;
}
Header contentEncoding = entity.getContentEncoding();
InputStreamReader inputStreamReader = new InputStreamReader((contentEncoding == null || contentEncoding.getValue().indexOf("gzip") == -1) ? content : new GZIPInputStream(content), HttpsClient.HTTP_CHARSET);
try {
CharArrayBuffer charArrayBuffer = new CharArrayBuffer(i);
char[] cArr = new char[IXAdIOUtils.BUFFER_SIZE];
while (true) {
int read = inputStreamReader.read(cArr);
if (read != -1) {
charArrayBuffer.append(cArr, 0, read);
} else {
return new JSONObject(charArrayBuffer.toString());
}
}
} finally {
acy.a(inputStreamReader);
}
}
private HttpResponse a(URI uri, String str, List list) {
String uri2 = uri.toString();
if (uri2.indexOf(63) > 0) {
uri2 = uri2 + "&sid=" + this.j + "&cv=1.0&cflv=" + abv.a();
}
HttpPost httpPost = new HttpPost(uri2);
if (list != null) {
Iterator it = list.iterator();
while (it.hasNext()) {
httpPost.addHeader((Header) it.next());
}
}
httpPost.addHeader(f);
httpPost.addHeader(g);
httpPost.setEntity(new ByteArrayEntity(acy.c(str)));
acd.a(d, "request uri:" + httpPost.getURI() + ",body:" + str + ",headers:" + Arrays.asList(httpPost.getAllHeaders()));
httpPost.getParams().setParameter("http.socket.timeout", 20000);
DefaultHttpClient b2 = acv.b();
try {
try {
acx.a(81921);
return b2.execute(httpPost);
} catch (IOException e2) {
httpPost.abort();
throw e2;
}
} finally {
acx.a();
}
}
private HttpResponse a(URI uri, List list, boolean z) {
String uri2 = uri.toString();
if (uri2.indexOf(63) > 0) {
uri2 = uri2 + "&sid=" + this.j + "&cv=1.0&cflv=" + abv.a();
}
HttpGet httpGet = new HttpGet(uri2);
if (list != null) {
Iterator it = list.iterator();
while (it.hasNext()) {
httpGet.addHeader((Header) it.next());
}
}
if (z) {
httpGet.addHeader(g);
}
acd.a(d, "request uri: " + httpGet.getURI() + ", headers: " + Arrays.asList(httpGet.getAllHeaders()));
httpGet.getParams().setParameter("http.socket.timeout", 20000);
DefaultHttpClient b2 = acv.b();
try {
try {
acx.a(81920);
return b2.execute(httpGet);
} catch (IOException e2) {
httpGet.abort();
throw e2;
}
} finally {
acx.a();
}
}
}