use of com.sun.identity.cli.rest.RestCommand in project OpenAM by OpenRock.
the class StopRecord method handleRequest.
/**
* Stop recording
* @param rc Request Context.
* @throws CLIException
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
IOutput outputWriter = getOutputWriter();
String serverName = getStringOptionValue(IArgument.SERVER_NAME);
debug.message("Stop recording: serverURL : '{}'", serverName);
String[] argsAttempt = { serverName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_STOP_RECORD", argsAttempt);
SSOToken adminSSOToken = getAdminSSOToken();
try {
if (!ServerConfiguration.isServerInstanceExist(adminSSOToken, serverName)) {
String message = "ServerName '" + serverName + "' doesn't exist";
debug.error(message);
outputWriter.printlnMessage(message);
String[] args = { serverName, message };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_STOP_RECORD", args);
return;
}
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
RestCommand restCommand = new RestCommand();
String result = restCommand.sendRestCommand(adminSSOToken.getTokenID(), new URL(serverName + "/json/" + RecordConstants.RECORD_REST_ENDPOINT + "?_action=" + RecordConstants.STOP_ACTION), "POST", headers, "");
debug.message("Stop recording with success. Result : '{}'", result);
if (result.isEmpty()) {
outputWriter.printlnMessage("Result from server is empty. An error occurred. See debug logs for more " + "information");
String[] args = { serverName, "Result from server is empty. An error occurred." };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_STATUS_RECORD", args);
}
String[] args = { serverName, result };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCESS_STOP_RECORD", args);
outputWriter.printlnMessage(result);
} catch (IOException | SMSException | SSOException e) {
debug.error("An error occurred", e);
outputWriter.printlnMessage(e.getMessage());
String[] args = { serverName, e.getMessage() };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_STOP_RECORD", args);
}
}
use of com.sun.identity.cli.rest.RestCommand in project OpenAM by OpenRock.
the class StartRecord method handleRequest.
/**
* Start recording handle
* @param rc Request Context.
* @throws CLIException
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
IOutput outputWriter = getOutputWriter();
String jsonFileName = getStringOptionValue(IArgument.JSON_FILE);
String jsonContent = CLIUtil.getFileContent(getCommandManager(), jsonFileName, false);
String serverName = getStringOptionValue(IArgument.SERVER_NAME);
debug.message("Start recording: serverURL : '{}', data '{}'", serverName, jsonContent);
String[] argsAttempt = { serverName, jsonContent };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_START_RECORD", argsAttempt);
SSOToken adminSSOToken = getAdminSSOToken();
try {
if (!ServerConfiguration.isServerInstanceExist(adminSSOToken, serverName)) {
String message = "ServerName '" + serverName + "' doesn't exist";
debug.error(message);
outputWriter.printlnMessage(message);
String[] args = { serverName, jsonContent, message };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_START_RECORD", args);
return;
}
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
RestCommand restCommand = new RestCommand();
String result = restCommand.sendRestCommand(adminSSOToken.getTokenID(), new URL(serverName + "/json/" + RecordConstants.RECORD_REST_ENDPOINT + "?_action=" + RecordConstants.START_ACTION), "POST", headers, jsonContent);
debug.message("Recording started with success. Result : '{}'", result);
if (result.isEmpty()) {
outputWriter.printlnMessage("Result from server is empty. An error occurred. See debug logs for more " + "information");
String[] args = { serverName, jsonContent, "Result from server is empty. An error occurred." };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_START_RECORD", args);
}
String[] args = { serverName, jsonContent, result };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCESS_START_RECORD", args);
outputWriter.printlnMessage(result);
} catch (SSOException | SMSException | IOException e) {
debug.error("An error occurred", e);
outputWriter.printlnMessage(e.getMessage());
String[] args = { serverName, jsonContent, e.getMessage() };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_START_RECORD", args);
}
}
use of com.sun.identity.cli.rest.RestCommand in project OpenAM by OpenRock.
the class StatusRecord method handleRequest.
/**
* Record
* @param rc Request Context.
* @throws CLIException
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
IOutput outputWriter = getOutputWriter();
String serverName = getStringOptionValue(IArgument.SERVER_NAME);
debug.message("Recording status: serverURL : '{}'", serverName);
String[] argsAttempt = { serverName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_STATUS_RECORD", argsAttempt);
SSOToken adminSSOToken = getAdminSSOToken();
try {
if (!ServerConfiguration.isServerInstanceExist(adminSSOToken, serverName)) {
String message = "ServerName '" + serverName + "' doesn't exist";
debug.error(message);
outputWriter.printlnMessage(message);
String[] args = { serverName, message };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_STATUS_RECORD", args);
return;
}
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
RestCommand restCommand = new RestCommand();
String result = restCommand.sendRestCommand(adminSSOToken.getTokenID(), new URL(serverName + "/json/" + RecordConstants.RECORD_REST_ENDPOINT + "?_action=" + RecordConstants.STATUS_ACTION), "POST", headers, "");
debug.message("Recording status with success. Result : '{}'", result);
if (result.isEmpty()) {
outputWriter.printlnMessage("Result from server is empty. An error occurred. See debug logs for more " + "information");
String[] args = { serverName, "Result from server is empty. An error occurred." };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_STATUS_RECORD", args);
}
String[] args = { serverName, result };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCESS_STATUS_RECORD", args);
outputWriter.printlnMessage(result);
} catch (IOException | SMSException | SSOException e) {
debug.error("An error occurred", e);
outputWriter.printlnMessage(e.getMessage());
String[] args = { serverName, e.getMessage() };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_STATUS_RECORD", args);
}
}
Aggregations