//package com.eactive.eai.inbound.remote; // //import java.io.File; //import java.io.FileInputStream; //import java.util.ArrayList; //import java.util.Date; //import java.util.Enumeration; //import java.util.Locale; //import java.util.Properties; // //import com.eactive.eai.batch.common.CalendarUtil; //import com.eactive.eai.batch.common.StringUtil; //import com.eactive.eai.common.property.PropManager; //import com.eactive.eai.common.util.DatetimeUtil; //import com.sterlingcommerce.cd.sdk.CDProcess; //import com.sterlingcommerce.cd.sdk.ConnectionException; //import com.sterlingcommerce.cd.sdk.LogonException; //import com.sterlingcommerce.cd.sdk.MediatorEnum; //import com.sterlingcommerce.cd.sdk.MsgException; //import com.sterlingcommerce.cd.sdk.Node; // //public class NDMTransferByApi extends CommonTransfer //{ // // //리모트 NDM 전송 프라퍼티 정보 // public static final String PROP_GROUP_REMOTE_TRANSFER_NDM = "RemoteTransferNdmInfo"; // public static final String PROP_NDM_SERVER_NODE_NAME = "NDM_SERVER_NODE_NAME"; //NDM 서버 NodeName (IP;Port) // public static final String PROP_NDM_SERVER_USER_ID = "NDM_SERVER_USER_ID"; //NDM 서버 UserId // public static final String PROP_NDM_SERVER_PASSWORD = "NDM_SERVER_PASSWORD"; //NDM 서버 Password // public static final String PROP_NDM_SERVER_PROTOCOL = "NDM_SERVER_PROTOCOL"; //NDM 서버 Protocol (Default : TCPIP) // // private static final String DEFAULT_NDM_SERVER_PREFIX = "DEFAULT"; // // private static final String COMMAND_TYPE_SELECT = "SELECT"; // private static final String COMMAND_TYPE_SUBMIT = "SUBMIT"; // // private static Properties ndmServerProp; // private String ndmNodeName = ""; // private String ndmUserId = ""; // private String ndmPassword = ""; // private String ndmProtocol = ""; // // private Node cdNode = null; // // private boolean isNdmTrace = false; // // private static String getPropNdmServerNodeName() throws Exception { // String propValue = PropManager.getInstance().getProperty(PROP_GROUP_REMOTE_TRANSFER_NDM, PROP_NDM_SERVER_NODE_NAME); // if (propValue == null) throw new Exception("'NDM 서버 Node Name (IP;Port)' 프라퍼티 정보가 없습니다. (PropGroupName:"+ PROP_GROUP_REMOTE_TRANSFER_NDM +", PropName:"+ PROP_NDM_SERVER_NODE_NAME +")"); // return propValue; // } // // private static String getPropNdmServerUserId() throws Exception { // String propValue = PropManager.getInstance().getProperty(PROP_GROUP_REMOTE_TRANSFER_NDM, PROP_NDM_SERVER_USER_ID); // if (propValue == null) throw new Exception("'NDM 서버 User Id' 프라퍼티 정보가 없습니다. (PropGroupName:"+ PROP_GROUP_REMOTE_TRANSFER_NDM +", PropName:"+ PROP_NDM_SERVER_USER_ID +")"); // return propValue; // } // // private static String getPropNdmServerPassword() throws Exception { // String propValue = PropManager.getInstance().getProperty(PROP_GROUP_REMOTE_TRANSFER_NDM, PROP_NDM_SERVER_PASSWORD); // if (propValue == null) throw new Exception("'NDM 서버 Password' 프라퍼티 정보가 없습니다. (PropGroupName:"+ PROP_GROUP_REMOTE_TRANSFER_NDM +", PropName:"+ PROP_NDM_SERVER_PASSWORD +")"); // return propValue; // } // // private static String getPropNdmServerProtocol() throws Exception { // String propValue = PropManager.getInstance().getProperty(PROP_GROUP_REMOTE_TRANSFER_NDM, PROP_NDM_SERVER_PROTOCOL); // if (propValue == null) { // logger.warn("'NDM 서버 Protocol' 프라퍼티 정보가 없습니다. 디폴트값은 'TCPIP' 입니다. (PropGroupName:"+ PROP_GROUP_REMOTE_TRANSFER_NDM +", PropName:"+ PROP_NDM_SERVER_PROTOCOL +")"); // return "TCPIP"; // } // return propValue; // } // // // //NDM property 파일정보 로딩 // public static void loadNdmServerProperty(String ndmServerPropFilePath) throws Exception { // logger.info("[리모트송수신] [NDM_Api] ■ NDM 서버 정보 Property 파일 로딩 시작..."); // logger.info("[리모트송수신] [NDM_Api] ⓟ Property 파일 : ["+ ndmServerPropFilePath +"]"); // // FileInputStream fis = null; // try { // fis = new FileInputStream(ndmServerPropFilePath); // ndmServerProp = new Properties(); // ndmServerProp.load(fis); // // } catch (Exception ex) { // logger.error( ex.getMessage(), ex); // ndmServerProp = null; // throw new Exception("NDM 서버 정보 Property 파일 로딩 오류!\n caused by..."+ ex.toString()); // // } finally { // try { // if (fis != null) // fis.close(); // }catch (Exception e) { // logger.error( e.getMessage(), e); // } // } // logger.info("[리모트송수신] [NDM_Api] ■ NDM 서버 정보 Property 파일 로딩 완료."); // } // // // // public NDMTransferByApi() throws Exception { // logger.info("[리모트송수신] [NDM_Api] ■ NDM 서버 정보 설정 시작 (by DB Property)..."); // // this.setNDMServerInfo(getPropNdmServerNodeName(), // getPropNdmServerUserId(), // getPropNdmServerPassword(), // getPropNdmServerProtocol()); // // logger.info("[리모트송수신] [NDM_Api] ■ NDM 서버 정보 설정 완료 (by DB Property)."); // } // // public NDMTransferByApi(String ndmServerPropFilePath) throws Exception { // this(ndmServerPropFilePath, DEFAULT_NDM_SERVER_PREFIX); // } // // public NDMTransferByApi(String ndmServerPropFilePath, String ndmServerPrefix) throws Exception { // // logger.info("[리모트송수신] [NDM_Api] ■ NDM 서버 정보 설정 시작 (by Property File)..."); // logger.info("[리모트송수신] [NDM_Api] ⓟ NDM 서버 정보 Prefix : ["+ ndmServerPrefix +"]"); // // if (ndmServerProp == null) loadNdmServerProperty(ndmServerPropFilePath); // // String checkReloading = ndmServerProp.getProperty(ndmServerPrefix +"_nodeName", ""); // //값이 없는 경우 파일을 다시 한번 읽도록 함 // if (checkReloading.equals("")) loadNdmServerProperty(ndmServerPropFilePath); // // String strNdmNodeName = ndmServerProp.getProperty(ndmServerPrefix +"_nodeName"); //ex) 172.17.33.111;1363 // String strNdmUserId = ndmServerProp.getProperty(ndmServerPrefix +"_userid"); // String strNdmPassword = ndmServerProp.getProperty(ndmServerPrefix +"_password"); // String strNdmProtocol = ndmServerProp.getProperty(ndmServerPrefix +"_protocol", "TCPIP"); // // if (strNdmNodeName == null || strNdmNodeName.equals("")) throw new Exception("NDM 서버 정보 Property 파일에 '"+ ndmServerPrefix +"_nodeName' 프라퍼티 값을 설정하세요. ex) 172.17.61.71;1363"); // if (strNdmUserId == null || strNdmUserId. equals("")) throw new Exception("NDM 서버 정보 Property 파일에 '"+ ndmServerPrefix +"_userid' 프라퍼티 값을 설정하세요."); // if (strNdmPassword == null || strNdmPassword.equals("")) throw new Exception("NDM 서버 정보 Property 파일에 '"+ ndmServerPrefix +"_password' 프라퍼티 값을 설정하세요."); // if (strNdmProtocol == null || strNdmProtocol.equals("")) throw new Exception("NDM 서버 정보 Property 파일에 '"+ ndmServerPrefix +"_protocol' 프라퍼티 값을 설정하세요. ex) TCPIP"); // // this.setNDMServerInfo(strNdmNodeName, // strNdmUserId, // strNdmPassword, // strNdmProtocol); // // logger.info("[리모트송수신] [NDM_Api] ■ NDM 서버 정보 설정 완료 (by Property File)."); // } // // public NDMTransferByApi(String ndmNodeName, String ndmUserId, String ndmPassword, String ndmProtocol) throws Exception { // logger.info("[리모트송수신] [NDM_Api] ■ NDM 서버 정보 설정 시작 (by Manual)..."); // // this.setNDMServerInfo(ndmNodeName, // ndmUserId, // ndmPassword, // ndmProtocol); // // logger.info("[리모트송수신] [NDM_Api] ■ NDM 서버 정보 설정 완료 (by Manual)."); // } // // public void setNDMServerInfo(String ndmNodeName, String ndmUserId, String ndmPassword, String ndmProtocol) throws Exception { // this.ndmNodeName = ndmNodeName; // this.ndmUserId = ndmUserId; // this.ndmPassword = ndmPassword; // this.ndmProtocol = ndmProtocol; // logger.info("[리모트송수신] [NDM_Api] ************* NDM 서버 정보 *************"); // logger.info("[리모트송수신] [NDM_Api] - NodeName :"+ this.ndmNodeName); // logger.info("[리모트송수신] [NDM_Api] - Userid :"+ this.ndmUserId ); // logger.info("[리모트송수신] [NDM_Api] - Password :"+ this.ndmPassword); // logger.info("[리모트송수신] [NDM_Api] - Protocol :"+ this.ndmProtocol); // logger.info("[리모트송수신] [NDM_Api] *****************************************"); // // if (ndmNodeName == null || ndmNodeName.equals("")) throw new Exception("NDM 서버 정보 'Node Name' 값을 설정하세요. ex) 172.17.61.71;1363"); // if (ndmUserId == null || ndmUserId. equals("")) throw new Exception("NDM 서버 정보 'User Id' 값을 설정하세요."); // if (ndmPassword == null || ndmPassword.equals("")) throw new Exception("NDM 서버 정보 'Password' 값을 설정하세요."); // if (ndmProtocol == null || ndmProtocol.equals("")) throw new Exception("NDM 서버 정보 'Protocol' 값을 설정하세요. ex) TCPIP"); // } // // private void connect() throws Exception { // // try { // logger.info("[리모트송수신] [NDM_Api] ▶ NDM 서버 연결 시도... " + this.ndmNodeName); // if (cdNode!=null) { // logger.info("[리모트송수신] [NDM_Api] ▶ 해당 NDM 서버에 이미 연결되어 있습니다. (" + cdNode.getConnectionInfo().getAddress() + ":" + cdNode.getConnectionInfo().getPort() +")"); // return; // } // // cdNode = new Node(this.ndmNodeName, // this.ndmUserId, // this.ndmPassword.toCharArray(), // this.ndmProtocol, // "EAI NDM Client Aplication", // Locale.getDefault()); // // if (isNdmTrace == true) { // cdNode.getConnectionInfo().setTraceOn(); // } else { // cdNode.getConnectionInfo().setTraceOff(); // } // logger.info("[리모트송수신] [NDM_Api] ☞ NDM 서버 OS_TYPE : [" + cdNode.getConnectionInfo().getOSType() +"]"); // logger.info("[리모트송수신] [NDM_Api] ☞ NDM 서버 NODE_NAME : [" + cdNode.getConnectionInfo().getNodeName() +"]"); // logger.info("[리모트송수신] [NDM_Api] ▶ NDM 서버에 연결되었습니다."); // // } catch (ConnectionException ex) { // logger.error( ex.getMessage(), ex); // throw new Exception("NDM 서버 연결 오류!\n caused by..."+ ex.toString()); // // } catch (LogonException ex) { // logger.error( ex.getMessage(), ex); // throw new Exception("NDM 서버 로그인 오류!\n caused by..."+ ex.toString()); // // } catch (Exception ex) { // logger.error( ex.getMessage(), ex); // throw new Exception("NDM 서버 연결정보 오류!\n caused by..."+ ex.toString()); // } // } // // private void disconnect() { // logger.info("[리모트송수신] [NDM_Api] ▶ NDM 서버 연결 해제 시도..."); // try { // if (cdNode!=null) cdNode.closeNode(); // cdNode = null; // logger.info("[리모트송수신] [NDM_Api] ▶ NDM 서버 연결이 해제 되었습니다."); // } catch (Exception ex) { // logger.error( ex.getMessage(), ex); // } // } // // //------------------------------------------------------------------------------------------- // // 리모트서버로 파일 송신 // //------------------------------------------------------------------------------------------- // public void sendFile(RemoteServerVO remoteServerVO, String ndmLocalDir, String ndmLocalFile, String remoteDir, String remoteFile) throws Exception { // // logger.info("[리모트송수신] [NDM_Api] ■ EAI→Remote 파일 NDM 송신 시작......"); // logger.info("[리모트송수신] [NDM_Api] ⓟ 리모트 서버 VO : ["+ remoteServerVO +"]"); // logger.info("[리모트송수신] [NDM_Api] ⓟ NDM로컬 경로 : ["+ ndmLocalDir +"]"); // logger.info("[리모트송수신] [NDM_Api] ⓟ NDM로컬 파일 : ["+ ndmLocalFile +"]"); // logger.info("[리모트송수신] [NDM_Api] ⓟ 리모트 경로 : ["+ remoteDir +"]"); // logger.info("[리모트송수신] [NDM_Api] ⓟ 리모트 파일 : ["+ remoteFile +"]"); // // //파라미터 체크 // if (remoteServerVO == null) throw new Exception("{리모트서버 VO} 파라미터 오류"); // if (ndmLocalDir.equals("")) throw new Exception("{NDM로컬} 파라미터 오류"); // if (ndmLocalFile.equals("")) throw new Exception("{NDM로컬} 파라미터 오류"); // if (remoteDir.equals("")) throw new Exception("{리모트경로} 파라미터 오류"); // if (remoteFile.equals("")) throw new Exception("{리모트파일} 파라미터 오류"); // // //파일전송 로그정보 설정 // if (isLogging) { // if (logInfo==null) logInfo = new RemoteTransferLogVO(); // logInfo.setRemoteServerVO (remoteServerVO); // logInfo.setRemoteServerId (remoteServerVO.getRemoteServerId()); // logInfo.setSendRecvType (DIRECTION_SEND); // logInfo.setTransferType (TRANSFER_TYPE_NDM); // logInfo.setEaiFilePath (ndmLocalDir); // logInfo.setEaiFileName (ndmLocalFile); // logInfo.setRemoteFilePath (remoteDir); // logInfo.setRemoteFileName (remoteFile); // logInfo.setFransferStartTime(CalendarUtil.getCurrentTimeNoDash()); // File f = new File(ndmLocalDir, ndmLocalFile); // logInfo.setFileSize (f.length()+""); // logInfo.setFileLastModified (DatetimeUtil.getFormattedDate("yyyyMMddHHmmssSSS", new Date(f.lastModified()))); // } // // // String remoteDelimiter = StringUtil.getDirDelimiter(remoteDir); // String ndmLocalDelimiter = StringUtil.getDirDelimiter(ndmLocalDir); // // if (remoteDir .endsWith(remoteDelimiter )) remoteDir = remoteDir .substring(0, remoteDir .length()-1); // if (ndmLocalDir.endsWith(ndmLocalDelimiter)) ndmLocalDir = ndmLocalDir.substring(0, ndmLocalDir.length()-1); // if (remoteFile==null || remoteFile.equals("")) remoteFile = ndmLocalFile; // // String command = logInfo.getNdmPname() + " process snode="+ remoteServerVO.getRemoteServerIP() +";"+ remoteServerVO.getRemoteNdmPort() +"\n" // + "step1 copy from (file=\""+ ndmLocalDir + ndmLocalDelimiter + ndmLocalFile +"\" pnode)\n" // + " to (file=\""+ remoteDir + remoteDelimiter + remoteFile +"\" disp=(rpl) snode)\n" // + "pend"; // executeNdmCommand(COMMAND_TYPE_SUBMIT, command); // // //파일전송 로그정보 설정 // if (isLogging) logInfo.setFransferEndTime (CalendarUtil.getCurrentTimeNoDash()); // // logger.info("[리모트송수신] [NDM_Api] ■ EAI→Remote 파일 NDM 송신 완료."); // } // // //------------------------------------------------------------------------------------------- // // 리모트서버로 부터 파일 수신 // //------------------------------------------------------------------------------------------- // public void receiveFile(RemoteServerVO remoteServerVO, String remoteDir, String remoteFile, String ndmLocalDir, String ndmLocalFile) throws Exception { // logger.info("[리모트송수신] [NDM_Api] ■ Remote→EAI 파일 NDM 수신 시작......"); // logger.info("[리모트송수신] [NDM_Api] ⓟ 리모트 서버 VO : ["+ remoteServerVO +"]"); // logger.info("[리모트송수신] [NDM_Api] ⓟ 리모트 경로 : ["+ remoteDir +"]"); // logger.info("[리모트송수신] [NDM_Api] ⓟ 리모트 파일 : ["+ remoteFile +"]"); // logger.info("[리모트송수신] [NDM_Api] ⓟ NDM로컬 경로 : ["+ ndmLocalDir +"]"); // logger.info("[리모트송수신] [NDM_Api] ⓟ NDM로컬 파일 : ["+ ndmLocalFile +"]"); // // //파라미터 체크 // if (remoteServerVO == null) throw new Exception("{리모트서버 VO} 파라미터 오류"); // if (remoteDir.equals("")) throw new Exception("{리모트경로} 파라미터 오류"); // if (remoteFile.equals("")) throw new Exception("{리모트파일} 파라미터 오류"); // if (ndmLocalDir.equals("")) throw new Exception("{NDM로컬} 파라미터 오류"); // if (ndmLocalFile.equals("")) throw new Exception("{NDM로컬} 파라미터 오류"); // // //파일전송 로그정보 설정 // if (isLogging) { // if (logInfo==null) logInfo = new RemoteTransferLogVO(); // logInfo.setRemoteServerVO (remoteServerVO); // logInfo.setRemoteServerId (remoteServerVO.getRemoteServerId()); // logInfo.setSendRecvType (DIRECTION_RECEIVE); // logInfo.setTransferType (TRANSFER_TYPE_NDM); // logInfo.setEaiFilePath (ndmLocalDir); // logInfo.setEaiFileName (ndmLocalFile); // logInfo.setRemoteFilePath (remoteDir); // logInfo.setRemoteFileName (remoteFile); // logInfo.setFransferStartTime(CalendarUtil.getCurrentTimeNoDash()); // } // // String remoteDelimiter = StringUtil.getDirDelimiter(remoteDir); // String ndmLocalDelimiter = StringUtil.getDirDelimiter(ndmLocalDir); // // if (remoteDir .endsWith(remoteDelimiter )) remoteDir = remoteDir .substring(0, remoteDir .length()-1); // if (ndmLocalDir.endsWith(ndmLocalDelimiter)) ndmLocalDir = ndmLocalDir.substring(0, ndmLocalDir.length()-1); // if (ndmLocalFile==null || ndmLocalFile.equals("")) ndmLocalFile = remoteFile; // // String command = logInfo.getNdmPname() + " process snode="+ remoteServerVO.getRemoteServerIP() +";"+ remoteServerVO.getRemoteNdmPort() +"\n" // + "step1 copy from (file=\""+ remoteDir + remoteDelimiter + remoteFile +"\" snode)\n" // + " to (file=\""+ ndmLocalDir + ndmLocalDelimiter + ndmLocalFile +"\" disp=(rpl) pnode)\n" // + "pend"; // // executeNdmCommand(COMMAND_TYPE_SUBMIT, command); // // //파일전송 로그정보 설정 // if (isLogging) { // File f = new File(ndmLocalDir, ndmLocalFile); // logInfo.setFileSize (f.length()+""); // logInfo.setFileLastModified (DatetimeUtil.getFormattedDate("yyyyMMddHHmmssSSS", new Date(f.lastModified()))); // logInfo.setFransferEndTime (CalendarUtil.getCurrentTimeNoDash()); // } // // logger.info("[리모트송수신] [NDM_Api] ■ Remote→EAI 파일 NDM 수신 완료."); // } // // // public ArrayList selectCommand(String selectCommand) throws Exception { // logger.info("[리모트송수신] [NDM_Api] ■ NDM Select Command 시작......"); // logger.info("[리모트송수신] [NDM_Api] ⓟ Select Command : ["+ selectCommand +"]"); // // ArrayList alist = executeNdmCommand(COMMAND_TYPE_SELECT, selectCommand); // // logger.info("[리모트송수신] [NDM_Api] ■ NDM Select Command 완료."); // return alist; // } // // // // // // // // @SuppressWarnings("rawtypes") // private ArrayList executeNdmCommand(String commandType, String command) throws Exception { // // logger.info("[리모트송수신] [NDM_Api] ▶ NDM Command 수행 시작... (Send Command to NDM 서버["+ this.ndmNodeName +"])"); // logger.info("[리모트송수신] [NDM_Api] ⓟ commandType : ["+ commandType +"]"); // // ArrayList alist = null; // try { // this.connect(); // // if (commandType.equalsIgnoreCase(COMMAND_TYPE_SUBMIT)) { // alist = this.executeSubmitCommand(command); //throw Exception // // } else if (commandType.equalsIgnoreCase(COMMAND_TYPE_SELECT)) { // alist = this.executeSelectCommand(command); //throw Exception // } // // } catch (MsgException ex) { // logger.error( ex.getMessage(), ex); // // String errMsg = ex.toString(); // Enumeration errorEnum = ex.elements(); // while (errorEnum.hasMoreElements()) { // Object obj = errorEnum.nextElement(); // logger.error("[리모트송수신] [NDM_Api] - " + obj); // errMsg += "\n - "+ obj; // } // throw new Exception("NDM Command 수행 실패!\n caused by..."+ errMsg); // // } catch (Exception ex) { // logger.error( ex.getMessage(), ex); // throw new Exception("NDM Command 수행 실패!\n caused by..."+ ex.toString()); // // } finally { // this.disconnect(); // } // logger.info("[리모트송수신] [NDM_Api] ▶ NDM Command 수행 완료."); // return alist; // } // // private ArrayList executeSubmitCommand(String command) throws Exception { // // logger.info("[리모트송수신] [NDM_Api] ▶ NDM Submit Command 수행 시작..."); // logger.info("[리모트송수신] [NDM_Api] ⓟ Command : submit maxdelay=unlimited \n"+ command); // MediatorEnum submitResults = cdNode.execute("submit maxdelay=unlimited", command); // // ArrayList alist = new ArrayList(); // while (submitResults.hasMoreElements()) { // CDProcess processData = (CDProcess)submitResults.getNextElement(); // alist.add(processData); // String processNumber = processData.getProcessNumber() +""; // String resultCode = processData.getConditionCode() +""; // String messageId = processData.getMsgId(); // String messageText = processData.getMsgText(); // logger.info("[리모트송수신] [NDM_Api] ☞ Process Number : "+ processNumber); // logger.info("[리모트송수신] [NDM_Api] ☞ Return code : "+ resultCode); // logger.info("[리모트송수신] [NDM_Api] ☞ Message id : "+ messageId +" ["+ messageText +"]"); // // //파일전송 로그정보 설정 // if (isLogging) logInfo.setNdmPnumber (processNumber); // if (isLogging) logInfo.setResultCode (resultCode); // // if (!resultCode.equals(RESULT_CODE_SUCCESS)) { // throw new Exception("NDM Submit 명령어 실행 결과 값이 정상이 아닙니다. (ResultCode:"+ resultCode +", MessageId:"+ messageId +")"); // } // } // logger.info("[리모트송수신] [NDM_Api] ▶ NDM Submit Command 수행 완료."); // return alist; // } // // private ArrayList executeSelectCommand(String command) throws Exception { // // logger.info("[리모트송수신] [NDM_Api] ▶ NDM Select Command 수행 시작..."); // logger.info("[리모트송수신] [NDM_Api] ⓟ Command : "+ command); // MediatorEnum seleteResults = cdNode.execute(command); // // ArrayList alist = new ArrayList(); // while (seleteResults.hasMoreElements()) { // Object obj = seleteResults.getNextElement(); // alist.add(obj); // logger.debug("[리모트송수신] [NDM_Api] ☞ Process Data : "+ obj); // //CDProcess processData = (CDProcess)submitResults.getNextElement(); // //logger.info("[리모트송수신] [NDM_Api] [NDM Command] ☞ Process Data : "+ processData); // } // logger.info("[리모트송수신] [NDM_Api] ▶ NDM Select Command 수행 완료."); // return alist; // } // // //}