package com.ifeng.at.testagent.reflect;


import java.lang.reflect.Field;

public class DataInterfaceHelper {
    private static String HTTP_VCIS_IFENG_COM = "http://vcis.ifeng.com";
    private static String HTTP_VCSP_IFENG_COM = "http://vcsp.ifeng.com";
    private static String HTTP_V_IFENG_COM = "http://v.ifeng.com";
    private static String HTTP_COMMENT_IFENG_COM = "http://comment.ifeng.com";

    public static void setHost(String host) throws ClassNotFoundException, IllegalAccessException {
        String className = "com.ifeng.video.dao.db.constants.DataInterface";
        Class dataInterface = Class.forName(className);
        Field[] fields = dataInterface.getDeclaredFields();
        for(Field field: fields){
            if(field.getType() == String.class){
                modifyHost(dataInterface, field, host);
            }
        }
    }

    private static void modifyHost(Object instance, Field field, String host) throws IllegalAccessException {
        field.setAccessible(true);
        String value = (String) field.get(instance);
        if(value.startsWith(HTTP_VCIS_IFENG_COM)){
            value = value.replaceFirst(HTTP_VCIS_IFENG_COM, "http://"+host+"/vcis.ifeng.com");
            field.set(instance, value);
        }else if(value.startsWith(HTTP_VCSP_IFENG_COM)){
            value = value.replaceFirst(HTTP_VCSP_IFENG_COM, "http://"+host+"/vcsp.ifeng.com");
            field.set(instance, value);
        }else if(value.startsWith(HTTP_V_IFENG_COM)){
            value = value.replaceFirst(HTTP_V_IFENG_COM, "http://"+host+"/v.ifeng.com");
            field.set(instance, value);
        }else if(value.startsWith(HTTP_COMMENT_IFENG_COM)){
            value = value.replaceFirst(HTTP_COMMENT_IFENG_COM, "http://"+host+"/comment.ifeng.com");
            field.set(instance, value);
        }
    }
}

@@ -394,16 +394,87 @@
 ng.com%22;
+%0A    private static String HTTPS_ID_IFENG_COM = %22https://id.ifeng.com%22;
 %0A%0A    pu
@@ -1882,32 +1882,220 @@
 stance, value);%0A
+        %7Delse if(value.startsWith(HTTPS_ID_IFENG_COM))%7B%0A            value = value.replaceFirst(HTTPS_ID_IFENG_COM, %22http://%22+host+%22/id.ifeng.com%22);%0A            field.set(instance, value);%0A
         %7D%0A    %7D%0A

Add login helper