Search in sources :

Example 1 with RestInvokeException

use of org.mx.rest.client.RestInvokeException in project main by JohnPeng739.

the class ServerManageServiceImpl method serviceStatusRestJson.

private JSONObject serviceStatusRestJson(String machineIp) throws UserInterfaceErrorException {
    if (StringUtils.isBlank(machineIp)) {
        throw new UserInterfaceErrorException(UserInterfaceErrors.SYSTEM_ILLEGAL_PARAM);
    }
    RestClientInvoke invoke = new RestClientInvoke();
    try {
        int restPort = env.getProperty("restful.port", Integer.class, 9999);
        String url = String.format("http://%s:%d/rest/server/status/local", machineIp, restPort);
        JSONObject json = invoke.get(url, JSONObject.class);
        if (logger.isDebugEnabled()) {
            logger.debug(String.format("From %s response: %s.", url, json.toJSONString()));
        }
        return json.getJSONObject("data");
    } catch (RestInvokeException ex) {
        if (logger.isErrorEnabled()) {
            logger.error(ex);
        }
        throw new UserInterfaceErrorException(UserInterfaceErrors.SERVICE_STATUS_FAIL);
    } finally {
        invoke.close();
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) RestInvokeException(org.mx.rest.client.RestInvokeException) RestClientInvoke(org.mx.rest.client.RestClientInvoke)

Example 2 with RestInvokeException

use of org.mx.rest.client.RestInvokeException in project main by JohnPeng739.

the class ServerManageServiceImpl method serviceRest.

/**
 * {@inheritDoc}
 *
 * @see ServerManageService#serviceRest(String, String, String)
 */
@Override
public boolean serviceRest(String cmd, String service, String machineIp) throws UserInterfaceErrorException {
    if (StringUtils.isBlank(cmd) || StringUtils.isBlank(service) || StringUtils.isBlank(machineIp)) {
        throw new UserInterfaceErrorException(UserInterfaceErrors.SYSTEM_ILLEGAL_PARAM);
    }
    RestClientInvoke invoke = new RestClientInvoke();
    try {
        JSONObject serviceConfig = getServiceConfig(machineIp, service);
        int restPort = env.getProperty("restful.port", Integer.class, 9999);
        String userCode = sessionDataStore.getCurrentUserCode();
        JSONObject json = invoke.post(String.format("http://%s:%d/rest/server/service/local?cmd=%s&service=%s&userCode=%s", machineIp, restPort, cmd, service, userCode), serviceConfig, JSONObject.class);
        return json.getBooleanValue("data");
    } catch (RestInvokeException ex) {
        if (logger.isErrorEnabled()) {
            logger.error(ex);
        }
        throw new UserInterfaceErrorException(UserInterfaceErrors.SERVICE_STATUS_FAIL);
    } finally {
        invoke.close();
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) RestInvokeException(org.mx.rest.client.RestInvokeException) RestClientInvoke(org.mx.rest.client.RestClientInvoke)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)2 UserInterfaceErrorException (com.ds.retl.exception.UserInterfaceErrorException)2 RestClientInvoke (org.mx.rest.client.RestClientInvoke)2 RestInvokeException (org.mx.rest.client.RestInvokeException)2