/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.google.gson.Gson
 *  javax.servlet.ServletException
 *  javax.servlet.ServletInputStream
 *  javax.servlet.http.HttpServlet
 *  javax.servlet.http.HttpServletRequest
 *  javax.servlet.http.HttpServletResponse
 *  org.apache.commons.lang.StringUtils
 *  org.apache.commons.logging.Log
 *  org.apache.commons.logging.LogFactory
 */
package com.hst.servlet;

import com.google.gson.Gson;
import com.hst.common.domain.BaseAppServiceDomain;
import com.hst.common.domain.TaxCommonReturnDomain;
import com.hst.common.util.Domain2Util;
import com.hst.common.util.HstWxServiceUtil;
import com.hst.framework.constants.WebConstants;
import com.hst.framework.domain.BaseBusinessDomain;
import com.ifugle.util.export.AESUtil;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class DsbServlet
extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public static Log _logger = LogFactory.getLog(DsbServlet.class);

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletInputStream inStream = null;
        ByteArrayOutputStream outSteam = null;
        String parJosn = "";
        TaxCommonReturnDomain returnDomain = null;
        try {
            try {
                inStream = request.getInputStream();
                outSteam = new ByteArrayOutputStream();
                byte[] buffer = new byte[1024];
                int len = -1;
                while ((len = inStream.read(buffer)) != -1) {
                    outSteam.write(buffer, 0, len);
                }
                parJosn = new String(outSteam.toByteArray(), "gbk");
                _logger.debug((Object)("parJosn=" + parJosn));
                parJosn = AESUtil.decryptWithUnzipFromBase64(parJosn, WebConstants.DSB_CLIENT_SECRET);
                BaseBusinessDomain appDomain = (BaseBusinessDomain)new Gson().fromJson(parJosn, BaseBusinessDomain.class);
                System.out.println(parJosn);
                if (StringUtils.isNotBlank((String)appDomain.getYwId())) {
                    String ywId = appDomain.getYwId();
                    BaseAppServiceDomain reqDomain = Domain2Util.getAppServiceDomain(ywId, appDomain.getParmJson());
                    StringBuffer url = new StringBuffer();
                    url.append("http://").append(request.getLocalAddr()).append(":").append(request.getLocalPort()).append("/taxService/service/");
                    if (appDomain.getYwId().indexOf("dd.") >= 0) {
                        url.append("taxDdCommon!doService");
                    } else if (appDomain.getYwId().indexOf("wxfwh.") >= 0) {
                        url.append("taxWxfwhCommon!doWxAppService");
                    }
                    returnDomain = Domain2Util.getDomain(ywId);
                    returnDomain = HstWxServiceUtil.sendMess(url.toString(), reqDomain, ywId, returnDomain.getClass());
                } else {
                    returnDomain = new TaxCommonReturnDomain();
                    returnDomain.setCode("01");
                    returnDomain.setMess("\u8c03\u7528\u63a5\u53e3\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5ywid");
                }
                PrintWriter out = response.getWriter();
                out.write(AESUtil.encryptWithZipToBase64(new Gson().toJson((Object)returnDomain), WebConstants.DSB_CLIENT_SECRET));
            }
            catch (IOException e) {
                _logger.error((Object)"\u8bfb\u53d6\u6570\u636eIO\u5f02\u5e38", (Throwable)e);
                returnDomain.setCode("01");
                returnDomain.setMess("\u8c03\u7528\u63a5\u53e3\u5931\u8d25\uff0c" + e.getMessage());
                outSteam.close();
                inStream.close();
            }
            catch (Exception e) {
                returnDomain = new TaxCommonReturnDomain();
                returnDomain.setCode("01");
                returnDomain.setMess("\u8c03\u7528\u63a5\u53e3\u5931\u8d25\uff0c" + e.getMessage());
                _logger.error((Object)"\u8bfb\u53d6\u6570\u636e\u5f02\u5e38", (Throwable)e);
                outSteam.close();
                inStream.close();
            }
        }
        finally {
            outSteam.close();
            inStream.close();
        }
    }
}
