use of org.jboss.as.cli.OperationCommand.HandledRequest in project wildfly-core by wildfly.
the class CommandContextImpl method buildRequest.
protected HandledRequest buildRequest(String line, boolean batchMode) throws CommandFormatException {
if (line == null || line.isEmpty()) {
throw new OperationFormatException("The line is null or empty.");
}
final DefaultCallbackHandler originalParsedArguments = this.parsedCmd;
final String originalCmdLine = this.cmdLine;
try {
this.parsedCmd = new DefaultCallbackHandler();
resetArgs(line);
if (parsedCmd.getFormat() == OperationFormat.INSTANCE) {
final ModelNode request = this.parsedCmd.toOperationRequest(this);
return new HandledRequest(request, null);
}
final CommandHandler handler = cmdRegistry.getCommandHandler(parsedCmd.getOperationName());
if (handler != null) {
if (batchMode) {
if (!handler.isBatchMode(this)) {
throw new OperationFormatException("The command is not allowed in a batch.");
}
Batch batch = getBatchManager().getActiveBatch();
return ((OperationCommand) handler).buildHandledRequest(this, batch.getAttachments());
} else if (!(handler instanceof OperationCommand)) {
throw new OperationFormatException("The command does not translate to an operation request.");
}
return new HandledRequest(((OperationCommand) handler).buildRequest(this), null);
} else {
return buildAeshCommandRequest(parsedCmd, batchMode);
}
} finally {
clear(Scope.REQUEST);
this.parsedCmd = originalParsedArguments;
this.cmdLine = originalCmdLine;
}
}
use of org.jboss.as.cli.OperationCommand.HandledRequest in project wildfly-core by wildfly.
the class CommandContextImpl method handleLegacyCommand.
private void handleLegacyCommand(String opLine, CommandHandler handler, boolean direct) throws CommandLineException {
if (isBatchMode() && handler.isBatchMode(this)) {
if (!(handler instanceof OperationCommand)) {
throw new CommandLineException("The command is not allowed in a batch.");
} else {
try {
Batch batch = getBatchManager().getActiveBatch();
HandledRequest request = ((OperationCommand) handler).buildHandledRequest(this, batch.getAttachments());
BatchedCommand batchedCmd = new DefaultBatchedCommand(this, opLine, request.getRequest(), request.getResponseHandler());
batch.add(batchedCmd);
} catch (CommandFormatException e) {
throw new CommandFormatException("Failed to add to batch '" + opLine + "'", e);
}
}
} else if (direct) {
handler.handle(CommandContextImpl.this);
} else {
execute(() -> {
executor.execute(handler, timeout, TimeUnit.SECONDS);
return null;
}, opLine);
}
}
Aggregations