package com.eactive.eai.adapter.http.client.impl.filter;

import java.util.Properties;

import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

import com.eactive.eai.common.TransactionContextKeys;

public class SimpleframeworkBodyFilter extends SimpleFrameworkFilter {
	@Override
	public Object doPreFilter(String adptGrpName, String adptName, Properties prop, Object message, Properties tempProp)
			throws Exception {
		
		Object returnMessage = super.doPreFilter(adptGrpName, adptName, prop, message, tempProp);
		
		JSONObject bizJsonStr = null;
		
		if ( returnMessage instanceof String ) {
			bizJsonStr = (JSONObject) JSONValue.parse( (String)returnMessage);
			if( bizJsonStr != null ) {
			    bizJsonStr.put("GUID", tempProp.getOrDefault(TransactionContextKeys.GUID, "") );
			}
		}
		
		return bizJsonStr != null ? bizJsonStr.toJSONString() : returnMessage;
	}
}
