package com.cim.idm.wmsextend.generic.esb;

import com.cim.idm.flowpackage.exception.BpelException;
import com.cim.idm.framework.IDMFrameServiceProxy;
import com.cim.idm.framework.data.EventInfo;
import com.cim.idm.framework.esb.IRequester;
import com.cim.idm.framework.exception.IDMFrameErrorSignal;
import com.cim.idm.framework.exception.ext.DuplicateNameSignal;
import com.cim.idm.framework.exception.ext.FrameworkErrorSignal;
import com.cim.idm.framework.exception.ext.InvalidStateTransitionSignal;
import com.cim.idm.framework.exception.ext.NotFoundSignal;
import com.cim.idm.framework.util.xml.JdomUtils;
import com.cim.idm.wmsextend.generic.GenericServiceProxy;
import com.cim.idm.wmsextend.generic.errorHandler.CustomException;
import com.cim.idm.wmsextend.generic.object.ErrorDef;
import com.cim.idm.wmsextend.generic.util.CommonUtil;
import com.cim.idm.wmsextend.generic.util.SMessageUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdom.Document;
import org.jdom.Element;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;

public class ESBService implements ApplicationContextAware {

	private static Log log = LogFactory.getLog(ESBService.class);
	/**
	 * @uml.property name="applicationContext"
	 * @uml.associationEnd
	 */
	private ApplicationContext applicationContext;
	public static final String SUCCESS = "0";
	/**
	 * @uml.property name="sendSubjectMap"
	 * @uml.associationEnd 
	 *                     qualifier="constant:java.lang.String java.lang.String"
	 */
	private static Map<String, String> sendSubjectMap = new Hashtable<String, String>();
	
	private static Map<String, String> customSubjectMap = new Hashtable<String, String>();

	/*
	 * Name : init Desc : This function is sendSubjectMap init Author : ZXY
	 * Systems, Inc Date : 2013.03.04
	 */
	public void init() {
		sendSubjectMap.put("CNXsvr", makeCustomServerLocalSubject("CNXsvr"));
		sendSubjectMap.put("QRYsvr", makeCustomServerLocalSubject("QRYsvr"));
		sendSubjectMap.put("PDAsvr", makeCustomServerLocalSubject("PDAsvr"));
		sendSubjectMap.put("ERPsvr", makeCustomServerLocalSubject("ERPsvr"));
		sendSubjectMap.put("CNMsvr", makeCustomServerLocalSubject("CNMsvr"));
		sendSubjectMap.put("AWMsvr", makeCustomServerLocalSubject("AWMsvr"));
		sendSubjectMap.put("AWXsvr", makeCustomServerLocalSubject("AWXsvr"));
		setCustomSubjectMap();
	}

	/*
	 * Name : getSendSubject Desc : This function is get SendSubject Author :
	 * ZXY Systems, Inc Date : 2013.03.04
	 */
	public static String getSendSubject(String serverName) {
		if (log.isInfoEnabled()) {
			log.debug("serverName = " + serverName);
		}

		return sendSubjectMap.get(serverName);
	}

	public static String getCustomSubject(String serverName){
		return customSubjectMap.get(serverName);
	}
	
	private void setCustomSubjectMap(){
		//ReadOnly
		customSubjectMap.put("SCHsvr", makeCustomServerLocalSubject("SCHsvr"));
		customSubjectMap.put("OICAlarm", System.getProperty("company")
				                              + "." + System.getProperty("factory")
				                              + "." + System.getProperty("mode")
				                              + "." + System.getProperty("cim")
				                              + ".OIC");
		customSubjectMap.put("MCS_SYSTEM", CommonUtil.getSubjectNameBySystemName("MCS")); 
	}
	
	/**
	 * auther is TY
	 * @param doc
	 * @param senderName
	 * FUN ： Send to MWMS
	 */
	public static void TY_sendBySender_Tape (Document doc, String senderName) {
		
		//通过Jdom生成XML Message
		String sendMsg = JdomUtils.toString(doc);
		//check senderName是否为ToMWMSSender
		if( StringUtils.equals(senderName, "ToMWMSSender")){
			
			GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldNameXmlData);
		}
		else {
			
			GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);	
		}
		//Send Message
		GenericServiceProxy.getGenericSender(senderName).send(sendMsg);
		log.debug("senderName = " + senderName);

		if ( !StringUtils.equals(senderName, "ToMWMSSender") ){
			log.debug(" SEND : Message=" + sendMsg);
		}
	}
	
	
	/**
	 * User: by TY
	 * @param materialName
	 * @param materialType
	 * @param Status
	 * @param lastEventUser
	 * @param Lasteventcomment
	 * @param fabInTimeKey
	 */
	public void TY_UpdateRubbingTape(String materialName, String materialType,
			String Status, String lastEventUser, String Lasteventcomment,
			String fabInTimeKey) {

		String sql = "UPDATE  BSMAT_RUBBING_TAPE "
				+ "SET STATUS= :Status, LASTEVENTUSER = :lastEventUser, LASTEVENTCOMMENT = :Lasteventcomment, FAB_IN_TIMEKEY= :fabInTimeKey, LASTEVENTNAME= :lastEventName "
				+ " WHERE MATERIALNAME = :materialName AND MATERIALTYPE= :materialType ";

		String lastEventName = "TapeFABIn";

		Map<String, String> bindMap = new HashMap<String, String>();
		bindMap.put("materialName", materialName);
		bindMap.put("materialType", materialType);
		bindMap.put("Status", Status);
		bindMap.put("lastEventUser", lastEventUser);
		bindMap.put("Lasteventcomment", Lasteventcomment);
		bindMap.put("fabInTimeKey", fabInTimeKey);
		bindMap.put("lastEventName", lastEventName);

		IDMFrameServiceProxy.getSqlTemplate().update(sql, bindMap);
	}

	/*
	* Name : sendRequestToMWMS
	* Desc : This function is sendRequestToMWMS - Send FAB IN Messages to MWMS
	* Author : TY
	* Date : 2017.5.11
	*/
	public void TY_sendRequestToMWMS(Map<String, String> bindMap) throws CustomException
	{
		int maxSendCount = 20;
		String sourceSubjectName = "";
		String targetSubjectName = "";
		
		try
		{
			//获取默认最大Send次数，默认为20
			maxSendCount = Integer.parseInt(CommonUtil.getEnumDefValueStringByEnumName("MWMSSendMessageCount"));
		}
		catch(Exception ex)
		{
			maxSendCount = 20;
		}
	
		if( bindMap != null )
		{
			//发送者
			sourceSubjectName = ESBService.getSendSubject("MATsvr");
			//目标地
			targetSubjectName = ESBService.getSendSubject("");
			
			log.info("TY_sendRequestToMWMS.  data Found. Send " + bindMap.toString() + "Messages to MWMS.");

			/**
			 * String materialName, String messageName, String shopName, String machineName, String transactionId,
			 *  String sourceSubjectName, String targetSubjectName, String eventUser
			 */
			
			String materialName = bindMap.get("materialName");
			String messageName = bindMap.get("messageName");
			String shopName = bindMap.get("shopName");
			String machineName = bindMap.get("machineName");
			String transactionId = bindMap.get("transactionId");
			String eventUser = bindMap.get("eventUser");		
			
			// Set Message,将bindMap写入Document文件 
			Document doc = TY_setMessageFormat_sendRequestMessageToMWMS(materialName, messageName, transactionId, sourceSubjectName, targetSubjectName,
					eventUser, machineName,shopName);

			// Send Message to MWMS
			ESBService.TY_sendBySender_Tape(doc, "ToMWMSSender");

			
		}
		else
		{
			log.info("TY_sendRequestToMWMS. No data found.");
		}
		
	}


	/*
	 * Name : sendReplyBySender
	 * Design by TY
	 */
	public void TY_sendReplyBySender(String replySubject, String replyMessage,
			String senderName) {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			// log.debug("replyMessage = " + replyMessage);
			log.debug("senderName = " + senderName);
		}
	
		//不明白此作用？
		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).reply(replySubject, replyMessage);
	
		log.debug(" SERP : Subject=" + replySubject);
		// log.debug(" SERP : Message=" + sReplyMsg);
	}
	
	
	/*
	* Name : TY_setMessageFormat_sendRequestMessageToMWMS
	* Author : TYTY
	* Date : 2017.5.13
	* FUN: 生成XML Message，并返回Document
	* materialName, messageName, transactionId, sourceSubjectName, targetSubjectName,
					eventUser, machineName,shopName
	* 
	*/
	public Document TY_setMessageFormat_sendRequestMessageToMWMS(
			String materialName, String messageName, String transactionId, String sourceSubjectName, 
			String targetSubjectName, String eventUser, String machineName, String shopName)
	{
		Element message = new Element( SMessageUtil.Message_Tag );  

		//创建xml Header
		Element header = new Element("Header");

		Element messageNameE = new Element("MESSAGENAME");
		messageNameE.setText(messageName);
		header.addContent(messageNameE);
		
		Element shopNameE = new Element("SHOPNAME");
		shopNameE.setText(shopName);
		header.addContent(shopNameE);

		Element machineNameE = new Element("MACHINENAME");
		machineNameE.setText(machineName);
		header.addContent(machineNameE);

		Element eventUserE = new Element("EVENTUSER");
		eventUserE.setText(eventUser);
		header.addContent(eventUserE);

		Element originalSourceSubjectName = new Element("ORIGINALSOURCESUBJECTNAME");
		originalSourceSubjectName.setText(sourceSubjectName);
		header.addContent(originalSourceSubjectName);
		
		Element eventCommentE = new Element("EVENTCOMMENT");
		eventCommentE.setText(messageName);
		header.addContent(eventCommentE);

		Element transactionIdE = new Element("TRANSACTIONID");
		machineNameE.setText(transactionId);
		header.addContent(transactionIdE);

		Element sourceSubjectNameE = new Element("SOURCESUBJECTNAME");
		sourceSubjectNameE.setText(sourceSubjectName);
		header.addContent(sourceSubjectNameE);

		Element targetSubjectNameE = new Element("TARGETSUBJECTNAME");
		targetSubjectNameE.setText(targetSubjectName);
		header.addContent(targetSubjectNameE);

		message.addContent(header);
		
		// 创建Body Element
		Element bodyElement = new Element("Body");

		Element materialNameE = new Element("MATERIALNAME");
		materialNameE.setText(materialName);
		bodyElement.addContent(materialNameE);

		message.addContent(bodyElement);


		//通过XML Message，创建Document的replyDoc，并返回
		Document replyDoc = new Document( message );

//		String sReplyMsg = JdomUtils.toString(replyDoc);
//		log.info(sReplyMsg);

		return replyDoc;
	}
	

	
	
	
	/*
	 * Name : makeCustomServerLocalSubject Desc : This function is
	 * makeCustomServerLocalSubject Author : ZXY Systems, Inc Date : 2013.03.04
	 */
	public String makeCustomServerLocalSubject(String serverName) {
		// _LOCAL.KRK0100.DEV.MES.MES.QRYsvr
		// A1.SO.G1.PROD.MES.QRYsvr

		if (log.isInfoEnabled()) {
			log.debug("serverName = " + serverName);
		}

		StringBuffer serverSubject = new StringBuffer();

		if (StringUtils.equals(serverName, "CNMsvr")
				|| StringUtils.equals(serverName, "PEMsvr")
				|| StringUtils.equals(serverName, "TEMsvr")
				|| StringUtils.equals(serverName, "QRYsvr")) {

			serverSubject.append(System.getProperty("company"))
					.append("." + System.getProperty("factory"))
					.append("." + System.getProperty("cim"))
					.append("." + System.getProperty("mode"))
					.append("." + serverName);

		} else {

			if (System.getProperty("company").indexOf("_LOCAL.") < 0) {

				serverSubject.append("_LOCAL")
						.append("." + System.getProperty("company"))
						.append("." + System.getProperty("factory"))
						.append("." + System.getProperty("cim"))
						.append("." + System.getProperty("mode"))
						.append("." + serverName);

			} else {

				serverSubject.append(System.getProperty("company"))
						.append("." + System.getProperty("factory"))
						.append("." + System.getProperty("cim"))
						.append("." + System.getProperty("mode"))
						.append("." + serverName);
			}
		}

		log.info("Maked SubjectName=" + serverSubject.toString());

		return serverSubject.toString();
	}

	/**
	 * @param arg0
	 * @throws BeansException
	 * @uml.property name="applicationContext"
	 */
	public void setApplicationContext(ApplicationContext arg0)
			throws BeansException {
		// TODO Auto-generated method stub
		this.applicationContext = arg0;
	}

	/*
	 * Name : sendRequest Desc : This function is sendRequest Author : ZXY
	 * Systems, Inc Date : 2013.03.04
	 */
	public Document sendRequest(String subject, Document doc) throws Exception {
		if (log.isInfoEnabled()) {
			log.debug("subject = " + subject);
		}

		String sendMsg = JdomUtils.toString(doc);
		IDMFrameServiceProxy.getGenericSender().setDataField(SMessageUtil.DataFieldName);
		String reply = (String) IDMFrameServiceProxy.getGenericSender().sendRequest(subject, sendMsg);
		Document createDocument = JdomUtils.loadText(reply);
		return createDocument;
	}

	/*
	 * Name : sendRequestTimeOut Desc : This function is sendRequestTimeOut
	 * Author : ZXY Systems, Inc Date : 2013.03.04
	 */
	public Document sendRequestTimeOut(String subject, Document doc, int timeOut)
			throws Exception {
		if (log.isInfoEnabled()) {
			log.debug("subject = " + subject);
		}

		String sendMsg = JdomUtils.toString(doc);
		IDMFrameServiceProxy.getGenericSender().setDataField(SMessageUtil.DataFieldName);
		String reply = (String) IDMFrameServiceProxy.getGenericSender().sendRequest(subject, sendMsg, timeOut);
		Document createDocument = JdomUtils.loadText(reply);
		return createDocument;
	}

	/*
	 * Name : send Desc : This function is IDM API send Author : ZXY Systems,
	 * Inc Date : 2013.03.04
	 */
	public void send(String subject, Document doc) {
		if (log.isInfoEnabled()) {
			log.debug("subject = " + subject);
		}

		String sendMsg = JdomUtils.toString(doc);
		GenericServiceProxy.getGenericSender("GenericSender").setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender("GenericSender").send(subject, sendMsg);
		log.debug(" SEND : Subject=" + subject);
		log.debug(" SEND : Message=" + sendMsg.toString());
	}
	
	public static void sendL(String subject, Document doc, Element element)
	{
		if (log.isInfoEnabled()) {
			log.debug("subject = " + subject);
		}

		Element message = new Element(SMessageUtil.Message_Tag);

		Element oriheader = doc.getDocument().getRootElement().getChild("Header");

		Element header = new Element("Header");
		// Element body = new Element("Body");

		Element messagename = new Element("MESSAGENAME");
		messagename.setText(oriheader.getChildText("MESSAGENAME"));
		header.addContent(messagename);

		Element shopName = new Element("SHOPNAME");
		shopName.setText(oriheader.getChildText("SHOPNAME"));
		header.addContent(shopName);

		Element machineName = new Element("MACHINENAME");
		machineName.setText(oriheader.getChildText("MACHINENAME"));
		header.addContent(machineName);

		Element transactionid = new Element("TRANSACTIONID");
		transactionid.setText(oriheader.getChildText("TRANSACTIONID"));
		header.addContent(transactionid);

		Element originalSourceSubjectName = new Element("ORIGINALSOURCESUBJECTNAME");
		originalSourceSubjectName.setText(oriheader.getChildText("ORIGINALSOURCESUBJECTNAME"));
		header.addContent(originalSourceSubjectName);

		Element sourceSubjectName = new Element("SOURCESUBJECTNAME");
		sourceSubjectName.setText(oriheader.getChildText("SOURCESUBJECTNAME"));
		header.addContent(sourceSubjectName);

		Element targetSubjectName = new Element("TARGETSUBJECTNAME");
		targetSubjectName.setText(oriheader.getChildText("TARGETSUBJECTNAME"));
		header.addContent(targetSubjectName);

		Element eventUser = new Element("EVENTUSER");
		eventUser.setText(oriheader.getChildText("EVENTUSER"));
		header.addContent(eventUser);

		Element eventComment = new Element("EVENTCOMMENT");
		eventComment.setText(oriheader.getChildText("EVENTCOMMENT"));
		header.addContent(eventComment);

		message.addContent(header);

		if (element != null) {
			message.addContent(element);
		}
		
		Element returnElement = new Element("Return");

		Element returnCode = new Element("RETURNCODE");
		returnCode.setText(SUCCESS);
		returnElement.addContent(returnCode);

		Element returnMessage = new Element("RETURNMESSAGE");
		returnMessage.setText("");
		returnElement.addContent(returnMessage);

		message.addContent(returnElement);
		
		String sendMsg = JdomUtils.toString(message);
		IDMFrameServiceProxy.getGenericSender().setDataField(SMessageUtil.DataFieldName);
		IDMFrameServiceProxy.getGenericSender().send(subject, sendMsg);
		
		log.debug(" SEND : Subject=" + subject);
		log.debug(" SEND : Message=" + sendMsg.toString());
	}

	/*
	 * Name : sendBySender Desc : This function is IDM API send Author : ZXY
	 * Systems, Inc Date : 2013.03.04
	 */
	public static void sendBySender(Document doc, String senderName) {
		String sendMsg = JdomUtils.toString(doc);
		if( StringUtils.equals(senderName, "DSPSender")){
			GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldNameXmlData);
		}
		else {
			GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);	
		}
		
		GenericServiceProxy.getGenericSender(senderName).send(sendMsg);
		log.debug("senderName = " + senderName);

		if ( !StringUtils.equals(senderName, "FMCSender") ){
			log.debug(" SEND : Message=" + sendMsg);
		}
	}

	/*
	 * Name : sendBySender Desc : This function is Create XML IDM API send
	 * Author : ZXY Systems, Inc Date : 2013.03.04
	 */
	public static Document sendBySender(Document doc, Element element,
			String senderName) throws Exception {
		if (log.isInfoEnabled()) {
			log.debug("senderName = " + senderName);
		}

		String sReplyMsg = null;

		Element message = new Element(SMessageUtil.Message_Tag);

		Element oriheader = doc.getDocument().getRootElement()
				.getChild("Header");

		Element header = new Element("Header");

		Element messagename = new Element("MESSAGENAME");
		messagename.setText(oriheader.getChildText("MESSAGENAME"));
		header.addContent(messagename);

		Element shopName = new Element("SHOPNAME");
		shopName.setText(oriheader.getChildText("SHOPNAME"));
		header.addContent(shopName);

		Element machineName = new Element("MACHINENAME");
		machineName.setText(oriheader.getChildText("MACHINENAME"));
		header.addContent(machineName);

		Element transactionid = new Element("TRANSACTIONID");
		transactionid.setText(oriheader.getChildText("TRANSACTIONID"));
		header.addContent(transactionid);

		Element originalSourceSubjectName = new Element(
				"ORIGINALSOURCESUBJECTNAME");
		originalSourceSubjectName.setText(oriheader
				.getChildText("ORIGINALSOURCESUBJECTNAME"));
		header.addContent(originalSourceSubjectName);

		Element sourceSubjectName = new Element("SOURCESUBJECTNAME");
		sourceSubjectName.setText(oriheader.getChildText("SOURCESUBJECTNAME"));
		header.addContent(sourceSubjectName);

		Element targetSubjectName = new Element("TARGETSUBJECTNAME");
		targetSubjectName.setText(oriheader.getChildText("TARGETSUBJECTNAME"));
		header.addContent(targetSubjectName);

		Element eventUser = new Element("EVENTUSER");
		eventUser.setText(oriheader.getChildText("EVENTUSER"));
		header.addContent(eventUser);

		Element eventComment = new Element("EVENTCOMMENT");
		eventComment.setText(oriheader.getChildText("EVENTCOMMENT"));
		header.addContent(eventComment);

		message.addContent(header);

		if (element != null) {
			message.addContent(element);
		}
		Element returnElement = new Element("Return");

		Element returnCode = new Element("RETURNCODE");
		returnCode.setText(SUCCESS);
		returnElement.addContent(returnCode);

		Element returnMessage = new Element("RETURNMESSAGE");
		returnMessage.setText("");
		returnElement.addContent(returnMessage);

		message.addContent(returnElement);

		Document replyDoc = new Document(message);

		sReplyMsg = JdomUtils.toString(replyDoc);

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).send(sReplyMsg);
		log.debug(" SEND : SenderName=" + senderName);
		log.debug(" SEND : Message=" + sReplyMsg);
		
		return replyDoc;
	}

	/*
	 * Name : sendBySender
	 * Desc : This function is Create Return XML IDM API
	 * send Author : ZXY Systems, Inc
	 * Date : 2014.12.03
	 */
	public static void sendBySender(String subject, Document doc, String senderName)
	{
		if (log.isInfoEnabled()) {
			log.debug("subject = " + subject);
			log.debug("senderName = " + senderName);
		}

		// add return
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ReturnCode, SUCCESS);
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ErrorMessage, "");
		//
		//Add 20170706
		/*if(StringUtils.equals(senderName, "HIFSender"))
		{
			try{
				String sourceSubjectNameText = "";
				String targetSubjectNameText = "";
				Element root = doc.getDocument().getRootElement();

				try {
					Element sourceSubjectName = root.getChild("Header").getChild("SOURCESUBJECTNAME");
					sourceSubjectNameText = sourceSubjectName.getText();
					Element targetSubjectName = root.getChild("Header").getChild("TARGETSUBJECTNAME");
					targetSubjectNameText = targetSubjectName.getText();
					
					if(StringUtils.isEmpty(sourceSubjectNameText)){
						sourceSubjectNameText = ESBService.getSendSubject("TEMsvr");
					}
					
					if(StringUtils.isEmpty(targetSubjectNameText)){
						targetSubjectNameText = ESBService.getSendSubject("HIFsvr");					
					}
				
					sourceSubjectName.setText(sourceSubjectNameText);
					targetSubjectName.setText(targetSubjectNameText);
					
				} catch (Exception e) {
					throw new CustomException("MACHINE-9003", sourceSubjectNameText, targetSubjectNameText);
				}
			}catch(Exception e){}
		}
		else*/ if(StringUtils.equals(senderName, "ACSSender"))
		{
			try{
				String sourceSubjectNameText = "";
				String targetSubjectNameText = "";
				Element root = doc.getDocument().getRootElement();

				try {
					Element sourceSubjectName = root.getChild("Header").getChild("SOURCESUBJECTNAME");
					sourceSubjectNameText = sourceSubjectName.getText();
					Element targetSubjectName = root.getChild("Header").getChild("TARGETSUBJECTNAME");
					
					if(StringUtils.isEmpty(sourceSubjectNameText)){
						sourceSubjectNameText = ESBService.getSendSubject("TEMsvr");
					}
				
					sourceSubjectName.setText(sourceSubjectNameText);
					targetSubjectName.setText(subject);
					
				} catch (Exception e) {
					throw new CustomException("MACHINE-9003", sourceSubjectNameText, targetSubjectNameText);
				}
			}catch(Exception e){}
		}

		String sendMsg = JdomUtils.toString(doc);
		
		//IDMFrameServiceProxy.getGenericSender().setDataField("Message");
		
		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).send(subject, sendMsg);
		
		log.debug(" SEND : Subject=" + subject);
//		if(senderName.equals("FMCSender"))
//		{
//			if(sendMsg.length() >= 620)
//			{
//				log.debug(" SEND : Message=" + sendMsg.substring(0, 620) + "\n .....Skip..... ");
//			}
//			else
//			{
//				log.debug(" SEND : Message=" + sendMsg);
//			}
//		}
//		else
//		{
//			log.debug(" SEND : Message=" + sendMsg);
//		}
		if(StringUtils.equals(senderName, "FMCSender"))
		{
			try{
				String machineName = doc.getRootElement().getChild(SMessageUtil.Body_Tag).getChildText("MACHINENAME");
				if(StringUtils.isNotEmpty(machineName))
				{
					log.info("EQP ID: "+machineName);
				}
			}catch(Exception e){}
			log.debug(" Send Message =  " +sendMsg);
		}
		else
		{
			log.info(" SEND : Message=" + sendMsg);
		}
	}

	/*
	 * Name : sendBySender
	 * Desc : This function is Create Return XML IDM API send
	 * Author : ZXY Systems, Inc
	 * Date : 2013.03.04
	 */
	public static Document sendBySender(String subject, Document doc, String senderName, String returnCode, String returnMsg)
	{
		if (log.isInfoEnabled()) {
			log.debug("subject = " + subject);
			log.debug("senderName = " + senderName);
		}

		// add return
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ReturnCode, returnCode);
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ErrorMessage, returnMsg);
		//
		
		//Add 20170706
		/*if(StringUtils.equals(senderName, "HIFSender"))
		{
			try{
				String sourceSubjectNameText = "";
				String targetSubjectNameText = "";
				Element root = doc.getDocument().getRootElement();

				try {
					Element sourceSubjectName = root.getChild("Header").getChild("SOURCESUBJECTNAME");
					sourceSubjectNameText = sourceSubjectName.getText();
					Element targetSubjectName = root.getChild("Header").getChild("TARGETSUBJECTNAME");
					targetSubjectNameText = targetSubjectName.getText();
					
					if(StringUtils.isEmpty(sourceSubjectNameText)){
						sourceSubjectNameText = ESBService.getSendSubject("TEMsvr");
					}
					
					if(StringUtils.isEmpty(targetSubjectNameText)){
						targetSubjectNameText = ESBService.getSendSubject("HIFsvr");					
					}
				
					sourceSubjectName.setText(sourceSubjectNameText);
					targetSubjectName.setText(targetSubjectNameText);
					
				} catch (Exception e) {
					throw new CustomException("MACHINE-9003", sourceSubjectNameText, targetSubjectNameText);
				}
			}catch(Exception e){}
		}
		else*/ if(StringUtils.equals(senderName, "ACSSender"))
		{
			try{
				String sourceSubjectNameText = "";
				String targetSubjectNameText = "";
				Element root = doc.getDocument().getRootElement();

				try {
					Element sourceSubjectName = root.getChild("Header").getChild("SOURCESUBJECTNAME");
					sourceSubjectNameText = sourceSubjectName.getText();
					Element targetSubjectName = root.getChild("Header").getChild("TARGETSUBJECTNAME");
					targetSubjectNameText = targetSubjectName.getText();
					
					if(StringUtils.isEmpty(sourceSubjectNameText)){
						sourceSubjectNameText = ESBService.getSendSubject("TEMsvr");
					}
					
					if(StringUtils.isEmpty(targetSubjectNameText)){
						targetSubjectNameText = CommonUtil.getSubjectNameBySystemName("ACS");					
					}
				
					sourceSubjectName.setText(sourceSubjectNameText);
					targetSubjectName.setText(targetSubjectNameText);
					
				} catch (Exception e) {
					throw new CustomException("MACHINE-9003", sourceSubjectNameText, targetSubjectNameText);
				}
			}catch(Exception e){}
		}

		String sendMsg = JdomUtils.toString(doc);
		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).send(subject, sendMsg);
		log.debug(" SEND : Subject=" + subject);
		log.debug(" SEND : Message=" + sendMsg);
		
		return doc;
	}

	/*
	 * Name : sendBySender Desc : This function is IDM API send Author : ZXY
	 * Systems, Inc Date : 2013.03.04
	 */
	public static void sendBySender(String subject, String sSendMsg,
			String senderName) {
		if (log.isInfoEnabled()) {
			log.debug("subject = " + subject);
			log.debug("senderName = " + senderName);
		}

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		
		if (!StringUtils.isEmpty(subject))
		{
			GenericServiceProxy.getGenericSender(senderName).send(subject, sSendMsg);
		} else {
			GenericServiceProxy.getGenericSender(senderName).send(sSendMsg);
		}

		log.debug(" SEND : Subject=" + subject);
		// log.debug(" SEND : Message=" + sSendMsg);
	}

	/*
	 * Name : sendBySenderMessage Desc : This function is Create Return XML IDM
	 * API send Author : ZXY Systems, Inc Date : 2013.03.04
	 */
	public static void sendBySenderMessage(String subject, Document doc,
			String senderName) {
		if (log.isInfoEnabled()) {
			log.debug("subject = " + subject);
			log.debug("senderName = " + senderName);
		}

		// add return
		// SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ReturnCode,
		// SUCCESS);
		// SMessageUtil.setResultItemValue(doc,
		// SMessageUtil.Result_ErrorMessage, "");
		//

		String sendMsg = JdomUtils.toString(doc);
		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).send(subject, sendMsg);
		log.debug(" SEND : Subject=" + subject);
		log.debug(" SEND : Message=" + sendMsg);
	}

	/*
	 * Name : send Desc : This function is Create XML IDM API reply Author : ZXY
	 * Systems, Inc Date : 2013.03.04
	 */
	public void send(String replySubject, Document doc, Element element)
			throws Exception {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
		}

		String sReplyMsg = null;
		String XPathBody = "//" + SMessageUtil.Message_Tag + "/"
				+ SMessageUtil.Body_Tag;
		String XPathHeader = "//" + SMessageUtil.Message_Tag + "/"
				+ SMessageUtil.Header_Tag;

		Element message = new Element(SMessageUtil.Message_Tag);

		Element oriheader = doc.getDocument().getRootElement()
				.getChild("Header");

		Element header = new Element("Header");
		Element body = new Element("Body");

		Element messagename = new Element("MESSAGENAME");
		messagename.setText(oriheader.getChildText("MESSAGENAME"));
		header.addContent(messagename);

		Element transactionid = new Element("TRANSACTIONID");
		transactionid.setText(oriheader.getChildText("TRANSACTIONID"));
		header.addContent(transactionid);

		message.addContent(header);

		if (element != null) {
			body = element;
			message.addContent(element);
		}
		Document replyDoc = new Document(message);

		sReplyMsg = JdomUtils.toString(replyDoc);

		IDMFrameServiceProxy.getGenericSender().setDataField(SMessageUtil.DataFieldName);
		IDMFrameServiceProxy.getGenericSender().reply(replySubject, sReplyMsg);

		log.debug(" SEND : Subject=" + replySubject);
		log.debug(" SEND : Message=" + sReplyMsg.toString());
	}

	/*
	 * Name : sendBySender Desc : This function is Create XML IDM API reply
	 * Author : ZXY Systems, Inc Date : 2013.03.04
	 */
	public static Document sendBySender(String replySubject, Document doc, Element element, String senderName) throws Exception
	{
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			log.debug("senderName = " + senderName);
		}

		String sReplyMsg = null;
		// String XPathBody =
		// "//"+SMessageUtil.Message_Tag+"/"+SMessageUtil.Body_Tag;
		// String XPathHeader =
		// "//"+SMessageUtil.Message_Tag+"/"+SMessageUtil.Header_Tag;

		Element message = new Element(SMessageUtil.Message_Tag);

		Element oriheader = doc.getDocument().getRootElement()
				.getChild("Header");

		Element header = new Element("Header");
		// Element body = new Element("Body");

		Element messagename = new Element("MESSAGENAME");
		messagename.setText(oriheader.getChildText("MESSAGENAME"));
		header.addContent(messagename);

		Element shopName = new Element("SHOPNAME");
		shopName.setText(oriheader.getChildText("SHOPNAME"));
		header.addContent(shopName);

		Element machineName = new Element("MACHINENAME");
		machineName.setText(oriheader.getChildText("MACHINENAME"));
		header.addContent(machineName);

		Element transactionid = new Element("TRANSACTIONID");
		transactionid.setText(oriheader.getChildText("TRANSACTIONID"));
		header.addContent(transactionid);

		Element originalSourceSubjectName = new Element(
				"ORIGINALSOURCESUBJECTNAME");
		originalSourceSubjectName.setText(oriheader
				.getChildText("ORIGINALSOURCESUBJECTNAME"));
		header.addContent(originalSourceSubjectName);

		Element sourceSubjectName = new Element("SOURCESUBJECTNAME");
		sourceSubjectName.setText(oriheader.getChildText("SOURCESUBJECTNAME"));
		header.addContent(sourceSubjectName);

		Element targetSubjectName = new Element("TARGETSUBJECTNAME");
		targetSubjectName.setText(oriheader.getChildText("TARGETSUBJECTNAME"));
		header.addContent(targetSubjectName);

		Element eventUser = new Element("EVENTUSER");
		eventUser.setText(oriheader.getChildText("EVENTUSER"));
		header.addContent(eventUser);

		Element eventComment = new Element("EVENTCOMMENT");
		eventComment.setText(oriheader.getChildText("EVENTCOMMENT"));
		header.addContent(eventComment);

		message.addContent(header);

		if (element != null) {
			// body = element;
			message.addContent(element);
		}
		//
		Element returnElement = new Element("Return");

		Element returnCode = new Element("RETURNCODE");
		returnCode.setText(SUCCESS);
		returnElement.addContent(returnCode);

		Element returnMessage = new Element("RETURNMESSAGE");
		returnMessage.setText("");
		returnElement.addContent(returnMessage);

		message.addContent(returnElement);

		//
		Document replyDoc = new Document(message);

		sReplyMsg = JdomUtils.toString(replyDoc);

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).reply(replySubject, sReplyMsg);

		log.info(" SEND : Subject=" + replySubject);
		log.info(" SEND : Message=" + sReplyMsg);

		return replyDoc;
	}

	/*
	 * Name : sendBySender Desc : This function is Create XML IDM API reply
	 * Author : ZXY Systems, Inc Date : 2013.03.04
	 */
	public static void sendBySenderL(Document doc, Element element, String senderName) throws Exception
	{
		String msg = null;
		
		Element message = new Element(SMessageUtil.Message_Tag);

		Element oriheader = doc.getDocument().getRootElement().getChild("Header");

		Element header = new Element("Header");
		// Element body = new Element("Body");

		Element messagename = new Element("MESSAGENAME");
		messagename.setText(oriheader.getChildText("MESSAGENAME"));
		header.addContent(messagename);

		Element shopName = new Element("SHOPNAME");
		shopName.setText(oriheader.getChildText("SHOPNAME"));
		header.addContent(shopName);

		Element machineName = new Element("MACHINENAME");
		machineName.setText(oriheader.getChildText("MACHINENAME"));
		header.addContent(machineName);

		Element transactionid = new Element("TRANSACTIONID");
		transactionid.setText(oriheader.getChildText("TRANSACTIONID"));
		header.addContent(transactionid);

		Element originalSourceSubjectName = new Element("ORIGINALSOURCESUBJECTNAME");
		originalSourceSubjectName.setText(oriheader.getChildText("ORIGINALSOURCESUBJECTNAME"));
		header.addContent(originalSourceSubjectName);

		Element sourceSubjectName = new Element("SOURCESUBJECTNAME");
		sourceSubjectName.setText(oriheader.getChildText("SOURCESUBJECTNAME"));
		header.addContent(sourceSubjectName);

		Element targetSubjectName = new Element("TARGETSUBJECTNAME");
		targetSubjectName.setText(oriheader.getChildText("TARGETSUBJECTNAME"));
		header.addContent(targetSubjectName);

		Element eventUser = new Element("EVENTUSER");
		eventUser.setText(oriheader.getChildText("EVENTUSER"));
		header.addContent(eventUser);

		Element eventComment = new Element("EVENTCOMMENT");
		eventComment.setText(oriheader.getChildText("EVENTCOMMENT"));
		header.addContent(eventComment);

		message.addContent(header);

		if (element != null) {
			message.addContent(element);
		}

		Element returnElement = new Element("Return");

		Element returnCode = new Element("RETURNCODE");
		returnCode.setText(SUCCESS);
		returnElement.addContent(returnCode);

		Element returnMessage = new Element("RETURNMESSAGE");
		returnMessage.setText("");
		returnElement.addContent(returnMessage);

		message.addContent(returnElement);

		Document newDoc = new Document(message);

		msg = JdomUtils.toString(newDoc);

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).send(msg);

//		String sendMsg = JdomUtils.toString(message);
//		IDMFrameServiceProxy.getGenericSender().setDataField(SMessageUtil.DataFieldName);
//		IDMFrameServiceProxy.getGenericSender().send(subject, sendMsg);
		
//		log.debug(" SEND : Message=" + sReplyMsg);
	}
	
	/*
	 * Name : sendBySender Desc : This function is Create XML IDM API reply
	 * Author : ZXY Systems, Inc Date : 2013.03.04
	 */
	public static void sendBySender(String replySubject, Document doc,
			Element element, String senderName, String returnMsg)
			throws Exception {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			log.debug("senderName = " + senderName);
		}

		String sReplyMsg = null;

		Element message = new Element(SMessageUtil.Message_Tag);

		Element oriheader = doc.getDocument().getRootElement()
				.getChild("Header");

		Element header = new Element("Header");

		Element messagename = new Element("MESSAGENAME");
		messagename.setText(oriheader.getChildText("MESSAGENAME"));
		header.addContent(messagename);

		Element shopName = new Element("SHOPNAME");
		shopName.setText(oriheader.getChildText("SHOPNAME"));
		header.addContent(shopName);

		Element machineName = new Element("MACHINENAME");
		machineName.setText(oriheader.getChildText("MACHINENAME"));
		header.addContent(machineName);

		Element transactionid = new Element("TRANSACTIONID");
		transactionid.setText(oriheader.getChildText("TRANSACTIONID"));
		header.addContent(transactionid);

		Element originalSourceSubjectName = new Element(
				"ORIGINALSOURCESUBJECTNAME");
		originalSourceSubjectName.setText(oriheader
				.getChildText("ORIGINALSOURCESUBJECTNAME"));
		header.addContent(originalSourceSubjectName);

		Element sourceSubjectName = new Element("SOURCESUBJECTNAME");
		sourceSubjectName.setText(oriheader.getChildText("SOURCESUBJECTNAME"));
		header.addContent(sourceSubjectName);

		Element targetSubjectName = new Element("TARGETSUBJECTNAME");
		targetSubjectName.setText(oriheader.getChildText("TARGETSUBJECTNAME"));
		header.addContent(targetSubjectName);

		Element eventUser = new Element("EVENTUSER");
		eventUser.setText(oriheader.getChildText("EVENTUSER"));
		header.addContent(eventUser);

		Element eventComment = new Element("EVENTCOMMENT");
		eventComment.setText(oriheader.getChildText("EVENTCOMMENT"));
		header.addContent(eventComment);

		message.addContent(header);

		if (element != null) {
			message.addContent(element);
		}

		Element returnElement = new Element("Return");

		Element returnCode = new Element("RETURNCODE");
		returnCode.setText(SUCCESS);
		returnElement.addContent(returnCode);

		Element returnMessage = new Element("RETURNMESSAGE");
		returnMessage.setText(returnMsg);
		returnElement.addContent(returnMessage);

		message.addContent(returnElement);

		//
		Document replyDoc = new Document(message);

		sReplyMsg = JdomUtils.toString(replyDoc);

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).reply(replySubject,sReplyMsg);

		log.debug(" SEND : Subject=" + replySubject);
		log.debug(" SEND : Message=" + sReplyMsg);

	}

	public static Document sendBySenderReturnMessage(String replySubject,
			Document doc, Element body, String senderName, String returnMsg)
			throws Exception {
		Element header = doc.getDocument().getRootElement()
				.getChild("Header");
		
		return sendBySenderReturnMessage(replySubject, header, body, senderName, returnMsg);
	}
	
	/**
	 * 
	    * @brief This function is sendBySenderReturnMessage
	    * @author Chenxing
	    * @param replySubject
	    * @param doc
	    * @param body
	    * @param senderName
	    * @param returnCode
	    * @param returnMsg
	    * @return
	    * @throws Exception
	 */
	public static Document sendBySenderReturnMessage( String replySubject, Document doc, Element body, String senderName, String returnCode, String returnMsg ) throws Exception
	{
		Element header = doc.getDocument().getRootElement().getChild( "Header" );

		return sendBySenderReturnMessage( replySubject, header, body, senderName, returnCode, returnMsg );
	}
	
	public static Document sendBySenderReturnMessage(String replySubject,
			Element oriheader, Element body, String senderName, String returnMsg)
			throws Exception {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			log.debug("senderName = " + senderName);
		}

		String sReplyMsg = null;

		Element message = new Element(SMessageUtil.Message_Tag);

		Element header = new Element("Header");

		Element messagename = new Element("MESSAGENAME");
		messagename.setText(oriheader.getChildText("MESSAGENAME"));
		header.addContent(messagename);

		Element shopName = new Element("SHOPNAME");
		shopName.setText(oriheader.getChildText("SHOPNAME"));
		header.addContent(shopName);

		Element machineName = new Element("MACHINENAME");
		machineName.setText(oriheader.getChildText("MACHINENAME"));
		header.addContent(machineName);

		Element transactionid = new Element("TRANSACTIONID");
		transactionid.setText(oriheader.getChildText("TRANSACTIONID"));
		header.addContent(transactionid);

		Element originalSourceSubjectName = new Element(
				"ORIGINALSOURCESUBJECTNAME");
		originalSourceSubjectName.setText(oriheader
				.getChildText("ORIGINALSOURCESUBJECTNAME"));
		header.addContent(originalSourceSubjectName);

		Element sourceSubjectName = new Element("SOURCESUBJECTNAME");
		sourceSubjectName.setText(oriheader.getChildText("SOURCESUBJECTNAME"));
		header.addContent(sourceSubjectName);

		Element targetSubjectName = new Element("TARGETSUBJECTNAME");
		targetSubjectName.setText(oriheader.getChildText("TARGETSUBJECTNAME"));
		header.addContent(targetSubjectName);

		Element eventUser = new Element("EVENTUSER");
		eventUser.setText(oriheader.getChildText("EVENTUSER"));
		header.addContent(eventUser);

		Element eventComment = new Element("EVENTCOMMENT");
		eventComment.setText(oriheader.getChildText("EVENTCOMMENT"));
		header.addContent(eventComment);

		message.addContent(header);

		if (body != null) {
			message.addContent(body);
		}

		Element returnElement = new Element("Return");

		Element returnCode = new Element("RETURNCODE");
		returnCode.setText(SUCCESS);
		returnElement.addContent(returnCode);

		Element returnMessage = new Element("RETURNMESSAGE");
		returnMessage.setText(returnMsg);
		returnElement.addContent(returnMessage);

		message.addContent(returnElement);

		//
		Document replyDoc = new Document(message);

		sReplyMsg = JdomUtils.toString(replyDoc);

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).reply(replySubject, sReplyMsg);

		log.info(" SEND : Subject=" + replySubject);
		log.info(" SEND : Message=" + sReplyMsg);

		return replyDoc;
	}
	
/**
 * 
    * @brief This function is sendBySenderReturnMessage
    * @author Chenxing
    * @param replySubject
    * @param oriheader
    * @param body
    * @param senderName
    * @param returnCodeT
    * @param returnMsg
    * @return
    * @throws Exception
 */
	public static Document sendBySenderReturnMessage(String replySubject,
			Element oriheader, Element body, String senderName, String returnCodeT, String returnMsg)
			throws Exception {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			log.debug("senderName = " + senderName);
		}

		String sReplyMsg = null;

		Element message = new Element(SMessageUtil.Message_Tag);

		Element header = new Element("Header");

		Element messagename = new Element("MESSAGENAME");
		messagename.setText(oriheader.getChildText("MESSAGENAME"));
		header.addContent(messagename);

		Element shopName = new Element("SHOPNAME");
		shopName.setText(oriheader.getChildText("SHOPNAME"));
		header.addContent(shopName);

		Element machineName = new Element("MACHINENAME");
		machineName.setText(oriheader.getChildText("MACHINENAME"));
		header.addContent(machineName);

		Element transactionid = new Element("TRANSACTIONID");
		transactionid.setText(oriheader.getChildText("TRANSACTIONID"));
		header.addContent(transactionid);

		Element originalSourceSubjectName = new Element(
				"ORIGINALSOURCESUBJECTNAME");
		originalSourceSubjectName.setText(oriheader
				.getChildText("ORIGINALSOURCESUBJECTNAME"));
		header.addContent(originalSourceSubjectName);

		Element sourceSubjectName = new Element("SOURCESUBJECTNAME");
		sourceSubjectName.setText(oriheader.getChildText("SOURCESUBJECTNAME"));
		header.addContent(sourceSubjectName);

		Element targetSubjectName = new Element("TARGETSUBJECTNAME");
		targetSubjectName.setText(oriheader.getChildText("TARGETSUBJECTNAME"));
		header.addContent(targetSubjectName);

		Element eventUser = new Element("EVENTUSER");
		eventUser.setText(oriheader.getChildText("EVENTUSER"));
		header.addContent(eventUser);

		Element eventComment = new Element("EVENTCOMMENT");
		eventComment.setText(oriheader.getChildText("EVENTCOMMENT"));
		header.addContent(eventComment);

		message.addContent(header);

		if (body != null) {
			message.addContent(body);
		}

		Element returnElement = new Element("Return");

		Element returnCode = new Element("RETURNCODE");
		returnCode.setText(returnCodeT);
		returnElement.addContent(returnCode);

		Element returnMessage = new Element("RETURNMESSAGE");
		returnMessage.setText(returnMsg);
		returnElement.addContent(returnMessage);

		message.addContent(returnElement);

		//
		Document replyDoc = new Document(message);

		sReplyMsg = JdomUtils.toString(replyDoc);

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).reply(replySubject, sReplyMsg);

		log.info(" SEND : Subject=" + replySubject);
		log.info(" SEND : Message=" + sReplyMsg);

		return replyDoc;
	}

	/*
	 * Name : sendBySender Desc : This function is Create XML Add ReturnCode,
	 * ReturnMessage. IDM API reply Author : ZXY Systems, Inc Date : 2013.03.04
	 */
	public static Document sendErrorBySenderReturnMessage(String replySubject, Document doc, Element element, String senderName, String returnCodeT, String returnMsg) throws Exception
	{
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			log.debug("senderName = " + senderName);
		}

		String sReplyMsg = null;

		Element message = new Element(SMessageUtil.Message_Tag);

		Element oriheader = doc.getDocument().getRootElement().getChild("Header");

		Element header = new Element("Header");

		Element messagename = new Element("MESSAGENAME");
		messagename.setText(oriheader.getChildText("MESSAGENAME"));
		header.addContent(messagename);

		Element shopName = new Element("SHOPNAME");
		shopName.setText(oriheader.getChildText("SHOPNAME"));
		header.addContent(shopName);

		Element machineName = new Element("MACHINENAME");
		machineName.setText(oriheader.getChildText("MACHINENAME"));
		header.addContent(machineName);

		Element transactionid = new Element("TRANSACTIONID");
		transactionid.setText(oriheader.getChildText("TRANSACTIONID"));
		header.addContent(transactionid);

		Element originalSourceSubjectName = new Element("ORIGINALSOURCESUBJECTNAME");
		originalSourceSubjectName.setText(oriheader.getChildText("ORIGINALSOURCESUBJECTNAME"));
		header.addContent(originalSourceSubjectName);

		Element sourceSubjectName = new Element("SOURCESUBJECTNAME");
		sourceSubjectName.setText(oriheader.getChildText("SOURCESUBJECTNAME"));
		header.addContent(sourceSubjectName);

		Element targetSubjectName = new Element("TARGETSUBJECTNAME");
		targetSubjectName.setText(oriheader.getChildText("TARGETSUBJECTNAME"));
		header.addContent(targetSubjectName);

		Element eventUser = new Element("EVENTUSER");
		eventUser.setText(oriheader.getChildText("EVENTUSER"));
		header.addContent(eventUser);

		Element eventComment = new Element("EVENTCOMMENT");
		eventComment.setText(oriheader.getChildText("EVENTCOMMENT"));
		header.addContent(eventComment);

		message.addContent(header);

		if (element != null) {
			message.addContent(element);
		}

		Element returnElement = new Element("Return");

		Element returnCode = new Element("RETURNCODE");
		returnCode.setText(returnCodeT);
		returnElement.addContent(returnCode);

		Element returnMessage = new Element("RETURNMESSAGE");
		returnMessage.setText(returnMsg);
		returnElement.addContent(returnMessage);

		message.addContent(returnElement);

		//
		Document replyDoc = new Document(message);

		sReplyMsg = JdomUtils.toString(replyDoc);

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).reply(replySubject, sReplyMsg);

		log.debug(" SEND : Subject=" + replySubject);
		log.info(" SEND : Message=" + sReplyMsg);

		return replyDoc;
	}

	/*
	 * Name : send Desc : This function is IDM API reply Author : ZXY Systems,
	 * Inc Date : 2013.03.04
	 */
	public void send(String beanName, String subject, Document doc) {
		if (log.isInfoEnabled()) {
			log.debug("beanName = " + beanName);
			log.debug("subject = " + subject);
		}

		String sendMsg = doc.toString();
		IRequester requester = (IRequester) this.applicationContext
				.getBean(beanName);
		requester.send(subject, doc.toString());

		log.debug(" SEND : Subject=" + subject);
		log.debug(" SEND : Message=" + sendMsg);

	}

	/*
	 * Name : sendReply Desc : This function is IDM API reply Author : ZXY
	 * Systems, Inc Date : 2013.03.04
	 */
	public void sendReply(String replySubject) {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
		}

		String sReplyMsg = SMessageUtil.replyXMLMessage(SUCCESS);

		IDMFrameServiceProxy.getGenericSender().setDataField(SMessageUtil.DataFieldName);
		IDMFrameServiceProxy.getGenericSender().reply(replySubject, sReplyMsg);

		String svrName = System.getProperty("svr");
		if(StringUtils.contains(GenericServiceProxy.getConstantMap().RECORD_MESSAGE_LOG_BY_SERVER, svrName)){
			log.info(" SERP : Subject=" + replySubject);
			log.info(" SERP : Message=" + sReplyMsg);
		}else{
			log.debug(" SERP : Subject=" + replySubject);
			log.debug(" SERP : Message=" + sReplyMsg);
		}
	}

	/*
	 * Name : sendReplyBySender Desc : This function is IDM API reply Author :
	 * ZXY Systems, Inc Date : 2013.03.04
	 */
	public void sendReplyBySender(String replySubject, String senderName) {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			log.debug("senderName = " + senderName);
		}

		String sReplyMsg = SMessageUtil.replyXMLMessage(SUCCESS);

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).reply(replySubject, sReplyMsg);

		log.debug(" SERP : Subject=" + replySubject);
		log.debug(" SERP : Message=" + sReplyMsg);
	}

	/*
	 * Name : sendReply Desc : This function is IDM API reply Author : ZXY
	 * Systems, Inc Date : 2013.03.04
	 */
	public void sendReply(String replySubject, String sReplyMsg) {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			log.debug("sReplyMsg = " + sReplyMsg);
		}

		IDMFrameServiceProxy.getGenericSender().setDataField(SMessageUtil.DataFieldName);
		IDMFrameServiceProxy.getGenericSender().reply(replySubject, sReplyMsg);

		log.debug(" SERP : Subject=" + replySubject);
		log.debug(" SERP : Message=" + sReplyMsg);
	}

	/*
	 * Name : sendReplyBySender Desc : This function is IDM API reply Author :
	 * ZXY Systems, Inc Date : 2013.03.04
	 */
	public void sendReplyBySender(String replySubject, String sReplyMsg,String senderName) {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			// log.debug("sReplyMsg = " + sReplyMsg);
			log.debug("senderName = " + senderName);
		}

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).reply(replySubject, sReplyMsg);

		log.debug(" SERP : Subject=" + replySubject);
		log.debug(" SERP : Message=" + sReplyMsg);
	}

	/*
	 * Name : sendReply Desc : This function is IDM API reply Author : ZXY
	 * Systems, Inc Date : 2013.03.04
	 */
	public void sendReply(String replySubject, Document doc, Element element)
			throws Exception {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
		}

		String sReplyMsg = null;
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ReturnCode,
				SUCCESS);
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ErrorMessage,
				"");
		String XPathResult = "//" + SMessageUtil.Message_Tag + "/"
				+ SMessageUtil.Result_Name_Tag;

		if (element != null) {
			JdomUtils.getNode(doc, XPathResult).addContent(element);
		}

		sReplyMsg = JdomUtils.toString(doc);

		IDMFrameServiceProxy.getGenericSender().setDataField(SMessageUtil.DataFieldName);
		IDMFrameServiceProxy.getGenericSender().reply(replySubject, sReplyMsg);

		String svrName = System.getProperty("svr");
		if(StringUtils.contains(GenericServiceProxy.getConstantMap().RECORD_MESSAGE_LOG_BY_SERVER, svrName)){
			log.info(" SERP : Subject=" + replySubject);
			log.info(" SERP : Message=" + sReplyMsg);
		}else{
			log.debug(" SERP : Subject=" + replySubject);
			log.debug(" SERP : Message=" + sReplyMsg);
		}
	}

	/*
	 * Name : sendReplyBySender
	 * Desc : This function is IDM API reply
	 * Author : ZXY Systems, Inc
	 * Date : 2014.12.04
	 */
	public void sendReplyBySender(String replySubject, Document doc, Element element, String senderName) throws Exception
	{
		if (log.isInfoEnabled()) {
			log.info("replySubject = " + replySubject);
			log.info("senderName = " + senderName);
		}

		String sReplyMsg = null;
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ReturnCode, SUCCESS);
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ErrorMessage, "");
		String XPathResult = "//" + SMessageUtil.Message_Tag + "/" + SMessageUtil.Body_Tag;

		if (element != null) {
			JdomUtils.getNode(doc, XPathResult).addContent(element);
		}

		sReplyMsg = JdomUtils.toString(doc);

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).reply(replySubject, sReplyMsg);

		String svrName = System.getProperty("svr");
		if(StringUtils.contains(GenericServiceProxy.getConstantMap().RECORD_MESSAGE_LOG_BY_SERVER, svrName)){
			log.info(" SERP : Subject=" + replySubject);
			log.info(" SERP : Message=" + sReplyMsg);
		}else{
			log.info(" SERP : Subject=" + replySubject);

			if(StringUtils.equals(senderName, "FMCSender"))
			{
				log.debug(" SERP : Message=" + sReplyMsg);
			}
			else
			{
				log.info(" SERP : Message=" + sReplyMsg);
			}
		}
	}

	/*
	 * Name : sendReasonCodeReplyBySender Desc : This function is
	 * sendReasonCodeReplyBySender IDM API reply Author : ZXY Systems, Inc Date
	 * : 2013.04.17
	 */
	public void sendReasonCodeReplyBySender(String replySubject, Document doc,
			Element element, String senderName, EventInfo eventInfo) 
			throws Exception {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			log.debug("senderName = " + senderName);
		}

		String sReplyMsg = null;

		// ReturnCode is any other values, except by "0"
		// ErrorMessage is EventComment
		if (!StringUtils.equals(eventInfo.getReasonCode().toString(), SUCCESS)) {
			SMessageUtil.setResultItemValue(doc,
					SMessageUtil.Result_ReturnCode, eventInfo.getReasonCode()
							.toString());
			SMessageUtil.setResultItemValue(doc,
					SMessageUtil.Result_ErrorMessage, eventInfo
							.getEventComment().toString());
		}
		// ReturnCode is "0"
		else {
			SMessageUtil.setResultItemValue(doc,
					SMessageUtil.Result_ReturnCode, SUCCESS);
			SMessageUtil.setResultItemValue(doc,
					SMessageUtil.Result_ErrorMessage, "");
		}

		String XPathResult = "//" + SMessageUtil.Message_Tag + "/"
				+ SMessageUtil.Body_Tag;

		if (element != null) {
			JdomUtils.getNode(doc, XPathResult).addContent(element);
		}

		sReplyMsg = JdomUtils.toString(doc);

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).reply(replySubject, sReplyMsg);

		log.info(" SERP : Subject=" + replySubject);
		log.info(" SERP : Message=" + sReplyMsg);
	}

	/*
	 * Name : sendReplyBodyChange Desc : This function is sendReplyBodyChange
	 * IDM API reply Author : ZXY Systems, Inc Date : 2013.04.17
	 */
	public void sendReplyBodyChange(String replySubject, Document doc,
			Element element) throws Exception {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
		}

		String replyMsg = null;
		String sReplyMsg = null;
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ReturnCode,
				SUCCESS);
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ErrorMessage,
				"");
		String XPathResult = "//" + SMessageUtil.Message_Tag + "/"
				+ SMessageUtil.Result_Name_Tag;

		if (element != null) {
			Element srcBody = JdomUtils.getNode(doc, "//"
					+ SMessageUtil.Message_Tag + "/" + SMessageUtil.Body_Tag);
			srcBody.removeContent();
			srcBody.addContent(element);
		}

		sReplyMsg = JdomUtils.toString(doc);

		IDMFrameServiceProxy.getGenericSender().setDataField(SMessageUtil.DataFieldName);
		IDMFrameServiceProxy.getGenericSender().reply(replySubject, sReplyMsg);

		String svrName = System.getProperty("svr");
		if(StringUtils.contains(GenericServiceProxy.getConstantMap().RECORD_MESSAGE_LOG_BY_SERVER, svrName)){
			log.info(" SERP : Subject=" + replySubject);
			log.info(" SERP : Message=" + sReplyMsg);
		}else{
			log.debug(" SERP : Subject=" + replySubject);
			log.debug(" SERP : Message=" + sReplyMsg);
		}
	}

	/*
	 * Name : sendBodyChangeBySender Desc : This function is
	 * sendBodyChangeBySender IDM API reply Author : ZXY Systems, Inc Date :
	 * 2013.04.17
	 */
	public void sendBodyChangeBySender(String replySubject, Document doc,
			Element element, String senderName) throws Exception {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			log.debug("senderName = " + senderName);
		}

		if (element != null) {
			Element message = JdomUtils.getNode(doc, "//"
					+ SMessageUtil.Message_Tag);
			Element srcBody = JdomUtils.getNode(doc, "//"
					+ SMessageUtil.Message_Tag + "/" + SMessageUtil.Body_Tag);
			// srcBody.detach();
			srcBody.removeContent();
			message.addContent(element);
		}

		String sReplyMsg = null;
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ReturnCode,
				SUCCESS);
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ErrorMessage,
				"");

		sReplyMsg = JdomUtils.toString(doc);

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).reply(replySubject, sReplyMsg);

		log.debug(" SERP : Subject=" + replySubject);
		log.debug(" SERP : Message=" + sReplyMsg);
	}

	/*
	 * Name : sendReplyBodyChangeBySender Desc : This function is
	 * sendReplyBodyChangeBySender IDM API reply Author : ZXY Systems, Inc Date
	 * : 2013.04.17
	 */
	public void sendReplyBodyChangeBySender(String replySubject, Document doc,
			Element element, String senderName) throws Exception {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			log.debug("senderName = " + senderName);
		}

		String replyMsg = null;
		String sReplyMsg = null;
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ReturnCode,
				SUCCESS);
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ErrorMessage,
				"");
		String XPathResult = "//" + SMessageUtil.Message_Tag + "/"
				+ SMessageUtil.Result_Name_Tag;

		if (element != null) {
			Element srcBody = JdomUtils.getNode(doc, "//"
					+ SMessageUtil.Message_Tag + "/" + SMessageUtil.Body_Tag);
			srcBody.removeContent();
			srcBody.addContent(element);
		}

		sReplyMsg = JdomUtils.toString(doc);

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).reply(replySubject, sReplyMsg);

		String svrName = System.getProperty("svr");
		if(StringUtils.contains(GenericServiceProxy.getConstantMap().RECORD_MESSAGE_LOG_BY_SERVER, svrName)){
			log.info(" SERP : Subject=" + replySubject);
			log.info(" SERP : Message=" + sReplyMsg);
		}else{
			log.debug(" SERP : Subject=" + replySubject);
			log.debug(" SERP : Message=" + sReplyMsg);
		}
	}

	/*
	 * Name : sendReply Desc : This function is Add XML Return IDM API reply
	 * Author : ZXY Systems, Inc Date : 2013.04.17
	 */
	public void sendReply(String replySubject, Document doc) {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
		}

		String sReplyMsg = null;
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ReturnCode,
				SUCCESS);
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ErrorMessage,
				"");

		sReplyMsg = JdomUtils.toString(doc);

		IDMFrameServiceProxy.getGenericSender().setDataField(SMessageUtil.DataFieldName);
		IDMFrameServiceProxy.getGenericSender().reply(replySubject, sReplyMsg);

		String svrName = System.getProperty("svr");
		if(StringUtils.contains(GenericServiceProxy.getConstantMap().RECORD_MESSAGE_LOG_BY_SERVER, svrName)){
			log.info(" SERP : Subject=" + replySubject);
			log.info(" SERP : Message=" + sReplyMsg);
		}else{
			log.debug(" SERP : Subject=" + replySubject);
			log.debug(" SERP : Message=" + sReplyMsg);
		}
	}

	/*
	 * Name : sendReplyBySender Desc : This function is Add XML Return IDM API
	 * reply Author : ZXY Systems, Inc Date : 2013.04.17
	 */
	public void sendReplyBySender(String replySubject, Document doc,
			String senderName) {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			log.debug("senderName = " + senderName);
		}

		String sReplyMsg = null;
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ReturnCode,
				SUCCESS);
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ErrorMessage,
				"");

		sReplyMsg = JdomUtils.toString(doc);

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).reply(replySubject, sReplyMsg);

		log.info(" SERP : Subject=" + replySubject);
		log.info(" SERP : Message=" + sReplyMsg);
	}

	/*
	 * Name : sendReplyByOIC Desc : This function is Add XML Return IDM API
	 * reply Author : ZXY Systems, Inc Date : 2013.04.17
	 */
	public void sendReplyByOIC(String replySubject, Document doc,
			String senderName) {
		if (replySubject.length() > 6) {
			if (StringUtils.equals(replySubject.substring(0, 6), "_INBOX")) {
				if (log.isInfoEnabled()) {
					log.debug("replySubject = " + replySubject);
					log.debug("senderName = " + senderName);
				}

				String sReplyMsg = null;
				SMessageUtil.setResultItemValue(doc,
						SMessageUtil.Result_ReturnCode, SUCCESS);
				SMessageUtil.setResultItemValue(doc,
						SMessageUtil.Result_ErrorMessage, "");

				sReplyMsg = JdomUtils.toString(doc);

				GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
				GenericServiceProxy.getGenericSender(senderName).reply(replySubject, sReplyMsg);

				String svrName = System.getProperty("svr");
				if(StringUtils.contains(GenericServiceProxy.getConstantMap().RECORD_MESSAGE_LOG_BY_SERVER, svrName)){
					log.info(" SERP : Subject=" + replySubject);
					log.info(" SERP : Message=" + sReplyMsg);
				}else{
					log.debug(" SERP : Subject=" + replySubject);
					log.debug(" SERP : Message=" + sReplyMsg);
				}
			}
		}
	}

	/*
	 * Name : sendReplyBySenderWithoutLog Desc : This function is
	 * sendReplyBySenderWithoutLog Add XML Return IDM API reply Author : ZXY
	 * Systems, Inc Date : 2013.04.17
	 */
	public void sendReplyBySenderWithoutLog(String replySubject, Document doc,
			String senderName) {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			log.debug("senderName = " + senderName);
		}

		String sReplyMsg = null;
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ReturnCode,
				SUCCESS);
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ErrorMessage,
				"");

		sReplyMsg = JdomUtils.toString(doc);

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).reply(replySubject, sReplyMsg);

		String svrName = System.getProperty("svr");
		if(StringUtils.contains(GenericServiceProxy.getConstantMap().RECORD_MESSAGE_LOG_BY_SERVER, svrName)){
			log.info(" SERP : Subject=" + replySubject);
			log.info(" SERP : Message=" + sReplyMsg);
		}else{
			log.debug(" SERP : Subject=" + replySubject);
		}
	}

	/*
	 * Name : sendReplyMessageBySender Desc : This function is
	 * sendReplyMessageBySender Add XML Return IDM API reply Author : ZXY
	 * Systems, Inc Date : 2013.04.17
	 */
	public void sendReplyMessageBySender(String replySubject, Document doc,
			String senderName) {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			log.debug("senderName = " + senderName);
		}

		String sReplyMsg = null;

		// SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ReturnCode,
		// SUCCESS);
		// SMessageUtil.setResultItemValue(doc,
		// SMessageUtil.Result_ErrorMessage, "");
		sReplyMsg = JdomUtils.toString(doc);

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).reply(replySubject, sReplyMsg);

		String svrName = System.getProperty("svr");
		if(StringUtils.contains(GenericServiceProxy.getConstantMap().RECORD_MESSAGE_LOG_BY_SERVER, svrName)){
			log.info(" SERP : Subject=" + replySubject);
			log.info(" SERP : Message=" + sReplyMsg);
		}else{
			log.debug(" SERP : Subject=" + replySubject);
			log.debug(" SERP : Message=" + sReplyMsg);
		}
	}

	/*
	 * Name : sendReplyMessage Desc : This function is sendReplyMessage Add XML
	 * Return IDM API reply Author : ZXY Systems, Inc Date : 2013.04.17
	 */
	public void sendReplyMessage(String replySubject, Document doc) {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
		}

		String sReplyMsg = null;
		// SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ReturnCode,
		// SUCCESS);
		// SMessageUtil.setResultItemValue(doc,
		// SMessageUtil.Result_ErrorMessage, "");

		sReplyMsg = JdomUtils.toString(doc);

		IDMFrameServiceProxy.getGenericSender().setDataField(SMessageUtil.DataFieldName);
		IDMFrameServiceProxy.getGenericSender().reply(replySubject, sReplyMsg);

		String svrName = System.getProperty("svr");
		if(StringUtils.contains(GenericServiceProxy.getConstantMap().RECORD_MESSAGE_LOG_BY_SERVER, svrName)){
			log.info(" SERP : Subject=" + replySubject);
			log.info(" SERP : Message=" + sReplyMsg);
		}else{
			log.debug(" SERP : Subject=" + replySubject);
			log.debug(" SERP : Message=" + sReplyMsg);
		}
	}

	/*
	 * Name : sendError Desc : This function is sendError Author : ZXY Systems,
	 * Inc Date : 2013.04.17
	 */
	public void sendError(String replySubject, Document doc, String lanuage,
			CustomException e) {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			// log.debug("lanuage = " + lanuage);
		}

		Exception e2 = (Exception) e;
		sendError(replySubject, doc, lanuage, e2);
	}

	/*
	 * Name : sendErrorBySender Desc : This function is sendErrorBySender Author
	 * : ZXY Systems, Inc Date : 2013.04.17
	 */
	public void sendErrorBySender(String replySubject, Document doc,
			String lanuage, CustomException e, String senderName) {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			// log.debug("lanuage = " + lanuage);
			log.debug("senderName = " + senderName);
		}

		Exception e2 = (Exception) e;
		sendErrorBySender(replySubject, doc, lanuage, e2, senderName);
	}

	/*
	 * Name : sendError Desc : This function is sendErsendErrorrorBySender
	 * Author : ZXY Systems, Inc Date : 2013.04.17
	 */
	public void sendError(String replySubject, Document doc, String lanuage,
			Exception e) {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			// log.debug("lanuage = " + lanuage);
		}

		if (e instanceof BpelException) {
			e = ((BpelException) e).getNativeException();
		}
		String sReplyMsg = this.makeSendError(replySubject, doc, lanuage, e);

		IDMFrameServiceProxy.getGenericSender().setDataField(SMessageUtil.DataFieldName);
		if (StringUtils.isNotEmpty(replySubject) == true)
			IDMFrameServiceProxy.getGenericSender().reply(replySubject, sReplyMsg);

		log.error(" SERP : Subject=" + replySubject);
		log.error(" SERP : Message=" + sReplyMsg);
	}

	/*
	 * Name : makeSendError Desc : This function is makeSendError Author : ZXY
	 * Systems, Inc Date : 2013.04.17
	 */
	private String makeSendError(String replySubject, Document doc,
			String lanuage, Exception e) {

		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			// log.debug("lanuage = " + lanuage);
		}

		String errorCode = "";
		String korErrorMsg = "";
		String engErrorMsg = "";
		String chaErrorMsg = "";
		String locErrorMsg = "";

		// Throwable orgEx = (BpelException)e;
		Throwable orgEx = e;

		Throwable targetEx;
		if (orgEx.getCause() instanceof InvocationTargetException)
			targetEx = ((InvocationTargetException) orgEx.getCause())
					.getTargetException();
		else if (orgEx.getCause() instanceof CustomException)
			targetEx = ((CustomException) orgEx.getCause());
		else if (orgEx.getCause() instanceof NotFoundSignal)
			targetEx = ((NotFoundSignal) orgEx.getCause());
		else if (orgEx.getCause() instanceof DuplicateNameSignal)
			targetEx = ((DuplicateNameSignal) orgEx.getCause());
		else if (orgEx.getCause() instanceof FrameworkErrorSignal)
			targetEx = ((FrameworkErrorSignal) orgEx.getCause());
		else if (orgEx.getCause() instanceof InvalidStateTransitionSignal)
			targetEx = ((InvalidStateTransitionSignal) orgEx.getCause());
		else if (orgEx.getCause() instanceof IDMFrameErrorSignal)
			targetEx = ((IDMFrameErrorSignal) orgEx.getCause());
		else
			targetEx = orgEx;
		


		


		// 2014.01.02
		targetEx = getThrowable(targetEx);
		targetEx = getThrowable(targetEx);
		targetEx = getThrowable(targetEx);
		targetEx = getThrowable(targetEx);
		targetEx = getThrowable(targetEx);
		
		

		if (targetEx instanceof NotFoundSignal) {
			errorCode = "NotFoundSignal";
			ErrorDef errorDef = GenericServiceProxy.getErrorDefMap()
					.getErrorDef(errorCode);

			korErrorMsg = MessageFormat.format(errorDef.getKor_errorMessage(),
					((NotFoundSignal) targetEx).getErrorCode(),
					((NotFoundSignal) targetEx).getMessage());
			engErrorMsg = MessageFormat.format(errorDef.getEng_errorMessage(),
					((NotFoundSignal) targetEx).getErrorCode(),
					((NotFoundSignal) targetEx).getMessage());
			chaErrorMsg = MessageFormat.format(errorDef.getCha_errorMessage(),
					((NotFoundSignal) targetEx).getErrorCode(),
					((NotFoundSignal) targetEx).getMessage());
			locErrorMsg = MessageFormat.format(errorDef.getLoc_errorMessage(),
					((NotFoundSignal) targetEx).getErrorCode(),
					((NotFoundSignal) targetEx).getMessage());

		} else if (targetEx instanceof DuplicateNameSignal) {
			errorCode = "DuplicateNameSignal";
			ErrorDef errorDef = GenericServiceProxy.getErrorDefMap()
					.getErrorDef(errorCode);

			korErrorMsg = MessageFormat.format(errorDef.getKor_errorMessage(),
					((DuplicateNameSignal) targetEx).getErrorCode(),
					((DuplicateNameSignal) targetEx).getMessage());
			engErrorMsg = MessageFormat.format(errorDef.getEng_errorMessage(),
					((DuplicateNameSignal) targetEx).getErrorCode(),
					((DuplicateNameSignal) targetEx).getMessage());
			chaErrorMsg = MessageFormat.format(errorDef.getCha_errorMessage(),
					((DuplicateNameSignal) targetEx).getErrorCode(),
					((DuplicateNameSignal) targetEx).getMessage());
			locErrorMsg = MessageFormat.format(errorDef.getLoc_errorMessage(),
					((DuplicateNameSignal) targetEx).getErrorCode(),
					((DuplicateNameSignal) targetEx).getMessage());
		} else if (targetEx instanceof FrameworkErrorSignal) {
			errorCode = "FrameworkErrorSignal";
			ErrorDef errorDef = GenericServiceProxy.getErrorDefMap()
					.getErrorDef(errorCode);

			korErrorMsg = MessageFormat.format(errorDef.getKor_errorMessage(),
					((FrameworkErrorSignal) targetEx).getErrorCode(),
					((FrameworkErrorSignal) targetEx).getMessage());
			engErrorMsg = MessageFormat.format(errorDef.getEng_errorMessage(),
					((FrameworkErrorSignal) targetEx).getErrorCode(),
					((FrameworkErrorSignal) targetEx).getMessage());
			chaErrorMsg = MessageFormat.format(errorDef.getCha_errorMessage(),
					((FrameworkErrorSignal) targetEx).getErrorCode(),
					((FrameworkErrorSignal) targetEx).getMessage());
			locErrorMsg = MessageFormat.format(errorDef.getLoc_errorMessage(),
					((FrameworkErrorSignal) targetEx).getErrorCode(),
					((FrameworkErrorSignal) targetEx).getMessage());
		} else if (targetEx instanceof InvalidStateTransitionSignal) {
			errorCode = "InvalidStateTransitionSignal";
			ErrorDef errorDef = GenericServiceProxy.getErrorDefMap()
					.getErrorDef(errorCode);

			korErrorMsg = MessageFormat.format(errorDef.getKor_errorMessage(),
					((InvalidStateTransitionSignal) targetEx).getErrorCode(),
					((InvalidStateTransitionSignal) targetEx).getMessage());
			engErrorMsg = MessageFormat.format(errorDef.getEng_errorMessage(),
					((InvalidStateTransitionSignal) targetEx).getErrorCode(),
					((InvalidStateTransitionSignal) targetEx).getMessage());
			chaErrorMsg = MessageFormat.format(errorDef.getCha_errorMessage(),
					((InvalidStateTransitionSignal) targetEx).getErrorCode(),
					((InvalidStateTransitionSignal) targetEx).getMessage());
			locErrorMsg = MessageFormat.format(errorDef.getLoc_errorMessage(),
					((InvalidStateTransitionSignal) targetEx).getErrorCode(),
					((InvalidStateTransitionSignal) targetEx).getMessage());
		} else if (targetEx instanceof CustomException) {
			errorCode = ((CustomException) targetEx).errorDef.getErrorCode();
			ErrorDef errorDef = ((CustomException) targetEx).errorDef;

			korErrorMsg = errorDef.getKor_errorMessage();
			engErrorMsg = errorDef.getEng_errorMessage();
			chaErrorMsg = errorDef.getCha_errorMessage();
			locErrorMsg = errorDef.getLoc_errorMessage();
		} else if (targetEx instanceof IDMFrameErrorSignal) {
			errorCode = "IDMFrameErrorSignal";
			ErrorDef errorDef = GenericServiceProxy.getErrorDefMap()
					.getErrorDef(errorCode);

			korErrorMsg = MessageFormat.format(errorDef.getKor_errorMessage(),
					((IDMFrameErrorSignal) targetEx).getErrorCode(),
					((IDMFrameErrorSignal) targetEx).getMessage());
			engErrorMsg = MessageFormat.format(errorDef.getEng_errorMessage(),
					((IDMFrameErrorSignal) targetEx).getErrorCode(),
					((IDMFrameErrorSignal) targetEx).getMessage());
			chaErrorMsg = MessageFormat.format(errorDef.getCha_errorMessage(),
					((IDMFrameErrorSignal) targetEx).getErrorCode(),
					((IDMFrameErrorSignal) targetEx).getMessage());
			locErrorMsg = MessageFormat.format(errorDef.getLoc_errorMessage(),
					((IDMFrameErrorSignal) targetEx).getErrorCode(),
					((IDMFrameErrorSignal) targetEx).getMessage());

		} else {
			errorCode = "UndefinedCode";
			ErrorDef errorDef = GenericServiceProxy.getErrorDefMap()
					.getErrorDef("UndefinedCode");

			korErrorMsg = MessageFormat.format(errorDef.getKor_errorMessage(),
					targetEx.getMessage());
			engErrorMsg = MessageFormat.format(errorDef.getEng_errorMessage(),
					targetEx.getMessage());
			chaErrorMsg = MessageFormat.format(errorDef.getCha_errorMessage(),
					targetEx.getMessage());
			locErrorMsg = MessageFormat.format(errorDef.getLoc_errorMessage(),
					targetEx.getMessage());
		}

		String sReplyMsg = null;
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ReturnCode,
				errorCode);

		if (lanuage.equals("KOR") == true)
			SMessageUtil.setResultItemValue(doc,
					SMessageUtil.Result_ErrorMessage, korErrorMsg);
		else if (lanuage.equals("ENG") == true
				|| lanuage.toUpperCase().equals("ENGLISH") == true)
			SMessageUtil.setResultItemValue(doc,
					SMessageUtil.Result_ErrorMessage, engErrorMsg);
		else if (lanuage.equals("CHA") == true
				|| lanuage.toUpperCase().equals("CHINESE") == true)
			SMessageUtil.setResultItemValue(doc,
					SMessageUtil.Result_ErrorMessage, chaErrorMsg);
		else
			SMessageUtil.setResultItemValue(doc,
					SMessageUtil.Result_ErrorMessage, locErrorMsg);

		sReplyMsg = JdomUtils.toString(doc);

		return sReplyMsg;
	}

	/*
	 * Name : sendErrorBySender Desc : This function is sendErrorBySender IDM
	 * API reply Author : ZXY Systems, Inc Date : 2013.04.17
	 */
	public void sendErrorBySender(String replySubject, Document doc,
			String lanuage, Exception e, String senderName) {
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			// log.debug("lanuage = " + lanuage);
			log.debug("senderName = " + senderName);
		}

		if (e instanceof BpelException) {
			e = ((BpelException) e).getNativeException();
		}
		String sReplyMsg = this.makeSendError(replySubject, doc, lanuage, e);

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		if (StringUtils.isNotEmpty(replySubject) == true)
			GenericServiceProxy.getGenericSender(senderName).reply(replySubject, sReplyMsg);

		log.error(" SERP : Subject=" + replySubject);
		log.error(" SERP : Message=" + sReplyMsg);
	}
	
	public void sendErrorBySenderNoReplySubject( Document doc,
			String lanuage, Exception e, String senderName) {

		if (e instanceof BpelException) {
			e = ((BpelException) e).getNativeException();
		}
		String sReplyMsg = this.makeSendError("", doc, lanuage, e);

		GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		GenericServiceProxy.getGenericSender(senderName).send(sReplyMsg);
			
		log.error(" SERP : Subject=" + senderName);
		log.error(" SERP : Message=" + sReplyMsg);
	}


	/*
	 * Name : makeErrorMessageLog Desc : This function is makeErrorMessageLog
	 * Author : ZXY Systems, Inc Date : 2013.03.17
	 */
	public String makeErrorMessageLog(Document doc, Exception e, String language) {
		if (e == null)
			return null;
		
		String errorCode = "";
		String korErrorMsg = "";
		String engErrorMsg = "";
		String chaErrorMsg = "";
		String locErrorMsg = "";

		Throwable orgEx = e;
		Throwable targetEx;
		
		if (orgEx.getCause() != null && orgEx.getCause() instanceof InvocationTargetException)
			targetEx = ((InvocationTargetException) orgEx.getCause()).getTargetException();
		else if (orgEx.getCause() != null)
			targetEx = orgEx.getCause();
		else
			targetEx = orgEx;
		
//		if (orgEx.getCause() instanceof InvocationTargetException)
//			targetEx = ((InvocationTargetException) orgEx.getCause())
//					.getTargetException();
//		else if (orgEx.getCause() instanceof CustomException)
//			targetEx = ((CustomException) orgEx.getCause());
//		else if (orgEx.getCause() instanceof NotFoundSignal)
//			targetEx = ((NotFoundSignal) orgEx.getCause());
//		else if (orgEx.getCause() instanceof DuplicateNameSignal)
//			targetEx = ((DuplicateNameSignal) orgEx.getCause());
//		else if (orgEx.getCause() instanceof FrameworkErrorSignal)
//			targetEx = ((FrameworkErrorSignal) orgEx.getCause());
//		else if (orgEx.getCause() instanceof InvalidStateTransitionSignal)
//			targetEx = ((InvalidStateTransitionSignal) orgEx.getCause());
//		else if (orgEx.getCause() instanceof IDMFrameErrorSignal)
//			targetEx = ((IDMFrameErrorSignal) orgEx.getCause());
//		else
//			targetEx = orgEx;

		// 2014.01.02
		targetEx = getThrowable(targetEx);
		
		if (targetEx instanceof NotFoundSignal) {
			errorCode = "NotFoundSignal";
			ErrorDef errorDef = GenericServiceProxy.getErrorDefMap()
					.getErrorDef(errorCode);

			korErrorMsg = MessageFormat.format(errorDef.getKor_errorMessage(),
					((NotFoundSignal) targetEx).getErrorCode(),
					((NotFoundSignal) targetEx).getMessage());
			engErrorMsg = MessageFormat.format(errorDef.getEng_errorMessage(),
					((NotFoundSignal) targetEx).getErrorCode(),
					((NotFoundSignal) targetEx).getMessage());
			chaErrorMsg = MessageFormat.format(errorDef.getCha_errorMessage(),
					((NotFoundSignal) targetEx).getErrorCode(),
					((NotFoundSignal) targetEx).getMessage());
			locErrorMsg = MessageFormat.format(errorDef.getLoc_errorMessage(),
					((NotFoundSignal) targetEx).getErrorCode(),
					((NotFoundSignal) targetEx).getMessage());

		} else if (targetEx instanceof DuplicateNameSignal) {
			errorCode = "DuplicateNameSignal";
			ErrorDef errorDef = GenericServiceProxy.getErrorDefMap()
					.getErrorDef(errorCode);

			korErrorMsg = MessageFormat.format(errorDef.getKor_errorMessage(),
					((DuplicateNameSignal) targetEx).getErrorCode(),
					((DuplicateNameSignal) targetEx).getMessage());
			engErrorMsg = MessageFormat.format(errorDef.getEng_errorMessage(),
					((DuplicateNameSignal) targetEx).getErrorCode(),
					((DuplicateNameSignal) targetEx).getMessage());
			chaErrorMsg = MessageFormat.format(errorDef.getCha_errorMessage(),
					((DuplicateNameSignal) targetEx).getErrorCode(),
					((DuplicateNameSignal) targetEx).getMessage());
			locErrorMsg = MessageFormat.format(errorDef.getLoc_errorMessage(),
					((DuplicateNameSignal) targetEx).getErrorCode(),
					((DuplicateNameSignal) targetEx).getMessage());
		} else if (targetEx instanceof FrameworkErrorSignal) {
			errorCode = "FrameworkErrorSignal";
			ErrorDef errorDef = GenericServiceProxy.getErrorDefMap()
					.getErrorDef(errorCode);

			korErrorMsg = MessageFormat.format(errorDef.getKor_errorMessage(),
					((FrameworkErrorSignal) targetEx).getErrorCode(),
					((FrameworkErrorSignal) targetEx).getMessage());
			engErrorMsg = MessageFormat.format(errorDef.getEng_errorMessage(),
					((FrameworkErrorSignal) targetEx).getErrorCode(),
					((FrameworkErrorSignal) targetEx).getMessage());
			chaErrorMsg = MessageFormat.format(errorDef.getCha_errorMessage(),
					((FrameworkErrorSignal) targetEx).getErrorCode(),
					((FrameworkErrorSignal) targetEx).getMessage());
			locErrorMsg = MessageFormat.format(errorDef.getLoc_errorMessage(),
					((FrameworkErrorSignal) targetEx).getErrorCode(),
					((FrameworkErrorSignal) targetEx).getMessage());
		} else if (targetEx instanceof InvalidStateTransitionSignal) {
			errorCode = "InvalidStateTransitionSignal";
			ErrorDef errorDef = GenericServiceProxy.getErrorDefMap()
					.getErrorDef(errorCode);

			korErrorMsg = MessageFormat.format(errorDef.getKor_errorMessage(),
					((InvalidStateTransitionSignal) targetEx).getErrorCode(),
					((InvalidStateTransitionSignal) targetEx).getMessage());
			engErrorMsg = MessageFormat.format(errorDef.getEng_errorMessage(),
					((InvalidStateTransitionSignal) targetEx).getErrorCode(),
					((InvalidStateTransitionSignal) targetEx).getMessage());
			chaErrorMsg = MessageFormat.format(errorDef.getCha_errorMessage(),
					((InvalidStateTransitionSignal) targetEx).getErrorCode(),
					((InvalidStateTransitionSignal) targetEx).getMessage());
			locErrorMsg = MessageFormat.format(errorDef.getLoc_errorMessage(),
					((InvalidStateTransitionSignal) targetEx).getErrorCode(),
					((InvalidStateTransitionSignal) targetEx).getMessage());
		} else if (targetEx instanceof CustomException) {
			errorCode = ((CustomException) targetEx).errorDef.getErrorCode();
			ErrorDef errorDef = ((CustomException) targetEx).errorDef;

			korErrorMsg = errorDef.getKor_errorMessage();
			engErrorMsg = errorDef.getEng_errorMessage();
			chaErrorMsg = errorDef.getCha_errorMessage();
			locErrorMsg = errorDef.getLoc_errorMessage();
		} else if (targetEx instanceof IDMFrameErrorSignal) {
			errorCode = "IDMFrameErrorSignal";
			ErrorDef errorDef = GenericServiceProxy.getErrorDefMap()
					.getErrorDef(errorCode);

			korErrorMsg = MessageFormat.format(errorDef.getKor_errorMessage(),
					((IDMFrameErrorSignal) targetEx).getErrorCode(),
					((IDMFrameErrorSignal) targetEx).getMessage());
			engErrorMsg = MessageFormat.format(errorDef.getEng_errorMessage(),
					((IDMFrameErrorSignal) targetEx).getErrorCode(),
					((IDMFrameErrorSignal) targetEx).getMessage());
			chaErrorMsg = MessageFormat.format(errorDef.getCha_errorMessage(),
					((IDMFrameErrorSignal) targetEx).getErrorCode(),
					((IDMFrameErrorSignal) targetEx).getMessage());
			locErrorMsg = MessageFormat.format(errorDef.getLoc_errorMessage(),
					((IDMFrameErrorSignal) targetEx).getErrorCode(),
					((IDMFrameErrorSignal) targetEx).getMessage());

		} else {
			errorCode = "UndefinedCode";
			ErrorDef errorDef = GenericServiceProxy.getErrorDefMap()
					.getErrorDef("UndefinedCode");

			korErrorMsg = MessageFormat.format(errorDef.getKor_errorMessage(),
					targetEx.getMessage());
			engErrorMsg = MessageFormat.format(errorDef.getEng_errorMessage(),
					targetEx.getMessage());
			chaErrorMsg = MessageFormat.format(errorDef.getCha_errorMessage(),
					targetEx.getMessage());
			locErrorMsg = MessageFormat.format(errorDef.getLoc_errorMessage(),
					targetEx.getMessage());
		}

		String sReplyMsg = null;
		SMessageUtil.setResultItemValue(doc, SMessageUtil.Result_ReturnCode,
				errorCode);

		if (language.equals("KOR") == true)
			SMessageUtil.setResultItemValue(doc,
					SMessageUtil.Result_ErrorMessage, korErrorMsg);
		else if (language.equals("ENG") == true)
			SMessageUtil.setResultItemValue(doc,
					SMessageUtil.Result_ErrorMessage, engErrorMsg);
		else if (language.equals("CHA") == true)
			SMessageUtil.setResultItemValue(doc,
					SMessageUtil.Result_ErrorMessage, chaErrorMsg);
		else
			SMessageUtil.setResultItemValue(doc,
					SMessageUtil.Result_ErrorMessage, locErrorMsg);

		sReplyMsg = JdomUtils.toString(doc);

		CommonUtil.insertErrorMessageLog(doc);

		return sReplyMsg;
	}
	
	private Throwable getThrowable(Throwable targetEx)
	{
		try
		{
			if (targetEx.getCause() instanceof InvocationTargetException)
			{
				if(((InvocationTargetException)targetEx.getCause()).getTargetException() != null)
				{
					Throwable invocationTargetEx = ((InvocationTargetException)targetEx.getCause()).getTargetException();
					
					if (invocationTargetEx instanceof CustomException)
						targetEx = ((CustomException) invocationTargetEx);
					else if (invocationTargetEx instanceof NotFoundSignal)
						targetEx = ((NotFoundSignal) invocationTargetEx);
					else if (invocationTargetEx instanceof DuplicateNameSignal)
						targetEx = ((DuplicateNameSignal) invocationTargetEx);
					else if (invocationTargetEx instanceof FrameworkErrorSignal)
						targetEx = ((FrameworkErrorSignal) invocationTargetEx);
					else if (invocationTargetEx instanceof InvalidStateTransitionSignal)
						targetEx = ((InvalidStateTransitionSignal) invocationTargetEx);
					else if (invocationTargetEx instanceof IDMFrameErrorSignal)
						targetEx = ((IDMFrameErrorSignal) invocationTargetEx);
				}
			}
		}
		catch(Exception ex)
		{
		}
		
		return targetEx;
	}
	/*
	 * Name : sendBySender Desc : This function is IDM API send Author : ZXY
	 * Systems, Inc Date : 2013.03.04
	 */
	public static void sendBySenderNoAddReturn(Document doc, String senderName) {
		String sendMsg = JdomUtils.toString(doc);
		if( StringUtils.equals(senderName, "DSPSender") || StringUtils.equals(senderName, "MPCSender")){
			GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldNameXmlData);
		}
		else {
			GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		}
		
		GenericServiceProxy.getGenericSender(senderName).send(sendMsg);
		log.debug("senderName = " + senderName);

		if ( !StringUtils.equals(senderName, "FMCSender") ){
			log.debug(" SEND : Message=" + sendMsg);
		}
	}
	
	public void sendErrorBySenderMessage(Document doc,
			String lanuage, Exception e, String senderName) {
		String replySubject = SMessageUtil.getElementValueByName(doc.getDocument().getRootElement().getChild("Header"), "ORIGINALSOURCESUBJECTNAME");
		
		if (log.isInfoEnabled()) {
			log.debug("replySubject = " + replySubject);
			log.debug("senderName = " + senderName);
		}
        
		if(StringUtils.isNotEmpty(replySubject)){
			if (e instanceof BpelException) {
				e = ((BpelException) e).getNativeException();
			}
			String sReplyMsg = this.makeSendError(replySubject, doc, lanuage, e);

			GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
			if (StringUtils.isNotEmpty(replySubject) == true)
				GenericServiceProxy.getGenericSender(senderName).reply(replySubject, sReplyMsg);

			log.error(" SERP : Subject=" + replySubject);
			log.error(" SERP : Message=" + sReplyMsg);
		}
	}
	
	public static Document sendRequestBySenderTimeOut(String subject, Document doc, String senderName, Integer timeout) throws Exception
	{
		log.info("senderName = " + senderName);

		String sendMsg = JdomUtils.toString(doc);

		log.info(" SEND : Message=" + sendMsg);

		if (StringUtils.equals(senderName, "SPCSender"))
		{
			GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldNameXmlData);
		}
		else
		{
			GenericServiceProxy.getGenericSender(senderName).setDataField(SMessageUtil.DataFieldName);
		}

		String reply = (String) GenericServiceProxy.getGenericSender(senderName).sendRequest(subject, sendMsg, timeout);

		log.info(" REP : Message=" + reply);

		Document replyDocument = JdomUtils.loadText(reply);

		return replyDocument;
	}
}
