use of org.apache.karaf.shell.api.console.SessionFactory in project karaf by apache.
the class SessionFactoryImplTest method createWithNullInputStream.
@Test
public void createWithNullInputStream() throws UnsupportedEncodingException {
final SessionFactory sessionFactory = new SessionFactoryImpl(createMock(ThreadIO.class));
sessionFactory.create(null, createMock(PrintStream.class), createMock(PrintStream.class));
}
use of org.apache.karaf.shell.api.console.SessionFactory in project ddf by codice.
the class CommandJob method doExecute.
public void doExecute(JobExecutionContext context) throws JobExecutionException {
String commandInput;
try {
commandInput = checkInput(context);
} catch (CommandException e) {
LOGGER.debug("unable to get command from job execution context", e);
return;
}
SessionFactory sessionFactory = getSessionFactory();
if (sessionFactory == null) {
LOGGER.debug("unable to create session factory: command=[{}]", commandInput);
return;
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Session session = null;
try (PrintStream output = getPrintStream(byteArrayOutputStream)) {
session = sessionFactory.create(null, output, output);
if (session == null) {
LOGGER.debug("unable to create session: command=[{}]", commandInput);
return;
}
if (commandInput != null) {
try {
LOGGER.trace("Executing command [{}]", commandInput);
session.execute(commandInput);
LOGGER.trace("Execution Output: {}", byteArrayOutputStream.toString(StandardCharsets.UTF_8.name()));
} catch (CommandNotFoundException e) {
LOGGER.info("Command could not be found. Make sure the command's library has been loaded and try again: {}", e.getLocalizedMessage());
LOGGER.debug("Command not found.", e);
} catch (Exception e) {
LOGGER.info("Error with execution. ", e);
}
}
} catch (UnsupportedEncodingException e) {
LOGGER.info("Unable to produce output", e);
} finally {
if (session != null) {
session.close();
}
try {
byteArrayOutputStream.close();
} catch (IOException e) {
LOGGER.debug("Could not close output stream", e);
}
}
}
use of org.apache.karaf.shell.api.console.SessionFactory in project karaf by apache.
the class Activator method doStart.
@Override
protected void doStart() throws Exception {
SessionFactory sf = getTrackedService(SessionFactory.class);
if (sf == null) {
return;
}
if (!ensureStartupConfiguration("org.apache.karaf.shell")) {
return;
}
RegexCommandLoggingFilter filter = new RegexCommandLoggingFilter();
filter.setPattern("ssh (.*?)-P +([^ ]+)");
filter.setGroup(2);
register(CommandLoggingFilter.class, filter);
filter = new RegexCommandLoggingFilter();
filter.setPattern("ssh (.*?)--password +([^ ]+)");
filter.setGroup(2);
register(CommandLoggingFilter.class, filter);
sessionFactory = sf;
sessionFactory.getRegistry().getService(Manager.class).register(SshAction.class);
if (Boolean.parseBoolean(bundleContext.getProperty("karaf.startRemoteShell"))) {
createAndRunSshServer();
}
}
use of org.apache.karaf.shell.api.console.SessionFactory in project karaf by apache.
the class ActionMaskingCallbackTest method setUp.
@Before
public void setUp() {
ThreadIO tio = new ThreadIOImpl();
CommandProcessor cp = new CommandProcessorImpl(tio);
SessionFactory sf = new SessionFactoryImpl(tio);
InputStream is = new ByteArrayInputStream(new byte[0]);
PrintStream os = new PrintStream(new ByteArrayOutputStream());
Session session = new HeadlessSessionImpl(sf, cp, is, os, os);
parser = new KarafParser(session);
ActionCommand cmd = new ActionCommand(null, UserAddCommand.class);
cb = ActionMaskingCallback.build(cmd);
}
Aggregations