use of org.neo4j.shell.Session in project neo4j by neo4j.
the class BashVariableInterpreterTest method customInterpreter.
@Test
public void customInterpreter() throws Exception {
// GIVEN
interpreter.addReplacer("test", new Replacer() {
@Override
public String getReplacement(ShellServer server, Session session) throws ShellException {
return "Hello";
}
});
// WHEN
String interpreted = interpreter.interpret("\\test world", server, session);
// THEN
assertEquals("Hello world", interpreted);
}
use of org.neo4j.shell.Session in project neo4j by neo4j.
the class SimpleAppServer method welcome.
@Override
public Welcome welcome(Map<String, Serializable> initialSession) throws RemoteException, ShellException {
Serializable clientId = newClientId();
if (clientSessions.containsKey(clientId)) {
throw new IllegalStateException("Client " + clientId + " already initialized");
}
Session session = newSession(clientId, initialSession);
clientSessions.put(clientId, session);
try {
String message = noWelcome(initialSession) ? "" : getWelcomeMessage();
return new Welcome(message, clientId, getPrompt(session));
} catch (ShellException e) {
throw new RemoteException(e.getMessage());
}
}
use of org.neo4j.shell.Session in project neo4j by neo4j.
the class SimpleAppServer method newSession.
private Session newSession(Serializable id, Map<String, Serializable> initialSession) throws ShellException {
Session session = new Session(id);
initialPopulateSession(session);
for (Map.Entry<String, Serializable> entry : initialSession.entrySet()) {
session.set(entry.getKey(), entry.getValue());
}
return session;
}
use of org.neo4j.shell.Session in project neo4j by neo4j.
the class AbstractAppServer method interpretLine.
@Override
public Response interpretLine(Serializable clientId, String line, Output out) throws ShellException {
Session session = getClientSession(clientId);
if (line == null || line.trim().length() == 0) {
return new Response(getPrompt(session), Continuation.INPUT_COMPLETE);
}
try {
Continuation commandResult = null;
for (String command : line.split(Pattern.quote("&&"))) {
command = TextUtil.removeSpaces(command);
command = replaceAlias(command, session);
AppCommandParser parser = new AppCommandParser(this, command);
commandResult = parser.app().execute(parser, session, out);
}
return new Response(getPrompt(session), commandResult);
} catch (Exception e) {
throw wrapException(e);
}
}
Aggregations