java json

272 views
Skip to first unread message

Alex Frieden

unread,
Jul 26, 2013, 10:24:25 AM7/26/13
to ne...@googlegroups.com
Hi all,
Trying to get a basic java get request to get json back from a cypher query via rest.  Localhost is running at http://localhost:7474.  All I need is a basic working example.  

Peter Neubauer

unread,
Jul 26, 2013, 10:29:24 AM7/26/13
to Neo4j User


Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Kids in Malmö this summer?        - http://www.kidscraft.se
Neo4j questions? Use GraphGist. - http://gist.neo4j.org


On Fri, Jul 26, 2013 at 4:24 PM, Alex Frieden <al...@frieden.org> wrote:
Hi all,
Trying to get a basic java get request to get json back from a cypher query via rest.  Localhost is running at http://localhost:7474.  All I need is a basic working example.  

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Luanne Coutinho

unread,
Jul 26, 2013, 10:29:48 AM7/26/13
to ne...@googlegroups.com
Hope it helps.

-Luanne


On Fri, Jul 26, 2013 at 7:54 PM, Alex Frieden <al...@frieden.org> wrote:
Hi all,
Trying to get a basic java get request to get json back from a cypher query via rest.  Localhost is running at http://localhost:7474.  All I need is a basic working example.  

--

Alex Frieden

unread,
Jul 26, 2013, 10:50:07 AM7/26/13
to ne...@googlegroups.com
Tried out the code, doesn't seem to work

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.rest.graphdb.RestAPI;
import org.neo4j.rest.graphdb.RestAPIFacade;
import org.neo4j.rest.graphdb.RestGraphDatabase;
import org.neo4j.rest.graphdb.entity.RestNode;
import org.neo4j.rest.graphdb.query.QueryEngine;
import org.neo4j.rest.graphdb.query.RestCypherQueryEngine;
import org.neo4j.rest.graphdb.util.QueryResult;
import static org.neo4j.helpers.collection.MapUtil.map;

import java.util.Collections;
import java.util.Iterator;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: afrieden
 * Date: 6/11/13
 * Time: 8:49 AM
 * To change this template use File | Settings | File Templates.
 */
public class Connect {
    public static void main(String[] args) {
        System.out.println("starting test");
        GraphDatabaseService graphDb= new RestGraphDatabase("http://localhost:7474/db/data");
        System.out.println("API created");
        RestAPI api = new RestAPIFacade("http://localhost:7474/db/data");
        QueryEngine engine=new RestCypherQueryEngine(api);
        QueryResult<Map<String,Object>> result=
                engine.query("start n=node(*) return count(n) as total", Collections.EMPTY_MAP);
        Iterator<Map<String, Object>> iterator=result.iterator();
        if(iterator.hasNext()) {
            Map<String,Object> row= iterator.next();
            System.out.print("Total nodes: " + row.get("total"));
        }
    }
}



Just getting 

starting test
Exception in thread "main" java.lang.NoClassDefFoundError: javax/ws/rs/core/Response$StatusType
at org.neo4j.rest.graphdb.RestAPIFacade.<init>(RestAPIFacade.java:294)
at org.neo4j.rest.graphdb.RestGraphDatabase.<init>(RestGraphDatabase.java:44)
at Connect.main(Connect.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.core.Response$StatusType
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 8 more

Process finished with exit code 1


--
You received this message because you are subscribed to a topic in the Google Groups "Neo4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/neo4j/SFHe_QdzBGE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to neo4j+un...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Alexander Frieden

Luanne Coutinho

unread,
Jul 26, 2013, 10:54:48 AM7/26/13
to ne...@googlegroups.com
You included the jar directly or used maven to include it? If you included the jar directly then you might need more dependencies. See http://stackoverflow.com/questions/17883077/neo4j-rest-api-not-working/

Peter Neubauer

unread,
Jul 26, 2013, 10:55:32 AM7/26/13
to Neo4j User
Seems you are not having the javax.ws classes on your classpath.


Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Kids in Malmö this summer?        - http://www.kidscraft.se
Neo4j questions? Use GraphGist. - http://gist.neo4j.org


Alex Frieden

unread,
Jul 26, 2013, 10:58:07 AM7/26/13
to ne...@googlegroups.com
Okay let me add those in.  The java-rest-bindings was built with all the dependencies, shouldn't those dependencies then be included if you don't add any other ones?  This is going to go in a grails application and I am not sure how to add a maven pom to a grails application or what ramifications it would have with the plugins.  

Alex Frieden

unread,
Jul 26, 2013, 11:06:26 AM7/26/13
to ne...@googlegroups.com
I am also not married to using the API.  I would be happy with using something else.  I just need it to work!
--
Alexander Frieden

Michael Hunger

unread,
Jul 26, 2013, 11:18:36 AM7/26/13
to ne...@googlegroups.com
If you just want to use grails with neo4j's rest endpoint, you probably don't need much.

With 1.9 just go against /db/data/cypher post your query with params and get the results back,

Groovy has some nice json builders and parsers that make life easy for you.

With 2.0 the transactional endpoint is even better as it is more efficient and supports cross request transactions.

You might want to look into the neo4j-jdbc driver too, which you then can you with the groovy / sql libs.


Michael

Alex Frieden

unread,
Jul 26, 2013, 12:18:02 PM7/26/13
to ne...@googlegroups.com
Thanks Michael!  Do you have a working example of this in groovy?  Thanks!

Stefan Armbruster

unread,
Jul 27, 2013, 5:03:05 AM7/27/13
to ne...@googlegroups.com

Alex Frieden

unread,
Jul 27, 2013, 8:59:28 AM7/27/13
to ne...@googlegroups.com
Great!  Is there a JDBC 2.0 driver out there yet?

Michael Hunger

unread,
Jul 27, 2013, 10:05:54 AM7/27/13
to ne...@googlegroups.com
Yep, there is a branch for 2.0 
you can build it with maven 
should be fully functional including transaction handling



Sent from mobile device
Reply all
Reply to author
Forward
0 new messages