“线程中的异常”;“主要”;com.sun.jersey.api.client.clienthandler异常:java.net.ConnectException:连接被拒绝:连接
我使用neo4j 2.2.4 我尝试了这个程序,这是我的测试代码“线程中的异常”;“主要”;com.sun.jersey.api.client.clienthandler异常:java.net.ConnectException:连接被拒绝:连接,java,neo4j,Java,Neo4j,我使用neo4j 2.2.4 我尝试了这个程序,这是我的测试代码 package neo4j.rest.client; import javax.ws.rs.core.MediaType; import org.json.JSONObject; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebR
package neo4j.rest.client;
import javax.ws.rs.core.MediaType;
import org.json.JSONObject;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
public class MyRestClient {
public static void main(String[] args) {
MyRestClient jersey = new MyRestClient();
jersey.createNode();
jersey.sendCypher();
}
public void createNode(){
//Create a REST Client
Client client = Client.create();
//Define a resource (REST Endpoint) which needs to be Invoked
//for creating a Node
WebResource resource = client.resource("http://localhost:7474").path("/db/data/node");
//Define properties for the node.
JSONObject node = new JSONObject();
node.append("Name", "John");
System.out.println(node.toString());
//Invoke the rest endpoint as JSON request
ClientResponse res = resource.accept(MediaType.APPLICATION_JSON)
.entity(node.toString())
.post(ClientResponse.class);
//Print the URI of the new Node
System.out.println("URI of New Node = " + res.getLocation());
}
public void sendCypher() {
//Create a REST Client
Client client = Client.create();
//Define a resource (REST Endpoint) which needs to be Invoked
//for executing Cypher Query
WebResource resource = client.resource("http://localhost:7474").path("/db/data/cypher");
//Define JSON Object and Cypher Query
JSONObject cypher = new JSONObject();
cypher.accumulate("query", "match n return n limit 10");
//Invoke the rest endpoint as JSON request
ClientResponse res = resource.accept(MediaType.APPLICATION_JSON).entity(cypher.toString())
.post(ClientResponse.class);
//Print the response received from the Server
System.out.println(res.getEntity(String.class));
}
}
这是我的错误信息
{“姓名”:[“约翰”]}
线程“main”com.sun.jersey.api.client.clienthandler异常:java.net.ConnectException:连接被拒绝:connect
位于com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:149)
位于com.sun.jersey.api.client.client.handle(client.java:648)
位于com.sun.jersey.api.client.WebResource.handle(WebResource.java:670)
com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
位于com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:553)
位于neo4j.rest.client.MyRestClient.createNode(MyRestClient.java:30)
位于neo4j.rest.client.MyRestClient.main(MyRestClient.java:14)
原因:java.net.ConnectException:连接被拒绝:连接
位于java.net.DualStackPlainSocketImpl.connect0(本机方法)
位于java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
位于java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:337)
位于java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198)
位于java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
位于java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
位于java.net.socksocketimpl.connect(socksocketimpl.java:391)
位于java.net.Socket.connect(Socket.java:579)
位于java.net.Socket.connect(Socket.java:528)
位于sun.net.NetworkClient.doConnect(NetworkClient.java:180)
位于sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
位于sun.net.www.http.HttpClient.openServer(HttpClient.java:483)
http.HttpClient.(HttpClient.java:213)
http.HttpClient.New(HttpClient.java:300)
http.HttpClient.New(HttpClient.java:316)
位于sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:992)
位于sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:928)
位于sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:846)
位于sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1087)
位于com.sun.jersey.client.urlconnection.URLConnectionClientHandler$1$1.getOutputStream(URLConnectionClientHandler.java:225)
位于com.sun.jersey.api.client.committengoutputstream.commitWrite(committengoutputstream.java:117)
位于com.sun.jersey.api.client.committengoutputstream.write(committengoutputstream.java:89)
在sun.nio.cs.streamncoder.writeBytes上(streamncoder.java:221)
位于sun.nio.cs.streamncoder.implFlushBuffer(streamncoder.java:291)
位于sun.nio.cs.streamncoder.implFlush(streamncoder.java:295)
位于sun.nio.cs.streamncoder.flush(streamncoder.java:141)
位于java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
位于java.io.BufferedWriter.flush(BufferedWriter.java:254)
位于com.sun.jersey.core.util.ReaderWriter.writeToAsString(ReaderWriter.java:191)
位于com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider.writeToAsString(AbstractMessageReaderWriterProvider.java:128)
位于com.sun.jersey.core.impl.provider.entity.StringProvider.writeTo(StringProvider.java:88)
位于com.sun.jersey.core.impl.provider.entity.StringProvider.writeTo(StringProvider.java:58)
位于com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:300)
在com.sun.jersey.client.urlconnection.URLConnectionClientHandler.\u调用(URLConnectionClientHandler.java:204)
位于com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:147)
... 还有6个
谢谢。- 检查Neo4j服务器是否已启动并正在运行。只需在浏览器中打开即可
- 如果您使用Neo4j的默认设置,您的代码将正常工作。因为默认情况下启用了授权。您有两个选择:
- 将授权标头添加到您的请求中
addFilter(新的HTTPBasicAuthFilter(“neo4j”,“您的_密码”))
- 禁用授权
# Disable authorization
dbms.security.auth_enabled=false
您确定您的服务器正在运行并且可以访问吗?