1
votes

I'm new to neo4j and jersey. I'm trying to follow the neo4j documentation for using the Cypher endpoints in Java with Jersey to do simple queries from a server [1], [2]. My code is below [4]. As well as my pom.xml [5].

I keep running in into an error that I have seen a lot on the boards about a missing message body writer [6]. Several of the solutions involve editing the rest server code and adding annotations. I'm looking for a different solution as I plan to use a neo4j server as an out of the box graph database. I've included my pom as many of the other answers suggest including specific packages to fix the problem. I tried including those and saw so success.

Any ideas?

[1] http://neo4j.com/docs/2.2.3/cypher-intro-applications.html

[2] http://neo4j.com/docs/stable/server-java-rest-client-example.html#_creating_a_node

[4] String query = "MATCH (m:Movie) RETURN m";

String uri = host + "/db/data/transaction/commit";

String cypherStatements = "{\"statements\": [\"statement\":{"+query+"}]}";

WebResource resource = Client.create().resource((uri));

ClientResponse response = resource.accept(MediaType.APPLICATION_JSON)
    .type(MediaType.APPLICATION_JSON)
    .entity(cypherStatements)
    .post(ClientResponse.class);

System.out.println(String
    .format("PUT to [%s], status code [%d]", uri, response.getStatus()));

[5]

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<build>
    <plugins>
        <plugin>
            <!-- Assemble the jar file including all it's dependencies. This is nescesary
                for DataCleaner to load them all collectively. -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<repositories>
    <!--<repository>-->
        <!--<id>snapshot-repository.java.net</id>-->
        <!--<name>Java.net Snapshot Repository for Maven</name>-->
        <!--<url>https://maven.java.net/content/repositories/snapshots/</url>-->
        <!--<layout>default</layout>-->
    <!--</repository>-->
    <repository>
        <id>maven-repository.java.net</id>
        <name>Java.net Maven 1 Repository</name>
        <url>http://download.java.net/maven/2</url>
        <layout>legacy</layout>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.0</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.19</version>
    </dependency>
    <dependency>
        <groupId>com.owlike</groupId>
        <artifactId>genson</artifactId>
        <version>1.3</version>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.3.1</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.19</version>
    </dependency>

    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j</artifactId>
        <version>2.2.3</version>
    </dependency>

    <dependency>
        <!-- Include DataCleaner as a provided dependency -->
        <groupId>org.eobjects.datacleaner</groupId>
        <artifactId>DataCleaner-desktop-ui</artifactId>
        <version>4.0-RC3</version>
        <scope>provided</scope>
    </dependency>

    <!-- Test dependencies -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
</dependencies>

[6]

java.util.concurrent.ExecutionException: com.sun.jersey.api.client.ClientHandlerException: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class java.lang.String, and MIME media type, application/json, was not found

com.sun.jersey.api.client.ClientHandlerException: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class java.lang.String, and MIME media type, application/json, was not found

com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class java.lang.String, and MIME media type, application/json, was not found

A message body writer for Java type, class java.lang.String, and MIME media type, application/json, was not found

1

1 Answers

0
votes

Oh so it looks like you are using the client, but not defining an endpoint right? In this case you need to register the message body writer/reader with the client, auto discovery works only with server side.

With Genson you can do it this way.