Search in sources :

Example 1 with Response

use of org.neo4j.shell.Response 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);
    }
}
Also used : Response(org.neo4j.shell.Response) Continuation(org.neo4j.shell.Continuation) AppCommandParser(org.neo4j.shell.AppCommandParser) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException) Session(org.neo4j.shell.Session)

Example 2 with Response

use of org.neo4j.shell.Response in project neo4j by neo4j.

the class AbstractClient method evaluate.

@Override
public void evaluate(String line, Output out) throws ShellException {
    if (EXIT_COMMANDS.contains(line)) {
        end();
        return;
    }
    boolean success = false;
    try {
        String expandedLine = fullLine(line);
        Response response = getServer().interpretLine(id, expandedLine, out);
        Continuation continuation = response.getContinuation();
        switch(continuation) {
            case INPUT_COMPLETE:
                endMultiLine();
                break;
            case INPUT_INCOMPLETE:
                multiLine.add(line);
                break;
            case EXIT:
                getServer().leave(id);
                end();
                break;
            case EXCEPTION_CAUGHT:
                endMultiLine();
                break;
            default:
                throw new IllegalStateException("Unknown continuation: " + continuation);
        }
        prompt = response.getPrompt();
        success = true;
    } catch (RemoteException e) {
        throw ShellException.wrapCause(e);
    } finally {
        if (!success) {
            endMultiLine();
        }
    }
}
Also used : Response(org.neo4j.shell.Response) Continuation(org.neo4j.shell.Continuation) RemoteException(java.rmi.RemoteException)

Example 3 with Response

use of org.neo4j.shell.Response in project neo4j by neo4j.

the class ClientIT method shouldExitMultilineModeAfterGettingWarningOrError.

@Test
public void shouldExitMultilineModeAfterGettingWarningOrError() throws ShellException, RemoteException {
    final CollectingOutput output = new CollectingOutput();
    final String message = "Test method called";
    final String prompt = "our test prompt";
    AbstractClient client = new AbstractClient(null, null) {

        @Override
        public ShellServer getServer() {
            ShellServer server = null;
            try {
                server = new GraphDatabaseShellServer(null) {

                    @Override
                    public Response interpretLine(Serializable clientId, String line, Output out) throws ShellException {
                        try {
                            out.println(message);
                        } catch (RemoteException ignored) {
                        }
                        return new Response(prompt, line.endsWith(";") ? Continuation.EXCEPTION_CAUGHT : Continuation.INPUT_INCOMPLETE);
                    }
                };
            } catch (RemoteException ignored) {
            }
            return server;
        }

        @Override
        public Output getOutput() {
            return output;
        }
    };
    client.evaluate("RETURN ");
    assertThat(client.getPrompt(), equalTo("> "));
    client.evaluate("i;");
    Set<String> messages = new HashSet<>();
    for (String s : output) {
        messages.add(s);
    }
    assertThat(messages, contains(message));
    assertThat(client.getPrompt(), equalTo(prompt));
}
Also used : Serializable(java.io.Serializable) ShellException(org.neo4j.shell.ShellException) Response(org.neo4j.shell.Response) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) ShellServer(org.neo4j.shell.ShellServer) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) Output(org.neo4j.shell.Output) RemoteException(java.rmi.RemoteException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with Response

use of org.neo4j.shell.Response in project neo4j by neo4j.

the class ClientIT method shouldHandleNormalInput.

@Test
public void shouldHandleNormalInput() throws ShellException, RemoteException {
    final CollectingOutput output = new CollectingOutput();
    final String message = "Test method called";
    AbstractClient client = new AbstractClient(null, null) {

        @Override
        public ShellServer getServer() {
            ShellServer server = null;
            try {
                server = new GraphDatabaseShellServer(null) {

                    @Override
                    public Response interpretLine(Serializable clientId, String line, Output out) throws ShellException {
                        try {
                            out.println(message);
                        } catch (RemoteException ignored) {
                        }
                        return new Response("", Continuation.INPUT_COMPLETE);
                    }
                };
            } catch (RemoteException ignored) {
            }
            return server;
        }

        @Override
        public Output getOutput() {
            return output;
        }
    };
    client.evaluate("RETURN 1;");
    Set<String> messages = new HashSet<>();
    for (String s : output) {
        messages.add(s);
    }
    assertThat(messages, contains(message));
}
Also used : Serializable(java.io.Serializable) ShellException(org.neo4j.shell.ShellException) Response(org.neo4j.shell.Response) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) ShellServer(org.neo4j.shell.ShellServer) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) Output(org.neo4j.shell.Output) RemoteException(java.rmi.RemoteException) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

RemoteException (java.rmi.RemoteException)4 Response (org.neo4j.shell.Response)4 ShellException (org.neo4j.shell.ShellException)3 Serializable (java.io.Serializable)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 Continuation (org.neo4j.shell.Continuation)2 Output (org.neo4j.shell.Output)2 ShellServer (org.neo4j.shell.ShellServer)2 GraphDatabaseShellServer (org.neo4j.shell.kernel.GraphDatabaseShellServer)2 AppCommandParser (org.neo4j.shell.AppCommandParser)1 Session (org.neo4j.shell.Session)1