package com.eactive.eai.custom.adapter.http.dynamic.filter;

import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.eactive.eai.adapter.http.dynamic.filter.InCryptoFilter;
import com.eactive.eai.adapter.http.dynamic.filter.HttpAdapterFilter;

/**
 * InCryptoFilter를 멤버변수로 관리하는 HttpAdapterFilter 구현체.
 *
 * 멤버변수에 세팅된 값을 Properties로 변환하여 {@link InCryptoFilter}에 위임한다.
 * 값이 blank인 멤버변수는 Properties에 포함하지 않으며, InCryptoFilter의 기본값이 적용된다.
 */
public class EncFieldInCryptoFilter implements HttpAdapterFilter {

    private final InCryptoFilter filter = new InCryptoFilter();

    @Override
    public Object doPreFilter(String adptGrpName, String adptName, Object message, Properties prop,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        return filter.doPreFilter(adptGrpName, adptName, message, setProp(prop), request, response);
    }

    @Override
    public Object doPostFilter(String adptGrpName, String adptName, Object resultMessage, Properties prop,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        return filter.doPostFilter(adptGrpName, adptName, resultMessage, setProp(prop), request, response);
    }

    protected Properties setProp(Properties p) {
    	p.setProperty(InCryptoFilter.PROP_DEC_FROM_PATH, "/encryptedData");
    	p.setProperty(InCryptoFilter.PROP_ENC_TO_PATH, "/encryptedData");
        return p;
    }

    
}
