package com.eactive.eai.control;

import java.util.Properties;

import com.eactive.eai.adapter.ElinkAdapter;
import com.eactive.eai.adapter.ElinkAdapterFactory;
import com.eactive.eai.common.util.Logger;

public class BusinessApplicationSender {
	private static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
	static final String IA_CONTROL_ERROR = "RECEAIAHA003";

	public static byte[] callService(String adapterGroupName, Properties prop, Object message, Properties tempProp)
			throws Exception {
		byte[] resBytes;
		try {
			ElinkAdapterFactory factory = ElinkAdapterFactory.newInstance();
			ElinkAdapter adapter = factory.getElinkAdapter(com.eactive.eai.adapter.Keys.TYPE_APP);
			if (prop == null) {
				prop = new Properties();
			}
			if (tempProp == null) {
				tempProp = new Properties();
			}
			if (tempProp.getProperty("ADAPTER_GROUP_NAME") == null) {
				tempProp.setProperty("ADAPTER_GROUP_NAME", adapterGroupName);
			}
			resBytes = (byte[]) adapter.callService(adapterGroupName, prop, message, tempProp);
		} catch (Exception e) {
			logger.error("callService error", e);
			throw e;
		}
		return resBytes;
	}
}
