/*
 * Decompiled with CFR 0.152.
 */
package com.hst.common.util;

import com.hst.framework.constants.WebConstants;
import gt3.esb.ejb.adapter.client.IEsbXmlMessageReceiver;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import javax.naming.InitialContext;

public class EjbJ3Util {
    private static final int MAX_OUTPUT_LINE_LENGTH = 200;
    private boolean logging = true;

    public String doCommService(String reqStr) throws Exception {
        long startTime = 0L;
        if (this.logging) {
            this.log("Initializing bean access.");
            startTime = System.currentTimeMillis();
        }
        try {
            InitialContext context = this.getInitialContext();
            IEsbXmlMessageReceiver service = (IEsbXmlMessageReceiver)context.lookup("gt3.esb.ejb.AipEJBAdapter.NF.JEJB#gt3.esb.ejb.adapter.client.IEsbXmlMessageReceiver");
            String response = service.receiveMessageXML(reqStr);
            if (this.logging) {
                long endTime = System.currentTimeMillis();
                this.log("Succeeded initializing bean access through Home interface.");
                this.log("Execution time: " + (endTime - startTime) + " ms.");
                System.out.println(response);
            }
            return response;
        }
        catch (Exception e) {
            if (this.logging) {
                this.log("Failed initializing bean access.");
            }
            e.printStackTrace();
            throw new Exception(e);
        }
    }

    private InitialContext getInitialContext() throws Exception {
        Properties properties = null;
        try {
            properties = new Properties();
            properties.put("java.naming.factory.initial", WebConstants.GT3_INITIAL_CONTEXT_FACTORY);
            properties.put("java.naming.provider.url", WebConstants.GT3_PROVIDER_URL);
            this.log("ejb request url :" + WebConstants.GT3_PROVIDER_URL);
            return new InitialContext(properties);
        }
        catch (Exception e) {
            this.log("Unable to connect to WebLogic server at " + WebConstants.PROVIDER_URL);
            this.log("Please make sure that the server is running.");
            throw e;
        }
    }

    private void log(String message) {
        if (message == null) {
            System.out.println("-- null");
            return;
        }
        if (message.length() > 200) {
            System.out.println("-- " + message.substring(0, 200) + " ...");
        } else {
            System.out.println("-- " + message);
        }
    }

    public static String getUUID() {
        String s = UUID.randomUUID().toString();
        return String.valueOf(s.substring(0, 8)) + s.substring(9, 13) + s.substring(14, 18) + s.substring(19, 23) + s.substring(24);
    }

    public String creatEjbXml(Map<String, String> map) {
        StringBuffer xml = new StringBuffer();
        xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append("<service xmlns=\"http://www.chinatax.gov.cn/spec/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">").append("\t<head>").append("      <tran_id>").append(map.get("tran_id")).append("</tran_id>").append("      <channel_id>").append(WebConstants.GT3_CHANNEL_ID).append("</channel_id>").append("      <tran_seq>").append(map.get("tran_seq")).append("</tran_seq>").append("      <tran_date>").append(map.get("tran_date")).append("</tran_date>").append("      <tran_time>").append(map.get("tran_time")).append("</tran_time>").append("      <expand>").append("         <name>identityType</name>").append("         <value>").append(WebConstants.GT3_IDENTITYTYPE).append("</value>").append("      </expand>").append("      <expand>").append("         <name>sjry</name>").append("         <value>").append(map.get("sjry")).append("</value>").append("      </expand>").append("      <expand>").append("         <name>sjjg</name>").append("         <value>").append(map.get("sjjg")).append("</value>").append("      </expand>").append("   </head>").append("   <body><![CDATA[").append(map.get("ywbw")).append("]]></body>").append("</service>");
        return xml.toString();
    }
}
