Search in sources :

Example 1 with RemoteUrl

use of com.baidu.disconf.core.common.restful.core.RemoteUrl in project disconf by knightliao.

the class RestfulMgrTestCase method tetGetJsonData.

/**
     *
     */
@Test
public void tetGetJsonData() {
    try {
        RemoteUrl remoteUrl = new RemoteUrl(RemoteMockServer.ITEM_URL, RemoteMockServer.LOCAL_HOST_LIST);
        ValueVo valueVo = restfulMgr.getJsonData(ValueVo.class, remoteUrl, 3, 3);
        Assert.assertEquals(String.valueOf(RemoteMockServer.DEFAULT_ITEM_VALUE), valueVo.getValue());
    } catch (Exception e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : RemoteUrl(com.baidu.disconf.core.common.restful.core.RemoteUrl) ValueVo(com.baidu.disconf.core.common.json.ValueVo) Test(org.junit.Test)

Example 2 with RemoteUrl

use of com.baidu.disconf.core.common.restful.core.RemoteUrl in project disconf by knightliao.

the class FetcherMgrImpl method getValueFromServer.

/**
     * 根据 URL 从远程 获取Value值
     */
public String getValueFromServer(String url) throws Exception {
    // 远程地址
    RemoteUrl remoteUrl = new RemoteUrl(url, hostList);
    ValueVo confItemVo = restfulMgr.getJsonData(ValueVo.class, remoteUrl, retryTime, retrySleepSeconds);
    LOGGER.debug("remote server return: " + confItemVo.toString());
    if (confItemVo.getStatus().equals(Constants.NOTOK)) {
        throw new Exception("status is not ok.");
    }
    return confItemVo.getValue();
}
Also used : RemoteUrl(com.baidu.disconf.core.common.restful.core.RemoteUrl) ValueVo(com.baidu.disconf.core.common.json.ValueVo)

Example 3 with RemoteUrl

use of com.baidu.disconf.core.common.restful.core.RemoteUrl in project disconf by knightliao.

the class FetcherMgrImpl method downloadFileFromServer.

/**
     * 下载配置文件, remoteUrl是 url
     *
     * @throws Exception
     */
public String downloadFileFromServer(String url, String fileName, String targetFileDir) throws Exception {
    // 下载的路径
    String localDir = getLocalDownloadDirPath();
    // 设置远程地址
    RemoteUrl remoteUrl = new RemoteUrl(url, hostList);
    // 下载
    return restfulMgr.downloadFromServer(remoteUrl, fileName, localDir, localDownloadDirTemp, targetFileDir, enableLocalDownloadDirInClassPath, retryTime, retrySleepSeconds);
}
Also used : RemoteUrl(com.baidu.disconf.core.common.restful.core.RemoteUrl)

Example 4 with RemoteUrl

use of com.baidu.disconf.core.common.restful.core.RemoteUrl in project disconf by knightliao.

the class RestfulMgrTestCase method testZooHost.

/**
     *
     */
@Test
public void testZooHost() {
    try {
        RemoteUrl remoteUrl = new RemoteUrl(RemoteMockServer.ZOO_URL, RemoteMockServer.LOCAL_HOST_LIST);
        ValueVo valueVo = restfulMgr.getJsonData(ValueVo.class, remoteUrl, 3, 3);
        Assert.assertEquals(String.valueOf(RemoteMockServer.ZOO_HOSTS), valueVo.getValue());
    } catch (Exception e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : RemoteUrl(com.baidu.disconf.core.common.restful.core.RemoteUrl) ValueVo(com.baidu.disconf.core.common.json.ValueVo) Test(org.junit.Test)

Example 5 with RemoteUrl

use of com.baidu.disconf.core.common.restful.core.RemoteUrl in project disconf by knightliao.

the class RestfulMgrTestCase method testZooPrefixUrl.

/**
     *
     */
@Test
public void testZooPrefixUrl() {
    try {
        RemoteUrl remoteUrl = new RemoteUrl(RemoteMockServer.ZOO_PREFIX_URL, RemoteMockServer.LOCAL_HOST_LIST);
        ValueVo valueVo = restfulMgr.getJsonData(ValueVo.class, remoteUrl, 3, 3);
        Assert.assertEquals(String.valueOf(RemoteMockServer.ZOO_PREFIX_VALUE), valueVo.getValue());
    } catch (Exception e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : RemoteUrl(com.baidu.disconf.core.common.restful.core.RemoteUrl) ValueVo(com.baidu.disconf.core.common.json.ValueVo) Test(org.junit.Test)

Aggregations

RemoteUrl (com.baidu.disconf.core.common.restful.core.RemoteUrl)6 ValueVo (com.baidu.disconf.core.common.json.ValueVo)4 Test (org.junit.Test)4 File (java.io.File)1