I just added a page (invoice) to the store front and i get this error, i'm not sure what caused this because yesterday i did added a simple page to test (backorder) it in the store front and it worked, now both of these pages don't work and this appears in the console log:
GRAVE: Exception Processing ErrorPage[exceptionType=java.lang.Exception, location=/exception.jsp]
org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core can not be solved either in web.xml or the jar files deployed with this application
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:56)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:445)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:117)
at org.apache.jasper.compiler.TagLibraryInfoImpl.generateTLDLocation(TagLibraryInfoImpl.java:325)
at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:154)
at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:410)
at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:475)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1410)
at org.apache.jasper.compiler.Parser.parse(Parser.java:138)
at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:604)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:543)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:470)
at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:420)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:208)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
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:748)
the impex file:
$contentCatalog=helvexContentCatalog
$contentCV=catalogVersion(CatalogVersion.catalog(Catalog.id[default=$contentCatalog]),CatalogVersion.version[default=Staged])[default=$contentCatalog:Staged]
$jarResourceCms=jar:org.helvex.com.mx.customstorefront.constants.HelvexcustomstorefrontConstants&/helvexcustomstorefront/import/cockpit/cmscockpit
$addonExtensionName=helvexcustomstorefront
## Configure page ...
INSERT_UPDATE ContentPage;$contentCV[unique=true];uid[unique=true];name;masterTemplate(uid,$contentCV);label;defaultPage[default='true'];approvalStatus(code)[default='approved'];homepage[default='false']
;;accountBalance;Account Balance;AccountPageTemplate;/account-balance
;;backOrder;Back Order;AccountPageTemplate;/back-order
;;invoice;Invoice;AccountPageTemplate;/invoice
# CMS Link Component
INSERT_UPDATE CMSLinkComponent;$contentCV[unique=true];uid[unique=true];name;url;&linkRef;&componentRef;target(code)[default='sameWindow']
;;AccountBalanceLink;AccountBalanceLink;/account-balance;AccountBalanceLink;AccountBalanceLink;
;;BackOrderLink;BackOrderLink;/back-order;BackOrderLink;BackOrderLink
;;InvoiceLink;InvoiceLink;/invoice;InvoiceLink;InvoiceLink
# CMS Navigation Nodes
INSERT_UPDATE CMSNavigationNode;uid[unique=true];$contentCV[unique=true];name;parent(uid, $contentCV);links(&linkRef)[mode=append];&nodeRef
;AccountBalanceLeftNavNode;;Check Accounts Balance;HelvexNavNode;AccountBalanceLink;AccountBalanceLeftNavNode
;BackOrderNavNode;;Back Order;HelvexNavNode;BackOrderLink;BackOrderNavNode
;InvoiceNavNode;;Invoice;HelvexNavNode;InvoiceLink;InvoiceNavNode
# the jsp pages we defined earlier
INSERT_UPDATE JspIncludeComponent;$contentCV[unique=true];uid[unique=true];name;page;actions(uid,$contentCV);&componentRef
;;AccountBalanceComponent;Check Accounts Balance Component;/WEB-INF/views/addons/$addonExtensionName/responsive/pages/accountBalancePage.jsp;;AccountBalanceComponent
;;BackOrderComponent;Back Order Component;/WEB-INF/views/addons/$addonExtensionName/responsive/pages/backOrderPage.jsp;;BackOrderComponen
;;InvoiceComponent;Invoice Component;/WEB-INF/views/addons/$addonExtensionName/responsive/pages/invoicePage.jsp;;InvoiceComponent
# the content slots
INSERT_UPDATE ContentSlot;$contentCV[unique=true];uid[unique=true];name;active;cmsComponents(uid,$contentCV);;;
;;BodyContent-accountsBalance;Body Content Slot for Accounts Balance;true;AccountBalanceComponent;;;
;;BodyContent-backOrder;Body Content Slot for Back Order;true;BackOrderComponent;;;
;;BodyContent-invoice;Body Content Slot for Invoice;true;InvoiceComponent;;;
INSERT_UPDATE ContentSlotForPage;$contentCV[unique=true];uid[unique=true];position[unique=true];page(uid,$contentCV)[unique=true][default='accountBalance'];contentSlot(uid,$contentCV)[unique=true];;;
;;BodyContent-accountsBalance;BodyContent;accountBalance;BodyContent-accountsBalance;;;
;;BodyContent-backOrder;BodyContent;backOrder;BodyContent-backOrder;;;
;;BodyContent-invoice;BodyContent;invoice;BodyContent-invoice;;;
the web-spring.xml
<bean name="accountBalancePageController" class="org.helvex.com.mx.customstorefront.controllers.pages.AccountBalancePageController"/>
<bean name="backOrderPageController" class="org.helvex.com.mx.customstorefront.controllers.pages.BackOrderPageController"/>
<bean name="invoicePageController" class="org.helvex.com.mx.customstorefront.controllers.pages.InvoicePageController"/>
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/account-balance">accountBalancePageController</prop>
<prop key="/back-order">backOrderPageController</prop>
<prop key="/invoice">invoicePageController</prop>
</props>
</property>
</bean>
What did i missed? How i can fix this error?
I think the problem here is, that your application didnt find any page. And than the application tries to open a 'exception.jsp' page. But on this page as well are some errors it seems.
So maybe try to open only the 'exception.jsp' and try to fix this error first.
I'm new at Spring MVC. I'm using STS and I've created Spring MVC Template Project (which uses Maven by default). I'm trying to use Hibernate and i know that in default Java Projects i have to put hibernate.xml.cfg in /src folder. I've read that in my case (with Spring MVC Template with maven) i have to put hibernate.cfg.xml in src/main/resources and in /WEB-INF/classes. But it didn't help too. I still have ClassNotFoundException:
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/mvc] threw exception [Handler processing failed; nested exception is java.lang.ExceptionInInitializerError] with root cause
java.lang.ClassNotFoundException: org.dom4j.DocumentException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at com.andrew.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:18)
at com.andrew.hibernate.DAO.getStudent(DAO.java:48)
at com.andrew.mvc.HomeController.home(HomeController.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Here is my hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="connection.url">jdbc:sqlserver://localhost:1433</property>
<property name="connection.username">hibernate</property>
<property name="connection.password">123456</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Mapping files -->
<mapping class="com.andrew.ModelPackage.Student"/>
<mapping class="com.andrew.ModelPackage.Subject"/>
</session-factory>
</hibernate-configuration>
My HibernateUtil class:
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
//AnnotationConfiguration
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Maybe i should write something about hibernate.cfg.xml in web.xml or in servlet-context.xml? I'm fighting with this problem about 7 hours and i tried even put hibernate.cfg.xml in every folder in the project but it didn't helped.
IMO is not a problem with the location of your hibernate.cfx.xml, but looks like a missing library. You should add the dom4j.jar in your classpath.
I have an action called GetFile which directly opens a file download box to open PDF.
Below is the struts.xml configuration and the action class for the same. I am using result type as stream to achieve this. I can see that the pdf download box opens all the times and i am also able to download the file.
But I find that there were some requests last night that had fired the action and it has produced the below error.
org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:570)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:452)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530)
at org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:159)
at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:374)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:278)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at deshaw.irweb.web.interceptor.AuthInterceptor.intercept(AuthInterceptor.java:60)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:510)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:294)
at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:183)
at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:169)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:636)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:205)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:105)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:182)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:123)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:80)
at org.apache.jsp.jsp.ServerError_jsp._jspService(ServerError_jsp.java:157)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
... 38 more
Can someone tell me what could have caused the problem ? I am not able to reproduce the problem currently. I read somewhere that it could be due to closing the download dialog, but it was not the case even after i tried from multiple browsers. Also checked getOutputStream() has already been called for this response , but could not relate directly to my problem as there is no redirection to jsp as the struts2 action directly leads to result stream.
struts.xml
<action name="GetFile" class="Class" method="DownloadFile">
<result name="success" type="stream">
<param name="contentType">contentType</param>
<param name="contentDisposition">fileName</param>
<param name="bufferSize">1024</param>
<param name="inputName">inputStream</param>
</result>
</action>
Action Class
public String DownloadFile ()
{
// create the object variable pdfdoc which is a custom object.
// You can assume that the pdfdoc is properly constructed
// and getFileContent does what it is required to do, so
// that the final pdf is generated.
...
...
inputStream = new ByteArrayInputStream(pdfdoc.getFileContent());
contentType = pdfdoc.getContentType();
fileName = pdfdoc.getFileName();
contentDisposition = doc.getContentDisposition();
bufferSize = 1024;
return "success";
}
I had a similar problem when using Internet Explorer and fixed it by adding this in the response header:
response.setHeader("Expires","0");
response.setHeader("Pragma","cache");
response.setHeader("Cache-Control","private");
Maybe the requests that you see in your log where generated by Internet Explorer.
Have a look here and here!
Update: To print the browser version in your log you can do something like this:
System.out.println(request.getHeader("User-Agent"));
I am trying to configure and run spring + hibernate client server project (Spring's HTTP invoker).
I have omitted the httpinvoker configuration and web.xml , because the configuration for httpinvoker is working well .
According to the suggestion from the answers, I removed the TestSimple class, and posting the stacktrace when i try to run the service from client side.
I have posted log (below) when I run mvn tomcat:run at server side and the stacktrace after I call the client code(posted below). I'm getting the NPE for sessionFactory. Could you please suggest some ideas?
My applicationContext.xml looks like :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- Database Configuration -->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/config.properties</value>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
p:username="${jdbc.username}" p:password="${jdbc.password}" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="dialect">${hibernate.dialect}</prop>
<prop key="show_sql">${hibernate.show_sql}</prop>
<prop key="format_sql">true</prop>
<prop key="use_sql_comments">true</prop>
<prop key="hibernate.connection.autocommit">true</prop>
<prop key="hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
</props>
</property>
<property name="packagesToScan" value="com.gt.cbpr.model"></property>
</bean>
<!-- auto wired/scan annotation based config -->
<context:annotation-config />
<context:component-scan base-package="com.gt.cbpr.server" />
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="dataSource" ref="dataSource" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
My LoginUserServiceImpl :
package com.gt.cbpr.server.service.impl;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.gt.cbpr.model.LoginUser;
import com.gt.cbpr.service.LoginUserService;
#Component
public class LoginUserServiceImpl implements LoginUserService {
#Autowired
private SessionFactory sessionFactory;
public void saveLoginUser(LoginUser user) throws Exception {
System.out.println(sessionFactory);
sessionFactory.getCurrentSession().saveOrUpdate(user);
}
}
Client side code :
import com.gt.cbpr.model.LoginUser;
import com.gt.cbpr.service.LoginUserService;
import com.gt.lib.utils.BeanUtils;
public class HelloClient {
public static void main(String[] args) throws Exception{
LoginUserService lus = (LoginUserService) BeanUtils.getBean("loginService");
LoginUser u = new LoginUser();
u.setUsername("AA");
u.setPassword("AAAASS");
lus.saveLoginUser(u); // I get exception here.
}
}
The tomcat log :
http://pastebin.com/Xw92PJv6
The stacktrace when i run the above client code :
10:47:11,938 DEBUG DispatcherServlet:819 - DispatcherServlet with name 'remoting' processing POST request for [/cbpr/remoting/helloService]
10:47:11,942 DEBUG BeanNameUrlHandlerMapping:124 - Mapping [/helloService] to HandlerExecutionChain with handler [org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter#93fd01] and 1 interceptor
10:47:11,946 DEBUG HttpInvokerServiceExporter:73 - Applying RemoteInvocation: method name 'setHello'; parameter types [com.gt.cbpr.model.HelloObject]
10:47:11,950 DEBUG RemoteInvocationTraceInterceptor:66 - Incoming HttpInvokerServiceExporter remote call: com.gt.cbpr.service.HelloService.setHello
10:47:11,950 DEBUG RemoteInvocationTraceInterceptor:72 - Finished processing of HttpInvokerServiceExporter remote call: com.gt.cbpr.service.HelloService.setHello
10:47:11,956 DEBUG DispatcherServlet:957 - Null ModelAndView returned to DispatcherServlet with name 'remoting': assuming HandlerAdapter completed request handling
10:47:11,956 DEBUG DispatcherServlet:913 - Successfully completed request
10:47:11,961 DEBUG DispatcherServlet:819 - DispatcherServlet with name 'remoting' processing POST request for [/cbpr/remoting/helloService]
10:47:11,961 DEBUG BeanNameUrlHandlerMapping:124 - Mapping [/helloService] to HandlerExecutionChain with handler [org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter#93fd01] and 1 interceptor
10:47:11,962 DEBUG HttpInvokerServiceExporter:73 - Applying RemoteInvocation: method name 'getHello'; parameter types []
10:47:11,962 DEBUG RemoteInvocationTraceInterceptor:66 - Incoming HttpInvokerServiceExporter remote call: com.gt.cbpr.service.HelloService.getHello
10:47:11,963 DEBUG RemoteInvocationTraceInterceptor:72 - Finished processing of HttpInvokerServiceExporter remote call: com.gt.cbpr.service.HelloService.getHello
10:47:11,964 DEBUG DispatcherServlet:957 - Null ModelAndView returned to DispatcherServlet with name 'remoting': assuming HandlerAdapter completed request handling
10:47:11,965 DEBUG DispatcherServlet:913 - Successfully completed request
10:47:11,994 DEBUG DispatcherServlet:819 - DispatcherServlet with name 'remoting' processing POST request for [/cbpr/remoting/loginService]
10:47:11,995 DEBUG BeanNameUrlHandlerMapping:124 - Mapping [/loginService] to HandlerExecutionChain with handler [org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter#9036e] and 1 interceptor
10:47:11,997 DEBUG HttpInvokerServiceExporter:73 - Applying RemoteInvocation: method name 'saveLoginUser'; parameter types [com.gt.cbpr.model.LoginUser]
10:47:11,999 DEBUG RemoteInvocationTraceInterceptor:66 - Incoming HttpInvokerServiceExporter remote call: com.gt.cbpr.service.LoginUserService.saveLoginUser
null
10:47:12,009 WARN RemoteInvocationTraceInterceptor:80 - Processing of HttpInvokerServiceExporter remote call resulted in fatal exception: com.gt.cbpr.service.LoginUserService.saveLoginUser
java.lang.NullPointerException
at com.gt.cbpr.server.service.impl.LoginUserServiceImpl.saveLoginUser(LoginUserServiceImpl.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.remoting.support.RemoteInvocationTraceInterceptor.invoke(RemoteInvocationTraceInterceptor.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy26.saveLoginUser(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.remoting.support.RemoteInvocation.invoke(RemoteInvocation.java:205)
at org.springframework.remoting.support.DefaultRemoteInvocationExecutor.invoke(DefaultRemoteInvocationExecutor.java:38)
at org.springframework.remoting.support.RemoteInvocationBasedExporter.invoke(RemoteInvocationBasedExporter.java:76)
at org.springframework.remoting.support.RemoteInvocationBasedExporter.invokeAndCreateResult(RemoteInvocationBasedExporter.java:112)
at org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter.handleRequest(HttpInvokerServiceExporter.java:117)
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
10:47:12,020 DEBUG HttpInvokerServiceExporter:92 - Target method failed for RemoteInvocation: method name 'saveLoginUser'; parameter types [com.gt.cbpr.model.LoginUser]
java.lang.NullPointerException
at com.gt.cbpr.server.service.impl.LoginUserServiceImpl.saveLoginUser(LoginUserServiceImpl.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.remoting.support.RemoteInvocationTraceInterceptor.invoke(RemoteInvocationTraceInterceptor.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy26.saveLoginUser(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.remoting.support.RemoteInvocation.invoke(RemoteInvocation.java:205)
at org.springframework.remoting.support.DefaultRemoteInvocationExecutor.invoke(DefaultRemoteInvocationExecutor.java:38)
at org.springframework.remoting.support.RemoteInvocationBasedExporter.invoke(RemoteInvocationBasedExporter.java:76)
at org.springframework.remoting.support.RemoteInvocationBasedExporter.invokeAndCreateResult(RemoteInvocationBasedExporter.java:112)
at org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter.handleRequest(HttpInvokerServiceExporter.java:117)
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
10:47:12,064 DEBUG DispatcherServlet:957 - Null ModelAndView returned to DispatcherServlet with name 'remoting': assuming HandlerAdapter completed request handling
10:47:12,067 DEBUG DispatcherServlet:913 - Successfully completed request
I could not figure out what wrong going on. Can you please help me in this?
Just a guess, but you are calling saveUser from the constructor. I am not sure about spring, but in other CDI I have used the beans are not injected when the object is created, but after the object has been created.
For this kind of "initialization", you should use saveUser with #PostConstruct (that will execute the method after the dependencies have been injected). The method should take no parameters. And of course you should remove the method call from the constructor.
The logs you show are the logs of your web application. Your test is a standalone application, where the main method simply instantiate your test class using new. There is no way for Spring to autowire a bean that it doesn't instantiate itself. When you construct a bean using new, you're bypassing Spring completely.
Your main method needs to instantiate an application context, and to ask this context for the bean of type TestSimple.
The anwser of #SJUan76 is correct as well. Spring instantiates the bean , then autowire it. So in the constructor, nothing is autowired yet. It's generally a bad practice to do something other than initialization in a constructor.
You aren't pulling TestSimple out of a Spring context, so the #Autowired tag does nothing. In your main, pull the object out of a spring context instead, this will work better.
If you're writing integration tests to test the behavior of your beans inside an application container then you should consider using Spring TestContext framework (it's the official way to write integration tests for Spring) - there's no magic in - normally JUnit will run Spring Test Context classes which implement JUnit Class Runner Api. So, you run JUnit, JUnit runs TestContext Framework, Test Context Framework creates application context from specified XML configuration file and runs your tests. Simple.
The unit tests are another story , there you test your beans separately by mocking their dependencies. In this part, you have to inject your the dependencies of your beans manually - there is no DI container so you have to call constructors and property setters directly from your test classes. Also that probably means that you'll have to replace your #Autowired fields with the public #Autowired property setters.
Hi iv been struggling with this error for some time and really cant figure out why its occurring , i have a web application that uses springs simpleJdbctemplate to access a database i can use this locally and it has been tested but when i deploy the application jersey has some problems running the queries on the server this is the stacktrace from the tomcat logs
10-Jan-2011 21:15:28 com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NullPointerException
at example.jersey.spring.dao.testDAO.getUsers(testDAO.java:20)
at example.jersey.spring.MyResource.getIt(MyResource.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:168)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:70)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:279)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:86)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:74)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1357)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1289)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1239)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1229)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:497)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:684)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
This is my resource
#GET
#Produces("text/plain")
public String getIt() {
return "the number of users are " +db.getUsers();
}
TestDAO.java
SimpleJdbcTemplate simpleJdbcTemplate ;
public void setDataSource(final DataSource dataSource) {
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
}
applicationContext.xml
<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</bean>
<bean id="testDAO" class="com.example.testDAOimpl">
<property name="dataSource" ref="dataSource"/>
</bean>
running locally in eclipse the db.getusers returns - the correct value of 1 so i cant understand why it doesnt work when deployed
Any help greatly appreciated
(Seems to be no real difference from the local set up and the server set up ) if anyone has encountered this anyhelp is much appreciated)
Thanks
Chris
Not sure if this is your problem. But I was facing a similar issue. And what ended up happening is I was missing the MimeMultipart.class on my class path in my server code. Jersey was unable to find the class, and therefore unable to map the server request properly. Strangest thing was I never saw any kind of error message on the server side indicating a class not found.
Assuming you use a bean factory, do something like this to get it from spring:
BeanFactoryLocator beanFactoryLocator = SingletonBeanFactoryLocator.getInstance();
BeanFactoryReference beanFactoryReference = beanFactoryLocator.useBeanFactory("ctx");
testDAOimpl myDao = (testDAOimpl)beanFactoryReference.getFactory().getBean("testDAO");