neo4j-contrib / gremlin-plugin

A Plugin for the Neo4j server add Tinkerpop-related functionality
Other
55 stars 23 forks source link

Neo4J 2.0.2 + Gremlin plugin: the console doesn't runs #22

Open jordidurancals opened 10 years ago

jordidurancals commented 10 years ago

I'm experimenting with Neo4J + Gremlin plugin, unfortunately I got this error (bellow) when I try to use the Gremlin console web (the console didn't runs on Gremlin language):

SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NoClassDefFoundError: org/neo4j/server/logging/Logger
    at org.neo4j.server.webadmin.console.GremlinSession.<clinit>(GremlinSession.java:42)
    at org.neo4j.server.webadmin.console.GremlinSessionCreator.newSession(GremlinSessionCreator.java:35)
......

I imagined that Neo4J Server has changed the Logger class.

jordidurancals commented 10 years ago

Hi,

Neo4J 2.0.2 server has changed the Logger class, so I modified GremlinSession.java code in order to use java.util.logging.Logger class instead of org.neo4j.server.logging.Logger. Finally the Gremlin console web works fine:

Here you will find the new GremlinSession.java code.

            /**
             * Copyright (c) 2002-2014 "Neo Technology,"
             * Network Engine for Objects in Lund AB [http://neotechnology.com]
             *
             * This file is part of Neo4j.
             *
             * Neo4j is free software: you can redistribute it and/or modify
             * it under the terms of the GNU General Public License as published by
             * the Free Software Foundation, either version 3 of the License, or
             * (at your option) any later version.
             *
             * This program is distributed in the hope that it will be useful,
             * but WITHOUT ANY WARRANTY; without even the implied warranty of
             * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
             * GNU General Public License for more details.
             *
             * You should have received a copy of the GNU General Public License
             * along with this program.  If not, see <http://www.gnu.org/licenses/>.
             */
            package org.neo4j.server.webadmin.console;

            import com.tinkerpop.blueprints.TransactionalGraph;
            import com.tinkerpop.blueprints.impls.neo4j2.Neo4j2Graph;
            import groovy.lang.Binding;
            import groovy.lang.GroovyRuntimeException;
            import org.codehaus.groovy.tools.shell.IO;
            import org.neo4j.graphdb.Transaction;
            import org.neo4j.helpers.Pair;
            import org.neo4j.server.database.Database;

            import java.util.logging.Logger;
            import java.util.logging.Level;
            import java.io.BufferedOutputStream;
            import java.io.ByteArrayOutputStream;
            import java.io.PrintStream;
            import java.util.ArrayList;
            import java.util.HashMap;
            import java.util.List;
            import java.util.Map;

            public class GremlinSession implements ScriptSession {
                    private static final String INIT_FUNCTION = "init()";
                    private static final Logger log = Logger.getLogger(GremlinSession.class.getName());
                    private final Database database;
                    private final IO io;
                    private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    private final List<String> initialBindings;
                    protected GremlinWebConsole scriptEngine;

                    public GremlinSession(Database database) {
                            this.database = database;
                            PrintStream out = new PrintStream(new BufferedOutputStream(baos));

                            io = new IO(System.in, out, out);

                            Map<String, Object> bindings = new HashMap<String, Object>();
                            bindings.put("g", getGremlinWrappedGraph());
                            bindings.put("out", out);

                            initialBindings = new ArrayList<String>(bindings.keySet());

                            try {
                                scriptEngine = new GremlinWebConsole(new Binding(bindings), io);
                            } catch (final Exception failure) {
                                scriptEngine = new GremlinWebConsole() {
                                    @Override
                                    public void execute(String script) {
                                        io.out.println("Could not start Groovy during Gremlin initialization, reason:");
                                        failure.printStackTrace(io.out);
                                    }
                                };
                            }
                    }

                    /**
                     * Take some gremlin script, evaluate it in the context of this gremlin
                     * session, and return the result.
                     *
                     * @param script
                     * @return the return string of the evaluation result, or the exception
                     *         message.
                     */
                    @Override
                    public Pair<String, String> evaluate(String script) {
                            String result = null;
                            try (Transaction tx = database.getGraph().beginTx()) {
                                if (script.equals(INIT_FUNCTION)) {
                                    result = init();
                                } else {
                                    try {
                                        scriptEngine.execute(script);
                                        result = baos.toString();
                                    } finally {
                                        resetIO();
                                    }
                                }
                                tx.success();
                            } catch (GroovyRuntimeException ex) {
                                log.log(Level.SEVERE, ex.toString());
                                result = ex.getMessage();
                            }
                            return Pair.of(result, null);
                    }

                    private String init() {
                            StringBuilder out = new StringBuilder();
                            out.append("\n");
                            out.append("         \\,,,/\n");
                            out.append("         (o o)\n");
                            out.append("-----oOOo-(_)-oOOo-----\n");
                            out.append("\n");

                            out.append("Available variables:\n");
                            for (String variable : initialBindings) {
                                out.append("  " + variable + "\t= ");
                                out.append(evaluate(variable));
                            }
                            out.append("\n");

                            return out.toString();
                    }

                    private void resetIO() {
                            baos.reset();
                    }

                    private TransactionalGraph getGremlinWrappedGraph() {
                            Neo4j2Graph neo4jGraph = null;
                            try {
                                neo4jGraph = new Neo4j2Graph(database.getGraph());
                            } catch (Exception e) {
                                throw new RuntimeException(e);
                            }
                            return neo4jGraph;
                    }
            }
bukzor commented 9 years ago

Similarly, I've installed the gremlin plugin, and although the curl shown in the README works, the console does not. I twiddled some xml to get a "Gremlin" button on the neo4j console page, but the prompt is "undefined" and any entry causes this stack trace in the logs:

==> /home/buck/prefices/brew/Cellar/neo4j/2.1.7/libexec/data/log/neo4j.1.0.log <==
Mar 28, 2015 10:38:04 PM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NoClassDefFoundError: Could not initialize class org.neo4j.server.webadmin.console.GremlinSession
    at org.neo4j.server.webadmin.console.GremlinSessionCreator.newSession(GremlinSessionCreator.java:35)
    at org.neo4j.server.rest.management.console.SessionFactoryImpl.getOrInstantiateSession(SessionFactoryImpl.java:76)
    at org.neo4j.server.rest.management.console.SessionFactoryImpl.createSession(SessionFactoryImpl.java:59)
    at org.neo4j.server.rest.management.console.ConsoleService.getSession(ConsoleService.java:149)
    at org.neo4j.server.rest.management.console.ConsoleService.exec(ConsoleService.java:126)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:211)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1096)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1030)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
    at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:445)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:268)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:229)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
    at java.lang.Thread.run(Thread.java:745)

==> /home/buck/prefices/brew/Cellar/neo4j/2.1.7/libexec/data/log/console.log <==
22:38:04.886 [qtp763677574-69] WARN  o.e.jetty.servlet.ServletHandler - 
javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initialize class org.neo4j.server.webadmin.console.GremlinSession
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699) ~[jersey-server-1.9.jar:1.9]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) ~[javax.servlet-3.0.0.v201112011016.jar:na]
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698) ~[jetty-servlet-9.0.5.v20130815.jar:9.0.5.v20130815]
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505) [jetty-servlet-9.0.5.v20130815.jar:9.0.5.v20130815]
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:211) [jetty-server-9.0.5.v20130815.jar:9.0.5.v20130815]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1096) [jetty-server-9.0.5.v20130815.jar:9.0.5.v20130815]
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432) [jetty-servlet-9.0.5.v20130815.jar:9.0.5.v20130815]
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175) [jetty-server-9.0.5.v20130815.jar:9.0.5.v20130815]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1030) [jetty-server-9.0.5.v20130815.jar:9.0.5.v20130815]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136) [jetty-server-9.0.5.v20130815.jar:9.0.5.v20130815]
    at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52) [jetty-server-9.0.5.v20130815.jar:9.0.5.v20130815]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [jetty-server-9.0.5.v20130815.jar:9.0.5.v20130815]
    at org.eclipse.jetty.server.Server.handle(Server.java:445) [jetty-server-9.0.5.v20130815.jar:9.0.5.v20130815]
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:268) [jetty-server-9.0.5.v20130815.jar:9.0.5.v20130815]
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:229) [jetty-server-9.0.5.v20130815.jar:9.0.5.v20130815]
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358) [jetty-io-9.0.5.v20130815.jar:9.0.5.v20130815]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601) [jetty-util-9.0.5.v20130815.jar:9.0.5.v20130815]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532) [jetty-util-9.0.5.v20130815.jar:9.0.5.v20130815]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_31]
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.neo4j.server.webadmin.console.GremlinSession
    at org.neo4j.server.webadmin.console.GremlinSessionCreator.newSession(GremlinSessionCreator.java:35) ~[neo4j-gremlin-plugin-2.1-SNAPSHOT.jar:2.1.7]
    at org.neo4j.server.rest.management.console.SessionFactoryImpl.getOrInstantiateSession(SessionFactoryImpl.java:76) ~[neo4j-server-2.1.7.jar:2.1.7]
    at org.neo4j.server.rest.management.console.SessionFactoryImpl.createSession(SessionFactoryImpl.java:59) ~[neo4j-server-2.1.7.jar:2.1.7]
    at org.neo4j.server.rest.management.console.ConsoleService.getSession(ConsoleService.java:149) ~[neo4j-server-2.1.7.jar:2.1.7]
    at org.neo4j.server.rest.management.console.ConsoleService.exec(ConsoleService.java:126) ~[neo4j-server-2.1.7.jar:2.1.7]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_31]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_31]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_31]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_31]
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) ~[jersey-server-1.9.jar:1.9]
    at org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139) ~[neo4j-server-2.1.7.jar:2.1.7]
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) ~[jersey-server-1.9.jar:1.9]
    ... 20 common frames omitted