package com.kbstar.eai.inbound.action; 

import javax.jms.Message;

import com.eactive.eai.inbound.action.ActionException;
import com.eactive.eai.inbound.action.RequestActionSupport;
import com.eactive.eai.transformer.util.HexUtil;

public class MQGCMSRequestAction extends RequestActionSupport
{ 
    
    public String[] perform(Object message) throws ActionException
    {
        String[] messageId = new String[1];
        
        if (message instanceof Message) {
            Message msg = (Message) message;
            try {
                String hexMsgId = msg.getJMSMessageID();
                // ID:414d5120504149445f514d2020202020454949d720002f03
                hexMsgId = hexMsgId.substring(3);
                
                messageId[0] = HexUtil.hex2Ascii2Digit(hexMsgId);
                logger.info(adapterName+"] MQ MessageID : " + messageId[0]);
            } catch(Exception e) {
                logger.error(adapterName+"] perform Exception Occur >> "+ e.getMessage(), e);
                throw new ActionException(e.getMessage());
            }
            
        } else {
            logger.error(adapterName+"] received Message Object >> "+ message.getClass().getName());
            throw new ActionException();
        }
        
        return messageId;
    }
    
    public int getFeedback(Object message) throws ActionException 
    {
        int feedback = -1;
        
        if (message instanceof Message) {
            Message msg = (Message) message;
            try {
                feedback = msg.getIntProperty("JMS_IBM_Feedback");
            } catch(Exception e) {
                logger.error(adapterName + "] Can not get feedback message >> " + e.getMessage());
                //throw new ActionException(e.getMessage());
            }
        }
        
        return feedback;
    }
    
	 public String getDescription() {
		return "키추출방식 : MQ JMSMessageID";
	}
} 
