use of org.mx.rest.client.RestClientInvoke 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();
}
}
use of org.mx.rest.client.RestClientInvoke 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();
}
}
Aggregations