spring-data-neo4j REST timeout

Showing 1-13 of 13 messages
spring-data-neo4j REST timeout Pamod len 8/23/12 1:00 AM
Hi All,
       In my project,I use spring-data-neo4j  to connect the neo4j server.
but when i use the java api method "template.getGraphDatabaseService().getAllNodes()",
I see error message like this:
Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: java.net.SocketTimeoutException: Read timed out
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:131)
at com.sun.jersey.api.client.Client.handle(Client.java:616)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:559)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:72)
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:494)
at org.neo4j.rest.graphdb.ExecutingRestRequest.post(ExecutingRestRequest.java:134)
at org.neo4j.rest.graphdb.ExecutingRestAPI.query(ExecutingRestAPI.java:404)
at org.neo4j.rest.graphdb.ExecutingRestAPI.query(ExecutingRestAPI.java:425)
at org.neo4j.rest.graphdb.RestAPIFacade.query(RestAPIFacade.java:230)
at org.neo4j.rest.graphdb.query.RestCypherQueryEngine.query(RestCypherQueryEngine.java:50)
at org.neo4j.rest.graphdb.RestGraphDatabase.getAllNodes(RestGraphDatabase.java:74)
at com.neo4j.util.DownloadData.downloadData(DownloadData.java:33)
at com.neo4j.main.MainTest.main(MainTest.java:16)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1049)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:218)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:129)
... 12 more

this is my applicationContext.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
xsi:schemaLocation="

<context:spring-configured />
<context:annotation-config />
<context:component-scan
base-package="org.springframework.data.neo4j.examples.hellograph" />

<neo4j:config graphDatabaseService="graphDatabaseService" />
<bean id="graphDatabaseService"
class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
<constructor-arg index="0" value="http://localhost:7474/db/data" />
</bean>

<neo4j:repositories base-package="org.springframework.data.neo4j.examples.hellograph" />

<bean id="neo4jTemplate" class="org.springframework.data.neo4j.support.Neo4jTemplate">
<constructor-arg ref="graphDatabaseService" />
</bean>

<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager">
<bean class="org.neo4j.kernel.impl.transaction.SpringTransactionManager">
<constructor-arg ref="graphDatabaseService" />
</bean>
</property>
<property name="userTransaction">
<bean class="org.neo4j.kernel.impl.transaction.UserTransactionImpl">
<constructor-arg ref="graphDatabaseService" />
</bean>
</property>
</bean>

<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" />
</beans>

this is my java:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;

import org.neo4j.graphdb.Node;
import org.springframework.data.neo4j.support.Neo4jTemplate;

import com.neo4j.main.ContextUtil;

public class DownloadData {
    public static BufferedReader bufread;
    private static String path = "D:/data.txt";
    private static File filename = new File(path);
    private static FileWriter fileWriter;
    private static BufferedWriter bw;

    
    private static Neo4jTemplate template = (Neo4jTemplate) ContextUtil.getContext().getBean("neo4jTemplate");

    @SuppressWarnings("deprecation")
    public static void downloadData() {
        System.out.println("test");
        try {
            creatTxtFile();
            fileWriter = new FileWriter(path);
            bw = new BufferedWriter(fileWriter);
            for (Node n : template.getGraphDatabaseService().getAllNodes()) {
                // Node n = db.getNodeById(2);
                System.out.println("Got node " + n);
                Iterator<String> it = n.getPropertyKeys().iterator();
                String str = "";
                while (it.hasNext()) {
                    String key = it.next();
                    str = str + " " + key + ":" + n.getProperty(key);
                }
                writeTxtFile(n.getId() + str);
            }
            fileWriter.flush();
            bw.close();
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            template.getGraphDatabaseService().shutdown();
        }
    }

    public static void creatTxtFile() throws IOException {
        if (!filename.exists()) {
            filename.createNewFile();
            System.err.println(filename + "is greated!");
        }
    }

    /**
     * write file.
     * 
     */
    public static void writeTxtFile(String newStr) throws IOException {
        bw.newLine();
        bw.write(newStr);
    }
}


please help me. Thanks.


Re: [Neo4j] spring-data-neo4j REST timeout Lasse Westh-Nielsen 8/23/12 1:21 AM
Pramod,

Can you try breaking down your problem.

1) separate reading from database from writing to file - does that work?
2) can you do even simple operations on the database, i.e. something not involving reading all nodes - i.e. testing your setup and config is in order

Regards,

Lasse






--
 
 

Re: [Neo4j] spring-data-neo4j REST timeout Michael Hunger 8/23/12 1:27 AM
Why don't you use <neo4j:config> as the configuration namespace but wire everything up yourself?

Why do you want to get all nodes?

It would be much better use a cypher statement

Iterable<Node> nodes = template.query("start n=node(*) return n").to(Node.class)

How many nodes are in your graph?

In the last java-rest-binding milestone (1.8.RC1) you can configure the connect and read-timeouts, see the readme:
So if you change your dependency to that (and probably exclude it in spring-data-neo4j-rest)
_timeouts in seconds_

* org.neo4j.rest.read_timeout=30
* org.neo4j.rest.connect_timeout=30
* org.neo4j.rest.driver="neo4j-rest-graphdb/1.8M07"
* org.neo4j.rest.stream=true

Am 23.08.2012 um 10:00 schrieb Pamod len:

--
 
 

Pamod len 8/23/12 1:28 AM <This message has been deleted.>
Re: [Neo4j] spring-data-neo4j REST timeout Pamod len 8/23/12 1:31 AM
Hi Lasse,
    thanks for your reply.
    If my java like this,use neo4j java api GraphDatabaseService
    It works normally.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.kernel.EmbeddedGraphDatabase;

public class DownloadData {
    
    public static BufferedReader bufread;
    private static String path = "D:/data.txt";
    private static File filename = new File(path);
    private static FileWriter fileWriter;
    private static BufferedWriter bw;
    private static final String DB_PATH = "D:/neo4j/data/data";
    private static GraphDatabaseService db = new EmbeddedGraphDatabase(DB_PATH);

    @SuppressWarnings("deprecation")
    public static void downloadData() {
        try {
            DownloadData.creatTxtFile();
            fileWriter = new FileWriter(path);
            bw = new BufferedWriter(fileWriter);
            for (Node n : db.getAllNodes()) {
                // Node n = db.getNodeById(2);
                System.out.println("Got node " + n);
                Iterator<String> it = n.getPropertyKeys().iterator();
                String str = "";
                while (it.hasNext()) {
                    String key = it.next();
                    str = str + " " + key + ":" + n.getProperty(key);
                }
                DownloadData.writeTxtFile(n.getId() + str);
            }
            fileWriter.flush();
            bw.close();
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void creatTxtFile() throws IOException {
        if (!filename.exists()) {
            filename.createNewFile();
            System.err.println(filename + "is greated!");
        }
    }

    public static void writeTxtFile(String newStr) throws IOException {
        bw.newLine();
        bw.write(newStr);
    }


Pamod len 8/23/12 1:36 AM <This message has been deleted.>
Re: [Neo4j] spring-data-neo4j REST timeout Michael Hunger 8/23/12 1:39 AM
Yes, but there is a big difference between a local in-process database and a remote database where all data has to be transported across the wire.

Michael

Am 23.08.2012 um 10:31 schrieb Pamod len:

--
 
 

Re: [Neo4j] spring-data-neo4j REST timeout Pamod len 8/23/12 1:41 AM
Hi Lasse,

It works normally when i use class org.neo4j.graphdb.GraphDatabaseService.
so....

Hi Michael,
Michael glad see you again,
do you remember my database index is lost.
so I must get all nodes for rebuild my index.
but my database version is 1.6.1 cant support node(*)

so....

Re: [Neo4j] spring-data-neo4j REST timeout Pamod len 8/23/12 1:47 AM
Hi Michael,

I do this only used to do a test, my real database can only connect with rest interface.

Re: [Neo4j] spring-data-neo4j REST timeout Michael Hunger 8/23/12 1:52 AM
Unfortunately this doesn't help you.

As the rest-graph-db uses cypher under the hood and the older versions don't support this method.

Why can't you just get the data/graph.db directory from the server and rebuild the index on that directory using an EmbeddedGraphDB ?

Otherwise you have to do it manually.

Get the #of nodes in your db from web-admin (first dashboard)

and in a for-loop do restGraphDB.getNodeById(id) and ignore those that have not been found.

Michael

Am 23.08.2012 um 10:41 schrieb Pamod len:
> --
>  
>  

Re: [Neo4j] spring-data-neo4j REST timeout Pamod len 8/23/12 2:15 AM
That is a nother way.
but I'm wondering, is there no way to let it not timeout?

在 2012年8月23日星期四UTC+8下午4时52分25秒,Michael Hunger写道:
Re: [Neo4j] spring-data-neo4j REST timeout Michael Hunger 8/23/12 2:22 AM
The default timeout is configured to 30 sec. which is more than enough in most cases. Which should also be fine for the manual approach described in the last email.

After all in your case it might even be that it is not a blocking timeout but rather an error occurring on the server side.

Your server is 1.6.1 ? What is the SDN/java-rest-binding version that you are using?

Michael

Am 23.08.2012 um 11:15 schrieb Pamod len:

--
 
 

Re: [Neo4j] spring-data-neo4j REST timeout Pamod len 8/23/12 2:54 AM
yes, my server is 1.6.1. but my project neo4j jar is 1.8.M06.
i cant know how to found the java-rest-binding version.
but i have spring-data-neo4j-rest-2.1.0.BUILD-SNAPSHOT.jar.

You mean the problem in version differences?
I will trying to change same version.


在 2012年8月23日星期四UTC+8下午5时22分04秒,Michael Hunger写道: