悦享送 v3.5.1版本的 MD5 值为:2b8a7c90a41fc63c8abfaa7ebdd1bef9

以下内容为反编译后的 HttpService4A.java 源代码,内容仅作参考


package com.eva.android;

import com.eva.epc.common.util.CommonUtils;
import com.eva.epc.common.util.EException;
import com.eva.framework.dto.DataFromClient;
import com.eva.framework.dto.DataFromServer;
import com.lzy.okgo.model.HttpHeaders;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpService4A {
    private static CookieHolder cookie0;
    private static CookieHolder cookie2;
    private String serviceName;
    private String servletName;
    private String servletRootURL;

    public HttpService4A(String str, String str2, String str3) {
        this.servletRootURL = "http://127.0.0.1:2683/";
        this.servletName = "";
        this.serviceName = null;
        this.serviceName = str;
        this.servletRootURL = str2;
        this.servletName = str3;
    }

    public DataFromServer sendObjToServer(DataFromClient dataFromClient) {
        return sendObjToServer(dataFromClient, true);
    }

    public DataFromServer sendObjToServer(DataFromClient dataFromClient, boolean z) {
        return sendObjToServer(dataFromClient, z, 0);
    }

    public DataFromServer sendObjToServer(DataFromClient dataFromClient, boolean z, int i) {
        HttpURLConnection httpURLConnection;
        DataFromServer dataFromServer;
        Exception exc;
        OutputStream outputStream;
        Exception exc2;
        dataFromClient.setDoInput(z);
        ?? r1 = 0;
        String str = null;
        r1 = 0;
        try {
            try {
                httpURLConnection = getServerConnection(z);
            } catch (Throwable th) {
                th = th;
                r1 = dataFromClient;
            }
        } catch (Exception e) {
            dataFromServer = null;
            httpURLConnection = null;
            exc = e;
            outputStream = null;
        } catch (Throwable th2) {
            th = th2;
            httpURLConnection = null;
        }
        try {
            outputStream = processSendData(dataFromClient, httpURLConnection.getOutputStream());
            try {
                if (z) {
                    if (i != 0) {
                        httpURLConnection.setReadTimeout(i);
                    }
                    DataFromServer[] dataFromServerArr = new DataFromServer[1];
                    processReceiveData(httpURLConnection.getInputStream(), dataFromServerArr);
                    dataFromServer = dataFromServerArr[0];
                } else {
                    dataFromServer = new DataFromServer();
                    try {
                        dataFromServer.setSuccess(true);
                    } catch (Exception e2) {
                        exc = e2;
                        String str2 = "May be due to network connectivity problems, " + exc.getMessage();
                        processRunningException(exc);
                        if (outputStream != null) {
                            try {
                                outputStream.close();
                            } catch (Exception e3) {
                                processFinallyException(e3);
                                exc2 = exc;
                                str = str2;
                                if (dataFromServer == null) {
                                }
                                return dataFromServer;
                            }
                        }
                        storeCookie(httpURLConnection);
                        if (httpURLConnection != null) {
                            httpURLConnection.disconnect();
                        }
                        exc2 = exc;
                        str = str2;
                        if (dataFromServer == null) {
                        }
                        return dataFromServer;
                    }
                }
                if (outputStream != null) {
                    try {
                        outputStream.close();
                    } catch (Exception e4) {
                        processFinallyException(e4);
                    }
                }
                storeCookie(httpURLConnection);
                if (httpURLConnection != null) {
                    httpURLConnection.disconnect();
                }
                exc2 = null;
            } catch (Exception e5) {
                exc = e5;
                dataFromServer = null;
            }
        } catch (Exception e6) {
            dataFromServer = null;
            exc = e6;
            outputStream = null;
        } catch (Throwable th3) {
            th = th3;
            if (r1 != 0) {
                try {
                    r1.close();
                } catch (Exception e7) {
                    processFinallyException(e7);
                    throw th;
                }
            }
            storeCookie(httpURLConnection);
            if (httpURLConnection != null) {
                httpURLConnection.disconnect();
            }
            throw th;
        }
        if (dataFromServer == null) {
            dataFromServer = new DataFromServer();
            dataFromServer.setSuccess(false);
            dataFromServer.setReturnValue(new EException(CommonUtils.isStringEmpty(HttpServiceFactory4A.defaultTipMsgIfFail) ? "Exception cause for sending datas." : HttpServiceFactory4A.defaultTipMsgIfFail, str, exc2.getCause()));
        }
        return dataFromServer;
    }

    protected OutputStream processSendData(DataFromClient dataFromClient, OutputStream outputStream) throws Exception {
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
        objectOutputStream.writeObject(dataFromClient);
        objectOutputStream.flush();
        return objectOutputStream;
    }

    protected InputStream processReceiveData(InputStream inputStream, DataFromServer[] dataFromServerArr) throws Exception {
        ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
        dataFromServerArr[0] = (DataFromServer) objectInputStream.readObject();
        return objectInputStream;
    }

    protected void processRunningException(Exception exc) {
        exc.printStackTrace();
    }

    protected void processFinallyException(Exception exc) {
        exc.printStackTrace();
    }

    protected HttpURLConnection getServerConnection(boolean z) throws Exception {
        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(getServletFullQualifyURL()).openConnection();
        httpURLConnection.setDoOutput(true);
        if (z) {
            httpURLConnection.setDoInput(z);
        }
        httpURLConnection.setUseCaches(false);
        setCookieHttpHeader(httpURLConnection);
        setOtherHttpHeader(httpURLConnection);
        httpURLConnection.setConnectTimeout(30000);
        return httpURLConnection;
    }

    protected void setOtherHttpHeader(HttpURLConnection httpURLConnection) throws Exception {
        httpURLConnection.setRequestProperty("hello_word", "eva.epc_v1.0");
    }

    protected void setCookieHttpHeader(HttpURLConnection httpURLConnection) throws Exception {
        CookieHolder cookieHolder = cookie0;
        if (cookieHolder != null) {
            httpURLConnection.setRequestProperty(cookieHolder.key, cookie0.value);
            return;
        }
        CookieHolder cookieHolder2 = cookie2;
        if (cookieHolder2 != null) {
            httpURLConnection.setRequestProperty(cookieHolder2.key, cookie2.value);
        }
    }

    protected void storeCookie(HttpURLConnection httpURLConnection) throws Exception {
        String pareseCookieValue = CookieHolder.pareseCookieValue(httpURLConnection.getHeaderField("Set-Cookie"));
        if (pareseCookieValue != null) {
            CookieHolder cookieHolder = cookie0;
            if (cookieHolder == null) {
                cookie0 = new CookieHolder("Cookie", pareseCookieValue);
                return;
            } else {
                cookieHolder.value = pareseCookieValue;
                return;
            }
        }
        String pareseCookieValue2 = CookieHolder.pareseCookieValue(httpURLConnection.getHeaderField("Set-Cookie2"));
        if (pareseCookieValue2 != null) {
            CookieHolder cookieHolder2 = cookie2;
            if (cookieHolder2 == null) {
                cookie2 = new CookieHolder(HttpHeaders.HEAD_KEY_COOKIE2, pareseCookieValue2);
            } else {
                cookieHolder2.value = pareseCookieValue2;
            }
        }
    }

    public String getServletFullQualifyURL() {
        String servletRootURL = getServletRootURL();
        StringBuilder sb = new StringBuilder();
        if (servletRootURL.lastIndexOf("/") == -1) {
            servletRootURL = "/" + servletRootURL;
        }
        sb.append(servletRootURL);
        sb.append(getServletName());
        return sb.toString();
    }

    public String getServletRootURL() {
        return this.servletRootURL;
    }

    public String getServletName() {
        return this.servletName;
    }

    public String getServiceName() {
        return this.serviceName;
    }

    public static class CookieHolder {
        public String key;
        public String value;

        public CookieHolder(String str, String str2) {
            this.key = str;
            this.value = str2;
        }

        public static String pareseCookieValue(String str) {
            if (str == null) {
                return null;
            }
            int indexOf = str.indexOf(";");
            return indexOf == -1 ? str : str.substring(0, indexOf);
        }

        public String toString() {
            return "key=" + this.key + ", value=" + this.value;
        }
    }
}