I am facing an odd issue in some of environments of UAT and PROD, but not in SIT. It seems to be a configuration related issue to me. Though all the settings, configuration verified are same.
Getting 'Closed Statement: next' SQLException while trying to loop over a result set with a while (rs.next()).
Code snippet, error stack trace, version details are provided below.
Existing code:
import org.apache.lucene.index.IndexWriter;
#SuppressWarnings("deprecation")
#Transactional(propagation = Propagation.REQUIRED)
private boolean fetchAndInsertData(final String indexType, final IndexWriter indexWriter) throws Exception {
logger.info("Entering fetchAndInsertData()");
Transaction tx = null;
boolean success = false;
CallableStatement callstmt = null;
ResultSet rs = null;
try {
tx = this.getCurrentSession().beginTransaction();
callstmt = this.getCurrentSession().connection().prepareCall("{call GET_VAL_PROC(?,?)}");
callstmt.setString(1, indexType);
callstmt.registerOutParameter(2, OracleTypes.CURSOR);
callstmt.execute();
rs = (ResultSet) callstmt.getObject(2);
rs.setFetchSize(5000);
logger.info("Resultset:"+ rs);
while (rs.next()) {
indexWriter.addDocument(convertResultToDoc(rs));
}
success = true;
} catch(SQLException e){
logger.error("Error in SQL execute", e);
success = false;
tx.commit();
return success;
} catch (final Exception e) {
logger.error("Getting Exception", e);
success = false;
} finally {
tx.commit();
}
logger.info("Exiting fetchAndInsertData()");
return success;
}
private Document convertResultToDoc(ResultSet results) throws SQLException {
final Document doc = new Document();
final String resultKey = results.getString(1) != null ? results.getString(1).toString() : null;
final String resultValue = results.getString(2) != null ? results.getString(2).toString() : null;
doc.add(new TextField("resultKey", resultKey, Field.Store.YES));
doc.add(new TextField("resultValue", resultValue, Field.Store.YES));
return doc;
}
Error stack trace:
java.sql.SQLException: Closed Statement: next
at
oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:263)
at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:271)
at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:205)
at com.ville.dao.SomeDaoImpl.fetchAndInsertData(SomeDaoImpl.java:263)
at com.ville.dao.SomeDaoImpl.createIndex(SomeDaoImpl.java:227)
at com.ville.dao.SomeDaoImpl.getDetails(SomeDaoImpl.java:375)
at com.ville.service.ServiceImpl.serviceCreateIndex(ServiceImpl.java:32)
at com.ville.service.WSControl.controlCreateIndex(WSControl.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.ville.filter.MultiRequestWrapperFilter.doFilter(MultiRequestWrapperFilter.java:30)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.ville.filter.HttpInterceptorFilter.doFilter(HttpInterceptorFilter.java:36)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1103)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1477)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
2018-07-13 07:02:56 INFO [http-nio-21290-exec-3] SomeDaoImpl - Exiting SomeDaoImpl.fetchAndInsertData()
2018-07-13 07:02:56 ERROR [http-nio-21290-exec-3] GlobalDefaultExceptionHandler - RestError [status=500, id=-1, message=Transaction not successfully started, developerMessage=org.hibernate.TransactionException: Transaction not successfully started
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:127)
at com.ville.dao.SomeDaoImpl.fetchAndInsertData(SomeDaoImpl.java:281)
at com.ville.dao.SomeDaoImpl.createIndex(SomeDaoImpl.java:227)
at com.ville.dao.SomeDaoImpl.getDetails(SomeDaoImpl.java:375)
at com.ville.service.ServiceImpl.serviceCreateIndex(ServiceImpl.java:32)
at com.ville.service.WSControl.controlCreateIndex(WSControl.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.ville.filter.MultiRequestWrapperFilter.doFilter(MultiRequestWrapperFilter.java:30)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.ville.filter.HttpInterceptorFilter.doFilter(HttpInterceptorFilter.java:36)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1103)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1477)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Version details:
Tomcat Version: 8.0.18_1
JRE : 1.8.0_111l64
OJDBC6.jar with JDBC : 11.1.0.7.0-Production
Oracle DB Version: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
Existing config in context.xml
Resource name="jdbc/SomeDS"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:#DbUrlWithPortNameEtc"
username="***"
password="********"
connectionProperties="SetBigStringTryClob=true"
accessToUnderlyingConnectionAllowed="true"
maxTotal="30"
maxIdle="10"
initialSize="5"
maxWaitMillis="180000"
I have configured maven, JDK and clone Sakai from github. Everything works fine, but when I click on lesson the system throws following error
Fatal internal error handling request:
Target exception of class org.springframework.jdbc.BadSqlGrammarException
Successive lines until stack trace show causes progressing to exception site:
PreparedStatementCallback; bad SQL grammar [SELECT lti_tools.id AS id, lti_tools.version AS version, lti_tools.SITE_ID AS SITE_ID, lti_tools.title AS title, lti_tools.allowtitle AS allowtitle, lti_tools.fa_icon AS fa_icon, lti_tools.pagetitle AS pagetitle, lti_tools.allowpagetitle AS allowpagetitle, lti_tools.description AS description, lti_tools.status AS status, lti_tools.visible AS visible, lti_tools.resource_handler AS resource_handler, lti_tools.deployment_id AS deployment_id, lti_tools.launch AS launch, lti_tools.allowlaunch AS allowlaunch, lti_tools.consumerkey AS consumerkey, lti_tools.allowconsumerkey AS allowconsumerkey, lti_tools.secret AS secret, lti_tools.allowsecret AS allowsecret, lti_tools.frameheight AS frameheight, lti_tools.allowframeheight AS allowframeheight, lti_tools.siteinfoconfig AS siteinfoconfig, lti_tools.sendname AS sendname, lti_tools.sendemailaddr AS sendemailaddr, lti_tools.allowoutcomes AS allowoutcomes, lti_tools.allowroster AS allowroster, lti_tools.allowsettings AS allowsettings, lti_tools.pl_launch AS pl_launch, lti_tools.pl_linkselection AS pl_linkselection, lti_tools.pl_contenteditor AS pl_contenteditor, lti_tools.pl_importitem AS pl_importitem, lti_tools.pl_fileitem AS pl_fileitem, lti_tools.pl_assessmentselection AS pl_assessmentselection, lti_tools.newpage AS newpage, lti_tools.debug AS debug, lti_tools.custom AS custom, lti_tools.settings AS settings, lti_tools.parameter AS parameter, lti_tools.tool_proxy_binding AS tool_proxy_binding, lti_tools.allowcustom AS allowcustom, lti_tools.xmlimport AS xmlimport, lti_tools.splash AS splash, lti_tools.created_at AS created_at, lti_tools.updated_at AS updated_at FROM lti_tools WHERE (lti_tools.SITE_ID = ? OR (lti_tools.SITE_ID IS NULL AND lti_tools.visible != 1 ) ) AND (lti_tools.pl_importitem = 1) ORDER BY lti_tools.id]; nested exception is java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: LTI_TOOLS in statement [SELECT lti_tools.id AS id, lti_tools.version AS version, lti_tools.SITE_ID AS SITE_ID, lti_tools.title AS title, lti_tools.allowtitle AS allowtitle, lti_tools.fa_icon AS fa_icon, lti_tools.pagetitle AS pagetitle, lti_tools.allowpagetitle AS allowpagetitle, lti_tools.description AS description, lti_tools.status AS status, lti_tools.visible AS visible, lti_tools.resource_handler AS resource_handler, lti_tools.deployment_id AS deployment_id, lti_tools.launch AS launch, lti_tools.allowlaunch AS allowlaunch, lti_tools.consumerkey AS consumerkey, lti_tools.allowconsumerkey AS allowconsumerkey, lti_tools.secret AS secret, lti_tools.allowsecret AS allowsecret, lti_tools.frameheight AS frameheight, lti_tools.allowframeheight AS allowframeheight, lti_tools.siteinfoconfig AS siteinfoconfig, lti_tools.sendname AS sendname, lti_tools.sendemailaddr AS sendemailaddr, lti_tools.allowoutcomes AS allowoutcomes, lti_tools.allowroster AS allowroster, lti_tools.allowsettings AS allowsettings, lti_tools.pl_launch AS pl_launch, lti_tools.pl_linkselection AS pl_linkselection, lti_tools.pl_contenteditor AS pl_contenteditor, lti_tools.pl_importitem AS pl_importitem, lti_tools.pl_fileitem AS pl_fileitem, lti_tools.pl_assessmentselection AS pl_assessmentselection, lti_tools.newpage AS newpage, lti_tools.debug AS debug, lti_tools.custom AS custom, lti_tools.settings AS settings, lti_tools.parameter AS parameter, lti_tools.tool_proxy_binding AS tool_proxy_binding, lti_tools.allowcustom AS allowcustom, lti_tools.xmlimport AS xmlimport, lti_tools.splash AS splash, lti_tools.created_at AS created_at, lti_tools.updated_at AS updated_at FROM lti_tools WHERE (lti_tools.SITE_ID = ? OR (lti_tools.SITE_ID IS NULL AND lti_tools.visible != 1 ) ) AND (lti_tools.pl_importitem = 1) ORDER BY lti_tools.id]
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT lti_tools.id AS id, lti_tools.version AS version, lti_tools.SITE_ID AS SITE_ID, lti_tools.title AS title, lti_tools.allowtitle AS allowtitle, lti_tools.fa_icon AS fa_icon, lti_tools.pagetitle AS pagetitle, lti_tools.allowpagetitle AS allowpagetitle, lti_tools.description AS description, lti_tools.status AS status, lti_tools.visible AS visible, lti_tools.resource_handler AS resource_handler, lti_tools.deployment_id AS deployment_id, lti_tools.launch AS launch, lti_tools.allowlaunch AS allowlaunch, lti_tools.consumerkey AS consumerkey, lti_tools.allowconsumerkey AS allowconsumerkey, lti_tools.secret AS secret, lti_tools.allowsecret AS allowsecret, lti_tools.frameheight AS frameheight, lti_tools.allowframeheight AS allowframeheight, lti_tools.siteinfoconfig AS siteinfoconfig, lti_tools.sendname AS sendname, lti_tools.sendemailaddr AS sendemailaddr, lti_tools.allowoutcomes AS allowoutcomes, lti_tools.allowroster AS allowroster, lti_tools.allowsettings AS allowsettings, lti_tools.pl_launch AS pl_launch, lti_tools.pl_linkselection AS pl_linkselection, lti_tools.pl_contenteditor AS pl_contenteditor, lti_tools.pl_importitem AS pl_importitem, lti_tools.pl_fileitem AS pl_fileitem, lti_tools.pl_assessmentselection AS pl_assessmentselection, lti_tools.newpage AS newpage, lti_tools.debug AS debug, lti_tools.custom AS custom, lti_tools.settings AS settings, lti_tools.parameter AS parameter, lti_tools.tool_proxy_binding AS tool_proxy_binding, lti_tools.allowcustom AS allowcustom, lti_tools.xmlimport AS xmlimport, lti_tools.splash AS splash, lti_tools.created_at AS created_at, lti_tools.updated_at AS updated_at FROM lti_tools WHERE (lti_tools.SITE_ID = ? OR (lti_tools.SITE_ID IS NULL AND lti_tools.visible != 1 ) ) AND (lti_tools.pl_importitem = 1) ORDER BY lti_tools.id]; nested exception is java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: LTI_TOOLS in statement [SELECT lti_tools.id AS id, lti_tools.version AS version, lti_tools.SITE_ID AS SITE_ID, lti_tools.title AS title, lti_tools.allowtitle AS allowtitle, lti_tools.fa_icon AS fa_icon, lti_tools.pagetitle AS pagetitle, lti_tools.allowpagetitle AS allowpagetitle, lti_tools.description AS description, lti_tools.status AS status, lti_tools.visible AS visible, lti_tools.resource_handler AS resource_handler, lti_tools.deployment_id AS deployment_id, lti_tools.launch AS launch, lti_tools.allowlaunch AS allowlaunch, lti_tools.consumerkey AS consumerkey, lti_tools.allowconsumerkey AS allowconsumerkey, lti_tools.secret AS secret, lti_tools.allowsecret AS allowsecret, lti_tools.frameheight AS frameheight, lti_tools.allowframeheight AS allowframeheight, lti_tools.siteinfoconfig AS siteinfoconfig, lti_tools.sendname AS sendname, lti_tools.sendemailaddr AS sendemailaddr, lti_tools.allowoutcomes AS allowoutcomes, lti_tools.allowroster AS allowroster, lti_tools.allowsettings AS allowsettings, lti_tools.pl_launch AS pl_launch, lti_tools.pl_linkselection AS pl_linkselection, lti_tools.pl_contenteditor AS pl_contenteditor, lti_tools.pl_importitem AS pl_importitem, lti_tools.pl_fileitem AS pl_fileitem, lti_tools.pl_assessmentselection AS pl_assessmentselection, lti_tools.newpage AS newpage, lti_tools.debug AS debug, lti_tools.custom AS custom, lti_tools.settings AS settings, lti_tools.parameter AS parameter, lti_tools.tool_proxy_binding AS tool_proxy_binding, lti_tools.allowcustom AS allowcustom, lti_tools.xmlimport AS xmlimport, lti_tools.splash AS splash, lti_tools.created_at AS created_at, lti_tools.updated_at AS updated_at FROM lti_tools WHERE (lti_tools.SITE_ID = ? OR (lti_tools.SITE_ID IS NULL AND lti_tools.visible != 1 ) ) AND (lti_tools.pl_importitem = 1) ORDER BY lti_tools.id]
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:91)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:649)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:684)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:716)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:726)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:776)
at org.sakaiproject.lti.impl.DBLTIService.getResultSet(DBLTIService.java:1050)
at org.sakaiproject.lti.impl.DBLTIService.getThingsDao(DBLTIService.java:810)
at org.sakaiproject.lti.impl.DBLTIService.getToolsDao(DBLTIService.java:228)
at org.sakaiproject.lti.impl.BaseLTIService.getTools(BaseLTIService.java:528)
at org.sakaiproject.lti.impl.BaseLTIService.getToolsImportItem(BaseLTIService.java:554)
at org.sakaiproject.lessonbuildertool.tool.beans.SimplePageBean.getToolsImportItem(SimplePageBean.java:6471)
at org.sakaiproject.lessonbuildertool.tool.producers.ShowPageProducer.fillComponents(ShowPageProducer.java:767)
at uk.org.ponder.rsf.view.support.ViewCollector.fillComponents(ViewCollector.java:56)
at uk.org.ponder.rsf.view.support.LayoutCollector.fillComponents(LayoutCollector.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy227.fillComponents(Unknown Source)
at uk.org.ponder.rsf.view.support.ViewGenerator.generateView(ViewGenerator.java:53)
at uk.org.ponder.rsf.processor.support.RSFRenderHandler$1.run(RSFRenderHandler.java:79)
at uk.org.ponder.rsf.processor.support.RequestInvoker$1.run(RequestInvoker.java:46)
at uk.org.ponder.util.CollectingRunnableInvoker$1.run(CollectingRunnableInvoker.java:25)
at uk.org.ponder.rsf.flow.support.BasicScopedAlterationWrapper.invokeRunnable(BasicScopedAlterationWrapper.java:59)
at uk.org.ponder.rsf.flow.support.BasicScopedAlterationWrapper$$FastClassBySpringCGLIB$$84f89202.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:652)
at uk.org.ponder.rsf.flow.support.BasicScopedAlterationWrapper$$EnhancerBySpringCGLIB$$497bbcf7.invokeRunnable(<generated>)
at uk.org.ponder.rsf.flow.support.BasicScopedAlterationWrapper$$FastClassBySpringCGLIB$$84f89202.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:652)
at uk.org.ponder.rsf.flow.support.BasicScopedAlterationWrapper$$EnhancerBySpringCGLIB$$497bbcf7.invokeRunnable(<generated>)
at uk.org.ponder.util.CollectingRunnableInvoker$1.run(CollectingRunnableInvoker.java:29)
at uk.org.ponder.util.CollectingRunnableInvoker.invokeWrappers(CollectingRunnableInvoker.java:32)
at uk.org.ponder.util.CollectingRunnableInvoker.invokeRunnable(CollectingRunnableInvoker.java:14)
at uk.org.ponder.rsf.processor.support.RequestInvoker.invokeRunnable(RequestInvoker.java:39)
at uk.org.ponder.rsf.processor.support.RSFRenderHandler.handle(RSFRenderHandler.java:75)
at uk.org.ponder.rsf.processor.support.RSFRenderHandler$$FastClassBySpringCGLIB$$5bda3a3d.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:652)
at uk.org.ponder.rsf.processor.support.RSFRenderHandler$$EnhancerBySpringCGLIB$$39423288.handle(<generated>)
at uk.org.ponder.rsf.processor.support.RenderHandlerBracketer.handle(RenderHandlerBracketer.java:82)
at uk.org.ponder.rsf.processor.support.RenderHandlerBracketer$$FastClassBySpringCGLIB$$3055fa0f.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:652)
at uk.org.ponder.rsf.processor.support.RenderHandlerBracketer$$EnhancerBySpringCGLIB$$fc1ae53e.handle(<generated>)
at uk.org.ponder.rsf.processor.support.RootHandlerBeanBase.handleGet(RootHandlerBeanBase.java:97)
at uk.org.ponder.rsf.processor.support.RootHandlerBeanBase.handle(RootHandlerBeanBase.java:79)
at org.sakaiproject.lessonbuildertool.util.RootHandlerBeanOverride.handle(RootHandlerBeanOverride.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at uk.org.ponder.reflect.JDKReflectiveCache.invokeMethod(JDKReflectiveCache.java:34)
at uk.org.ponder.reflect.JDKReflectiveCache.invokeMethod(JDKReflectiveCache.java:22)
at uk.org.ponder.reflect.JDKReflectiveCache.invokeMethod(JDKReflectiveCache.java:92)
at uk.org.ponder.rsac.support.RSACBeanLocatorImpl.createBean(RSACBeanLocatorImpl.java:553)
at uk.org.ponder.rsac.support.RSACBeanLocatorImpl.access$000(RSACBeanLocatorImpl.java:75)
at uk.org.ponder.rsac.support.RSACBeanLocatorImpl$1.run(RSACBeanLocatorImpl.java:449)
at uk.org.ponder.rsac.RSACErrorBridge.invokeRunnable(RSACErrorBridge.java:38)
at uk.org.ponder.rsac.support.RSACBeanLocatorImpl.createBean(RSACBeanLocatorImpl.java:447)
at uk.org.ponder.rsac.support.RSACBeanLocatorImpl.getLocalBean(RSACBeanLocatorImpl.java:348)
at uk.org.ponder.rsac.support.RSACBeanLocatorImpl.getBean(RSACBeanLocatorImpl.java:379)
at uk.org.ponder.rsac.support.PerRequestInfo$1.locateBean(PerRequestInfo.java:49)
at org.sakaiproject.rsf.servlet.ReasonableSakaiServlet.service(ReasonableSakaiServlet.java:89)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.sakaiproject.util.RequestFilter.doFilter(RequestFilter.java:411)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:720)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:358)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
at org.sakaiproject.tool.impl.ActiveToolComponent$MyActiveTool.forward(ActiveToolComponent.java:513)
at org.sakaiproject.portal.charon.SkinnableCharonPortal.forwardTool(SkinnableCharonPortal.java:1474)
at org.sakaiproject.portal.charon.handlers.SiteHandler.doToolBuffer(SiteHandler.java:1227)
at org.sakaiproject.portal.charon.handlers.SiteHandler.bufferContent(SiteHandler.java:1061)
at org.sakaiproject.portal.charon.handlers.SiteHandler.doSite(SiteHandler.java:490)
at org.sakaiproject.portal.charon.handlers.SiteHandler.doGet(SiteHandler.java:266)
at org.sakaiproject.portal.charon.handlers.SiteHandler.doGet(SiteHandler.java:154)
at org.sakaiproject.portal.charon.SkinnableCharonPortal.doGet(SkinnableCharonPortal.java:853)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.sakaiproject.util.RequestFilter.doFilter(RequestFilter.java:460)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
I have not changed any configuration settings or anything. I think bltiToolId is null or empty.
I'm trying to print all date in this MonthlyReport and got this exception.
SEVERE: Servlet.service() for servlet showMettingReports threw
exception java.lang.ClassCastException: [Ljava.lang.Object; cannot be
cast to com.sakhnin.classes.MonthlySummary at
org.apache.jsp.jspFiles.showMettingReports_jsp._jspService(showMettingReports_jsp.java:150)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721)
at
org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466)
at
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391)
at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
at com.sakhnin.implementations.Controller.doGet(Controller.java:140)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:725) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at
org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to
com.sakhnin.classes.MonthlySummary
MonthlySummary.java
public class MonthlySummary {
#Id
private String Date;
private int Cost;
private String Place;
private String Start;
private String End;
private String Description;
private int MentorID;
public MonthlySummary() {
// TODO Auto-generated constructor stub
}
public MonthlySummary(String place, String date, String start, String end,
String description, int cost, int mentorID) {
super();
Place = place;
Date = date;
Start = start;
End = end;
Description = description;
Cost = cost;
MentorID = mentorID;
}
MonthlySummaryIMP.java
public List<MonthlySummary> getMentorReportsById(int id) {
List<MonthlySummary> reports=null;
try{
session = factory.openSession();
session.beginTransaction();
// Fetch all active coupons whose businesses' parent's category is as got in the argument
SQLQuery query = session.createSQLQuery("SELECT * FROM MonthlySummary WHERE MentorID="+id );
reports = query.list();
closeSession();
}
catch(HibernateException e){
System.err.println(e.getMessage());
}
catch(Exception e){
System.err.println(e.getMessage());
}
return reports;
}
jsp file
<tbody>
<%
List<MonthlySummary> m = (List<MonthlySummary>)request.getSession().getAttribute("meetingsReports");
for(MonthlySummary report : m) {
%>
<td>Date<%=report.getDate() %></td>
<td>Date<%=report.getPlace()%></td>
<td>Date<%=report.getStart()%></td>
<td>Date<%=report.getEnd()%></td>
<td>Date<%=report.getDescription() %></td>
<td>Date<%=report.getCost()%></td>
<%
}
%>
</tbody>
To avoid such ClassCastException, you need to add Entity into your query object.
Try below--
SQLQuery query = session.createSQLQuery("SELECT * FROM MonthlySummary WHERE MentorID="+id );
query.addEntity(MonthlySummary.class);
reports = query.list();
--rest of code
As your stack trace suggests that the its trying to cast List of MonthlySummary but actually it cannot understand the left hand object to complete this process.
This kind of strange because if you would have not set the HTTPSession attribute on the first hand it should give you Null Pointer Exception.
Are you sure that you are not setting any attribute with that key, my assumption here is that you are setting some other object in that key.
Please use the trick mentioned by Sighr and that should do the magic for you.
I wonder if anyone can explain why the following code in a DAO in a Spring and Hibernate web application:
#Override
public Book get(Integer bookId) {
logger.info(BookDAOImpl.class.getName() + ".get() method called.");
Session session = sessionFactory.openSession();
try {
System.out.println("Book : " + bookId);
Book book = (Book) session.get(Book.class, bookId);
return book;
}
finally {
session.close();
}
}
Will work perfectly well inside its parent web application but when called via REST through a controller and service class:
// Gets a Book via REST.
#RequestMapping(value="/book/{bookId}", method=RequestMethod.GET)
public #ResponseBody Object getBook(#PathVariable("bookId") String bookId) {
logger.info(RestController.class.getName() + ".getBook() method called.");
if (bookIdValid(bookId)) {
Book book = bookService.get(Integer.parseInt(bookId));
System.out.println("ABook " + book.toString());
return book;
}
else {
Messages messages = new Messages();
messages.addMessage(messageSource.getMessage("bookId.required", null, null));
return messages;
}
}
The line Book book = (Book) session.get(Book.class, bookId); returns null.
Line 53 of BookDAOImpl is line return bookId == book.getBookId().intValue(); in the method below:
#Override
public boolean check(Integer bookId) {
logger.info(BookDAOImpl.class.getName() + ".check() method called.");
try {
Book book = this.get(bookId);
return bookId == book.getBookId().intValue();
}
catch(IndexOutOfBoundsException e) {
return false;
}
}
The stacktrace is:
Book : 78
INFO|12 07 2015|22 07 16|http-apr-8080-exec-123|library.controller.PersonController| - library.controller.ExceptionController.exception() method called.
null
library.dao.BookDAOImpl.check(BookDAOImpl.java:53)
library.service.BookServiceImpl.check(BookServiceImpl.java:32)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:483)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:201)
com.sun.proxy.$Proxy571.check(Unknown Source)
library.controller.RestController.bookIdValid(RestController.java:127)
library.controller.RestController.getBook(RestController.java:102)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:483)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:690)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2451)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2440)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:744)
library.interceptor.ClientInterceptor.afterCompletion() method completed: GET: /Library/rest/book/78?null at 12 07 2015 # 22 07 ended with HTTP code: 500.
It looks like session.get(Book.class, bookId) is returning null - your database likely does not contain book 78. Do you have a create book endpoint you can use to insert into the database prior to hitting the get endpoint?
I have a problem with my MVC server. When I post my JSON:
{
"shipName":"shfdsfds",
"signal":"fdsfsd321",
"longitude":43,
"latitude":32,
"maxSpeed":342
}
using PUT method and in Signal class two constructors is defined:
public Signal(){
}
public Signal(String shipName, String signal, int latitude, int longitude,
int maxSpeed) {
ShipName = shipName;
Signal = signal;
Latitude = latitude;
Longitude = longitude;
MaxSpeed = maxSpeed;
}
everytime I receive Status Code: 200-Ok, but wrong value of prams (addSignal: 0).
My controler:
#RequestMapping(value = "/addSignal", method = RequestMethod.PUT)
#ModelAttribute
public ResponseEntity<Signal> add(
#ModelAttribute Signal signal) throws SQLException,
ClassNotFoundException {
System.out.println("addSignal: "+signal.getMaxSpeed());
return new ResponseEntity<Signal>(signal, HttpStatus.OK);
}
When I try remove the first constructor (public Signal(){}), I receive error:
Status Code: 500 Internal Server Error
Console:
maj 16, 2015 3:18:23 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [server] in context with path [/shipserver] threw exception [Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.mkozykowski.api.Signal]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.mkozykowski.api.Signal.<init>()] with root cause
java.lang.NoSuchMethodException: com.mkozykowski.api.Signal.<init>()
at java.lang.Class.getConstructor0(Class.java:2892)
at java.lang.Class.getDeclaredConstructor(Class.java:2058)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:105)
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:81)
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:101)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:123)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:746)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:833)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:651)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1517)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1474)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
---------edit---------
I have changed my controller:
#RequestMapping(value = "/addSignal", method = RequestMethod.PUT, produces = "application/json")
public ResponseEntity<Signal> add(
#RequestBody Signal signal) throws SQLException,
ClassNotFoundException {
System.out.println("addSignal: "+signal.getMaxSpeed());
return new ResponseEntity<Signal>(signal, HttpStatus.OK);
}
In Signal class now I have one constructor:
public Signal(#JsonProperty("shipName")String shipName,#JsonProperty("signal")String signal,
#JsonProperty("latitude")int latitude, #JsonProperty("longitude")int longitude,
#JsonProperty("maxSpeed")int maxSpeed) {
ShipName = shipName;
Signal = signal;
Latitude = latitude;
Longitude = longitude;
MaxSpeed = maxSpeed;
}
Sending Json by RESTClient I add header:Content-Type:application/json.
Now I receive error:
HTTP Status 415
In my console nothing appears.
I feel like you should use #RequestBody instead of #ModelAttribute.
And to be sure that json deserializer correctly constructs your class using json data i suggest annotating constructor parameters with #JsonProperty("propertyName") where propertyName matches json property name.
---edit---
Are you sure that you correctly set header? Because your code works fine for me.