package com.eactive.eai.control;

import java.net.SocketTimeoutException;
import java.util.Properties;

import com.eactive.eai.adapter.ElinkAdapter;
import com.eactive.eai.adapter.ElinkAdapterFactory;
import com.eactive.eai.adapter.Keys;
import com.eactive.eai.adapter.http.HttpStatusException;
import com.eactive.eai.common.exception.ExceptionUtil;
import com.eactive.eai.common.util.Logger;

public class HttpSender {
	static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
	static final long serialVersionUID = 1L;
    static final String HTTP_CONTROL_ERROR1 = "RECEAIOHC001";
    static final String HTTP_CONTROL_ERROR2 = "RECEAIOHC002";
    static final String HTTP_QUICS = "HTTP_QUICS";			//럭키넘버스 업무를 위한 http adpater 

	public static Object callService(String adapterGroupName, Properties prop, Object inputData, Properties tempProp)
			throws Exception {

		ElinkAdapter adapter = null;

		adapter = ElinkAdapterFactory.newInstance().getElinkAdapter(Keys.TYPE_HTTP);
		
		String adapterName = tempProp.getProperty(com.eactive.eai.adapter.Keys.OUT_ADAPTER_NAME);
		
		try {
			return adapter.callService(adapterGroupName, prop, inputData, tempProp);
		} catch (SocketTimeoutException ste) {
			throw ste;
		} catch (HttpStatusException hse) {
			throw hse;
		} catch (Exception e) {
			logger.error("HttpSender] callService " + adapterName + " : "+ e.getMessage(), e);
			throw new Exception(ExceptionUtil.getErrorCode(e, HTTP_CONTROL_ERROR1) + ", Adapter : " + adapterName);
		}
	}
}
