2013-02-22 71 views
1

jax-rs REST服務有問題。REST服務每工作一次請求

服務無法正常運行。每秒請求服務都會拋出異常:

HTTP Status 500 - could not execute query 

type Exception report 

message could not execute query 

description The server encountered an internal error that prevented it from fulfilling this request. 

exception 

org.hibernate.exception.JDBCConnectionException: could not execute query 
    org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74) 
    org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) 
    org.hibernate.loader.Loader.doList(Loader.java:2147) 
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028) 
    org.hibernate.loader.Loader.list(Loader.java:2023) 
    org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95) 
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569) 
    org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283) 
    com.fit.utilities.BaseDAO.getAll_fetchEager(BaseDAO.java:62) 
    com.fit.utilities.BaseDAO.getAll(BaseDAO.java:37) 
    com.fit.servis.Korisnik_servis.PronadjiPrijatelje(Korisnik_servis.java:174) 
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    java.lang.reflect.Method.invoke(Unknown Source) 
    com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) 
    com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185) 
    com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) 
    com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288) 
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) 
    com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) 
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) 
    com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) 
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1483) 
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1414) 
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1363) 
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1353) 
    com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414) 
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) 
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
root cause 

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.Connection was implicitly closed by the driver. 
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
    java.lang.reflect.Constructor.newInstance(Unknown Source) 
    com.mysql.jdbc.Util.handleNewInstance(Util.java:409) 
    com.mysql.jdbc.Util.getInstance(Util.java:384) 
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015) 
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989) 
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984) 
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929) 
    com.mysql.jdbc.ConnectionImpl.throwConnectionClosedException(ConnectionImpl.java:1204) 
    com.mysql.jdbc.ConnectionImpl.checkClosed(ConnectionImpl.java:1191) 
    com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4276) 
    com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4242) 
    org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:497) 
    org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:415) 
    org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139) 
    org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1560) 
    org.hibernate.loader.Loader.doQuery(Loader.java:661) 
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) 
    org.hibernate.loader.Loader.doList(Loader.java:2144) 
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028) 
    org.hibernate.loader.Loader.list(Loader.java:2023) 
    org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95) 
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569) 
    org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283) 
    com.fit.utilities.BaseDAO.getAll_fetchEager(BaseDAO.java:62) 
    com.fit.utilities.BaseDAO.getAll(BaseDAO.java:37) 
    com.fit.servis.Korisnik_servis.PronadjiPrijatelje(Korisnik_servis.java:174) 
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    java.lang.reflect.Method.invoke(Unknown Source) 
    com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) 
    com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185) 
    com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) 
    com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288) 
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) 
    com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) 
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) 
    com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) 
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1483) 
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1414) 
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1363) 
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1353) 
    com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414) 
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) 
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
root cause 

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 22.477.953 milliseconds ago. The last packet sent successfully to the server was 22.478.000 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem. 
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
    java.lang.reflect.Constructor.newInstance(Unknown Source) 
    com.mysql.jdbc.Util.handleNewInstance(Util.java:409) 
    com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1122) 
    com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3317) 
    com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1941) 
    com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2114) 
    com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2696) 
    com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2105) 
    com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2264) 
    org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186) 
    org.hibernate.loader.Loader.getResultSet(Loader.java:1668) 
    org.hibernate.loader.Loader.doQuery(Loader.java:662) 
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) 
    org.hibernate.loader.Loader.doList(Loader.java:2144) 
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028) 
    org.hibernate.loader.Loader.list(Loader.java:2023) 
    org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95) 
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569) 
    org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283) 
    com.fit.utilities.BaseDAO.getAll_fetchEager(BaseDAO.java:62) 
    com.fit.utilities.BaseDAO.getAll(BaseDAO.java:37) 
    com.fit.servis.Korisnik_servis.Login(Korisnik_servis.java:32) 
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    java.lang.reflect.Method.invoke(Unknown Source) 
    com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) 
    com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185) 
    com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) 
    com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288) 
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) 
    com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) 
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) 
    com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) 
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1483) 
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1414) 
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1363) 
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1353) 
    com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414) 
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) 
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
root cause 

java.net.SocketException: Software caused connection abort: socket write error 
    java.net.SocketOutputStream.socketWrite0(Native Method) 
    java.net.SocketOutputStream.socketWrite(Unknown Source) 
    java.net.SocketOutputStream.write(Unknown Source) 
    java.io.BufferedOutputStream.flushBuffer(Unknown Source) 
    java.io.BufferedOutputStream.flush(Unknown Source) 
    com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3298) 
    com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1941) 
    com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2114) 
    com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2696) 
    com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2105) 
    com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2264) 
    org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186) 
    org.hibernate.loader.Loader.getResultSet(Loader.java:1668) 
    org.hibernate.loader.Loader.doQuery(Loader.java:662) 
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) 
    org.hibernate.loader.Loader.doList(Loader.java:2144) 
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028) 
    org.hibernate.loader.Loader.list(Loader.java:2023) 
    org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95) 
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569) 
    org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283) 
    com.fit.utilities.BaseDAO.getAll_fetchEager(BaseDAO.java:62) 
    com.fit.utilities.BaseDAO.getAll(BaseDAO.java:37) 
    com.fit.servis.Korisnik_servis.Login(Korisnik_servis.java:32) 
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    java.lang.reflect.Method.invoke(Unknown Source) 
    com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) 
    com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185) 
    com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) 
    com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288) 
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) 
    com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) 
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) 
    com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) 
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1483) 
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1414) 
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1363) 
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1353) 
    com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414) 
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) 
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.32 logs. 

Apache Tomcat/7.0.32 

服務檢索JSON ..我認爲問題是由於字節大小的字符串。

成功的典範檢索:

example

如何解決這個問題呢?

+1

這與REST或JAX-WS的錯誤標記無關。這是一個數據層問題。你需要處理MySQL的超時設置以保持連接的存活時間更長 – kolossus 2013-02-22 17:07:11

回答

1

問題出在你的mysql數據源配置中。嘗試將這兩個參數添加到數據源定義:

testOnBorrow="true" validationQuery="select 1" 
+0

非常感謝!現在完美工作:)。 – 2013-02-22 17:17:37

1

我想這是服務器端問題。它清晰可見你的類BaseDAO執行方法getAll_fetchEager在這種方法中,你正在做一些標準查詢,由於某種原因失敗。我相信如果你更正你的標準查詢問題就會解決。嘗試找出正確設置的連接屬性,並且可以連接數據庫。

+0

+1爲解答...... – 2013-02-22 17:18:58

1

我認爲答案是在堆棧跟蹤。

成功從服務器接收到的最後一個數據包是22.477.953毫秒前。成功發送到服務器的最後一個數據包是22.478.000毫秒前。比服務器配置的'wait_timeout'值長。在應用程序中使用之前,應考慮過期和/或測試連接有效性,增加服務器配置的客戶端超時值,或者使用Connector/J連接屬性'autoReconnect = true'來避免此問題。

與您的mysql的連接未保持打開狀態,且未設置爲自動重新連接。

+0

+1爲回答.... – 2013-02-22 17:19:37