- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我用的是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.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));
}
}
这是我的错误信息,
{"Name":["John"]} Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:149) at com.sun.jersey.api.client.Client.handle(Client.java:648) at com.sun.jersey.api.client.WebResource.handle(WebResource.java:670) at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:553) at neo4j.rest.client.MyRestClient.createNode(MyRestClient.java:30) at neo4j.rest.client.MyRestClient.main(MyRestClient.java:14) Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:337) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391) at java.net.Socket.connect(Socket.java:579) at java.net.Socket.connect(Socket.java:528) at sun.net.NetworkClient.doConnect(NetworkClient.java:180) at sun.net.www.http.HttpClient.openServer(HttpClient.java:388) at sun.net.www.http.HttpClient.openServer(HttpClient.java:483) at sun.net.www.http.HttpClient.(HttpClient.java:213) at sun.net.www.http.HttpClient.New(HttpClient.java:300) at sun.net.www.http.HttpClient.New(HttpClient.java:316) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:992) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:928) at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:846) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1087) at com.sun.jersey.client.urlconnection.URLConnectionClientHandler$1$1.getOutputStream(URLConnectionClientHandler.java:225) at com.sun.jersey.api.client.CommittingOutputStream.commitWrite(CommittingOutputStream.java:117) at com.sun.jersey.api.client.CommittingOutputStream.write(CommittingOutputStream.java:89) at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221) at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291) at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295) at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141) at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229) at java.io.BufferedWriter.flush(BufferedWriter.java:254) at com.sun.jersey.core.util.ReaderWriter.writeToAsString(ReaderWriter.java:191) at com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider.writeToAsString(AbstractMessageReaderWriterProvider.java:128) at com.sun.jersey.core.impl.provider.entity.StringProvider.writeTo(StringProvider.java:88) at com.sun.jersey.core.impl.provider.entity.StringProvider.writeTo(StringProvider.java:58) at com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:300) at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:204) at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:147) ... 6 more
谢谢。
最佳答案
检查您的 Neo4j 服务器是否已启动并正在运行。打开http://localhost:7474即可在您的浏览器中。
如果您使用 Neo4j 的默认设置,您的代码将有效。因为授权是默认启用的。您有两个选择:
将授权 header 添加到您的请求中
client.addFilter(new HTTPBasicAuthFilter("neo4j","your_password"));
禁用授权
neo4j-server.properties
# Disable authorization
dbms.security.auth_enabled=false
关于java - 线程 "main"com.sun.jersey.api.client.ClientHandlerException : java.net.ConnectException 中的异常:连接被拒绝:连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33404538/
我在 REST 应用程序中使用 Jersey。我需要用 junit 来测试它。但我得到了一个com.sun.jersey.api.client.ClientHandlerException。堆栈跟踪:
我已经设置了 REST Web 服务和客户端。 Web 服务部署在 Glassfish 服务器上。如果我从 netbeans 运行客户端的主类,一切都会正常。现在我使用 Maven 创建一个可执行的
我正在使用 Jersey 客户端来访问 Spring MVC REST Controller 以实现图像上传功能。我收到以下异常: com.sun.jersey.api.client.ClientHa
我是 Docusign 新手,在我的 java 代码中生成 docusign token 时遇到以下问题: 异常(exception): com.sun.jersey.api.client.Clien
我正在使用 jersey api 客户端调用基于 REST 的网络服务(该服务托管在我的本地主机中)。当我打电话时 String entity = (client response object he
我在使用 Java DocuSignAPI 时遇到问题。该代码在 2.9.0 版中运行良好,但在更高版本中我得到一个 ClientHandlerException。我按照 DocuSign 网页上的
我用的是neo4j 2.2.4 我试试这个程序,这是我的测试代码 package neo4j.rest.client; import javax.ws.rs.core.MediaType; impor
我正在开发来自 http://www.javainuse.com/spring/spring-cloud-netflix-zuul-tutorial 的代码,还没有自定义。我不断收到下面提到的错误。因
我是一名优秀的程序员,十分优秀!