Wildfly 10.0.0 Accessing CLI programmatically
delphinus818 Jun 7, 2017 12:05 PMWhat is the right way to access CLI programmatically using Wildfly 10.0.0? I tried to use jboss-deployment-structure.xml to specify org.jboss.as.cli as a module and exclude all dependencies. I got the following error:
CliInitializationException : org.jboss.as.cli.CliInitializationException: Failed to load org.jboss.as.cli.impl.CommandContextFactoryImpl
at org.jboss.as.cli.CommandContextFactory.getInstance(CommandContextFactory.java:43)
If I tried to package jboss-as-cli as a dependency, then I also had to package staxmapper as a dependency, eventually it will lead to the following error using this approach:
Exception when handling error trying to reset the response.: java.util.ServiceConfigurationError: org.jboss.as.cli.CommandHandlerProvider: Provider org.wildfly.extension.messaging.activemq.jms.cli.ConnectionFactoryHandlerProvider not a subtype
at java.util.ServiceLoader.fail(ServiceLoader.java:239) [rt.jar:1.8.0_71]
at java.util.ServiceLoader.access$300(ServiceLoader.java:185) [rt.jar:1.8.0_71]
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376) [rt.jar:1.8.0_71]
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404) [rt.jar:1.8.0_71]
at java.util.ServiceLoader$1.next(ServiceLoader.java:480) [rt.jar:1.8.0_71]
at org.jboss.as.cli.impl.CommandContextImpl.registerExtraHandlers(CommandContextImpl.java:591) [jboss-cli-client.jar:2.0.10.Final]
at org.jboss.as.cli.impl.CommandContextImpl.initCommands(CommandContextImpl.java:584) [jboss-cli-client.jar:2.0.10.Final]
at org.jboss.as.cli.impl.CommandContextImpl.<init>(CommandContextImpl.java:302) [jboss-cli-client.jar:2.0.10.Final]
at org.jboss.as.cli.impl.CommandContextFactoryImpl.newCommandContext(CommandContextFactoryImpl.java:44) [jboss-cli-client.jar:2.0.10.Final]
The code is something like this:
//CLI API
import org.jboss.as.cli.CliInitializationException;
import org.jboss.as.cli.CommandContext;
import org.jboss.as.cli.CommandContextFactory;
import org.jboss.as.cli.CommandLineException;
import org.jboss.as.cli.CommandFormatException;
import org.jboss.as.controller.client.ModelControllerClient;
// DMR API
import org.jboss.dmr.ModelNode;
public class CLILoggingImpl implements LoggingConfiguration {
private static final Logger logger = Logger.getLogger(CLILoggingImpl.class);
private static CommandContext ctx;
private String failureDescription;
private Handler handlerType = Handler.UNKNOWN;
private ModelNode result;
private Level logLevel = null;
private String rotateSize = null;
private String maxBackupIndex = null;
public CLILoggingImpl() {
try {
logger.debug("CLILogging Init...");
ctx = CommandContextFactory.getInstance().newCommandContext();
}
catch(CliInitializationException e) {
logger.debug("CliInitializationException ", e);
//throw new IllegalStateException("Failed to initialize CLI context", e);
}
}
private LResult connectHandler(String request) {
try {
ctx.connectController();
logger.debug("Running command ---- " + request);
CommandResult res = runCommands(request);
ctx.disconnectController();
.......
}
catch (CommandLineException e) {
logger.error("Failed to connect, CommandLineException ", e);
this.failureDescription = e.getMessage();
return LResult.FAILED;
}
}