/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  ctais.business.eai.ejb.CtaisService
 *  ctais.business.eai.ejb.CtaisServiceHome
 *  ctais.business.eai.wssbejb.WssbService
 *  ctais.business.eai.wssbejb.WssbServiceHome
 *  javax.rmi.PortableRemoteObject
 */
package com.hst.common.util;

import com.hst.common.util.External;
import com.hst.framework.constants.WebConstants;
import ctais.business.eai.ejb.CtaisService;
import ctais.business.eai.ejb.CtaisServiceHome;
import ctais.business.eai.wssbejb.WssbService;
import ctais.business.eai.wssbejb.WssbServiceHome;
import java.util.Hashtable;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

public class EjbExternal
implements External {
    @Override
    public String doCommService(String sid, String reqStr) throws Exception {
        try {
            Context context = this.getInitialContext();
            System.out.println("context");
            Object obj = context.lookup("dc.ejb.eai.eaiprocessor");
            CtaisServiceHome ejbHome = (CtaisServiceHome)PortableRemoteObject.narrow((Object)obj, CtaisServiceHome.class);
            CtaisService service = ejbHome.create();
            String retStr = service.doService(sid, reqStr);
            service.remove();
            return retStr;
        }
        catch (Throwable t) {
            throw new Exception(t);
        }
    }

    @Override
    public String doCommService(String sid, Hashtable reqStr) throws Exception {
        try {
            Context context = this.getInitialContext();
            Object obj = context.lookup("dc.ejb.eai.webprocessor");
            WssbServiceHome ejbHome = (WssbServiceHome)PortableRemoteObject.narrow((Object)obj, WssbServiceHome.class);
            WssbService service = ejbHome.create();
            String retStr = service.doService(sid, reqStr);
            service.remove();
            return retStr;
        }
        catch (Exception ae) {
            throw ae;
        }
        catch (Throwable t) {
            throw new Exception(t);
        }
    }

    private Context getInitialContext() throws Exception {
        Properties properties = null;
        try {
            properties = new Properties();
            properties.put("java.naming.factory.initial", WebConstants.INITIAL_CONTEXT_FACTORY);
            properties.put("java.naming.provider.url", WebConstants.PROVIDER_URL);
            properties.put("java.naming.security.principal", WebConstants.SECURITY_PRINCIPAL);
            properties.put("java.naming.security.credentials", WebConstants.SECURITY_CREDENTIALS);
            return new InitialContext(properties);
        }
        catch (Throwable t) {
            throw new Exception(t);
        }
    }
}
