package com.bocloud.ims.service.utils;


import com.bocloud.common.enums.PostDataFormat;
import com.bocloud.common.http.HttpClient;
import com.bocloud.common.model.Result;
import com.bocloud.ims.common.utils.constant.Constant;

/**
 * HttpUtils
 *
 * @author 007
 *
 */
public class HttpUtils {

    /**
     * get url to check if http service is in service
     *
     * @param url
     * @return
     */
    public static boolean online(String url) {
        try {
            HttpClient imageServerClient = new HttpClient(1000 * 10, PostDataFormat.RAW);
            Result pingResult = imageServerClient.get(url);
            return !pingResult.isFailed() && !pingResult.getMessage().contains(Constant.TIME_OUT)
                    && !pingResult.getMessage().contains(Constant.REFUSED)
                    && !pingResult.getMessage().contains(Constant.NO_CONTENT);
        } catch (Exception e) {
            return false;
        }
    }
}