package com.drops.exp.util;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.drops.utils.HTTPUtils;
import com.drops.utils.ReUtil;

/**
 * @ClassName: H2DatabaseUtil
 * @Description: TODO
 * @Author: Summer
 * @Date: 2021/7/30 9:35
 * @Version: v1.0.0
 * @Description:
 **/
public class H2DatabaseUtil {

    public static boolean hasH2Database(String target ){
        String regex = "h2database";
        String result = HTTPUtils.getRequest(target).body();
        if (result.contains(regex)){
            return true;
        }else {
            return false;
        }
    }

    public static String getJsessionid(String target){
        String result = HTTPUtils.getRequest(target + "/h2-console").body();
        String regex = "jsessionid=([A-Za-z0-9]+)";
//        System.out.println(result);
//        System.out.println(HTTPUtils.getRequest(target + "/h2-console").getStatus());
//        System.out.println(ReUtil.hasVersion(result, regex));

        return ReUtil.hasVersion(result, regex);
    }





    public static void main(String[] args) {
        H2DatabaseUtil.getJsessionid("http://127.0.0.1:9096");
    }
}
