URLString urlRequestString = new URLString();
urlRequestString.parseRequestURLString(bodyString);
String callKey = urlRequestString.getCallKey();
String serviceName = urlRequestString.getParamValue("serviceName");
SCMgmtClient client = new SCMgmtClient(host, port, ConnectionType.NETTY_TCP);
client.attach();
if (callKey.equalsIgnoreCase(Constants.CC_CMD_KILL)) {
client.killSC();
System.out.println("SC exit requested");
} else if (callKey.equalsIgnoreCase(Constants.CC_CMD_DUMP)) {
client.dump();
System.out.println("SC dump requested");
client.detach();
} else if (callKey.equalsIgnoreCase(Constants.CC_CMD_CLEAR_CACHE)) {
client.clearCache();
System.out.println("Cache has been cleared");
client.detach();
} else if (callKey.equalsIgnoreCase(Constants.CC_CMD_ENABLE)) {
try {
client.enableService(serviceName);
System.out.println("Service [" + serviceName + "] has been enabled");
} catch (SCServiceException e) {
System.out.println("Service [" + serviceName + "] does not exist!");
status = 4;
}
client.detach();
} else if (callKey.equalsIgnoreCase(Constants.CC_CMD_DISABLE)) {
try {
client.disableService(serviceName);
System.out.println("Service [" + serviceName + "] has been disabled");
} catch (SCServiceException e) {
System.out.println("Service [" + serviceName + "] does not exist!");
status = 4;
}
client.detach();
} else if (callKey.equalsIgnoreCase(Constants.CC_CMD_STATE)) {
try {
Map<String, String> stateMap = client.getStateOfServices(serviceName);
Set<Entry<String, String>> parameters = stateMap.entrySet();
StringBuilder sb = new StringBuilder();
if (parameters.size() == 0) {
System.out.println("Service [" + serviceName + "] does not exist!");
status = 4;
} else {
for (Entry<String, String> param : parameters) {
sb.append("Service [");
sb.append(param.getKey());
sb.append("] is ");
sb.append(param.getValue());
sb.append("\n");
}
if (sb.length() > 0) {
System.out.println(sb.toString());
}
}
} catch (SCServiceException e) {
System.out.println("Service [" + serviceName + "] does not exist!");
status = 4;
}
client.detach();
} else if (callKey.equalsIgnoreCase(Constants.CC_CMD_SESSIONS)) {
try {
Map<String, String> workloadMap = client.getWorkload(serviceName);
Set<Entry<String, String>> workloads = workloadMap.entrySet();
StringBuilder sb = new StringBuilder();
for (Entry<String, String> param : workloads) {
sb.append("Service [");
sb.append(param.getKey());
sb.append("] has ");
sb.append(param.getValue());
sb.append(" sessions\n");
}
System.out.println(sb.toString());
} catch (SCServiceException e) {
System.out.println("Service [" + serviceName + "] does not exist!");
status = 4;
}
client.detach();
} else if (callKey.equalsIgnoreCase(Constants.CC_CMD_SC_VERSION)) {
try {
String scVersion = client.getSCVersion();
System.out.println(scVersion);
} catch (SCServiceException e) {
System.out.println("Getting version (SC Version) of remote SC failed.");
status = 4;
}
client.detach();
} else if (callKey.equalsIgnoreCase(Constants.CC_CMD_SERVICE_CONF)) {
try {
Map<String, String> serviceConf = client.getServiceConfiguration(serviceName);
System.out.println(serviceConf);
} catch (SCServiceException e) {
System.out.println("Getting service [" + serviceName + "] configuration failed.");
status = 4;
}
client.detach();
} else {
SCConsole.showError("Error - wrong call key in request string.");
status = 3;
}
} catch (UnsupportedEncodingException e) {