我正在使用MongoDb作为数据库构建Resteasy服务。
它在我的Mac上完美运行,但在测试服务器的Fedora 15上,它引发了如下错误:
07:20:15,060 WARNING [com.mongodb.tcp] (http--0.0.0.0-8000-1) Exception determining maxBSON size using0: java.io.IOException: couldn't connect to [eid/67.215.65.132:27017] bc:java.net.ConnectException: Connection timed out
at com.mongodb.DBPort._open(DBPort.java:228) [mongo-2.7.0.jar:]
at com.mongodb.DBPort.go(DBPort.java:112) [mongo-2.7.0.jar:]
at com.mongodb.DBPort.go(DBPort.java:93) [mongo-2.7.0.jar:]
at com.mongodb.DBPort.findOne(DBPort.java:146) [mongo-2.7.0.jar:]
at com.mongodb.DBPort.runCommand(DBPort.java:157) [mongo-2.7.0.jar:]
at com.mongodb.DBTCPConnector.fetchMaxBsonObjectSize(DBTCPConnector.java:457) [mongo-2.7.0.jar:]
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:444) [mongo-2.7.0.jar:]
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:209) [mongo-2.7.0.jar:]
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:305) [mongo-2.7.0.jar:]
at com.mongodb.DBCursor._check(DBCursor.java:369) [mongo-2.7.0.jar:]
at com.mongodb.DBCursor._hasNext(DBCursor.java:498) [mongo-2.7.0.jar:]
at com.mongodb.DBCursor.hasNext(DBCursor.java:523) [mongo-2.7.0.jar:]
at eid.ariel.TestService.getAllUsers(TestService.java:39) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_22]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [:1.6.0_22]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [:1.6.0_22]
at java.lang.reflect.Method.invoke(Method.java:616) [:1.6.0_22]
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:255) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:220) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:209) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:519) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:496) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) [resteasy-jaxrs-2.2.1.GA.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:139) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]
at org.jboss.as.web.NamingValve.invoke(NamingValve.java:57) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:154) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:952) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at java.lang.Thread.run(Thread.java:679) [:1.6.0_22]
访问db的代码是:
public List<DBObject> getAllUsers() throws UnknownHostException, MongoException, FileNotFoundException{
Mongo mongo = new Mongo("localhost");
DBCollection collection = mongo.getDB("eid_security_dev").getCollection("users");
DBCursor cur = collection.find();
List<DBObject> result = new ArrayList<DBObject>();
while (cur.hasNext()){
result.add(cur.next());
}
return result;
}
使用Mongo驱动程序2.7.0和mongodb server 2.0.0
答案 0 :(得分:1)
java.io.IOException: couldn't connect to [eid/67.215.65.132:27017] bc:java.net.ConnectException: Connection timed out
您的数据库客户端似乎无法连接到MongoDB服务器。需要调查的一些事项:
确保您的数据库服务器已启动并正在运行。
使用mongo
shell验证您的MongoDB服务器是否完全正常运行。
67.215.65.132
是公共IP地址。 localhost
通常应解析为地址为127.0.0.1
或类似的环回接口。请直接尝试使用127.0.0.1
,因为使用公共IP可能意味着存在阻止访问数据库服务器端口的防火墙规则。连接超时而非被拒绝使得这种情况非常可能。
答案 1 :(得分:0)
See here。例如,您正在使用OpenDNS为未知主机返回此IP。