javax.servlet.ServletException: Could not resolve view with name in servlet with name 'dispatcher' - spring

javax.servlet.ServletException: Could not resolve view with name
I'm new to Spring MVC. I got an issue here. I'm trying to get a view from a handler function. Issue is that it is returning an error, which I have seen a lot of times and solved. But for this I'm totally stuck. Could you please help me?
#RequestMapping(value="/editcasetypes.htm", method = RequestMethod.GET)
public ModelAndView loadEditCaseTypePage(#ModelAttribute("addcasetypes") CaseTypesFormBean caseTypesFormBean, ModelMap model, HttpSession session, HttpServletRequest request) throws Exception {
String editThis="20";
if(!editThis.equals("") && editThis!=null){
caseTypesFormBean.setCaseTypeCd(Integer.parseInt(editThis));
caseTypesBusinessDelegate.editCaseTypeToDB(caseTypesFormBean);
}
model.addAttribute(caseTypesFormBean);
return new ModelAndView("addcasetypes", model);
}
I'm just adding the header part of my JSP:
<body onload="init()">
<form:form modelAttribute="addcasetypes" id="addcasetypes">
<div id="wrapper_popup">
<c:if test="${success}">
<div class="successmsg">${message}</div>
</c:if>
<c:if test="${errors}">
<div class="errormsg">${message}</div>
</c:if>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="frmtable">
<tr>
<td class="label"><spring:message code="lblCaseType" /><span class="mand">*</span></td>
<td><form:input path="caseType" id="caseType" tabindex="1" maxlength="80" onchange="zerValidationName(this.value, this.id);"/></td>
</tr>
</table>
Tiles-defs:
<definition name="editcasetypes" extends="popupLayout">
<put-attribute name="title" value="CCTNS"/>
<put-attribute name="body" value="/WEB-INF/jsp/addcasetypes.jsp"/>
</definition>
view.prop
addcasetypes.(class)=org.springframework.web.servlet.view.tiles2.TilesView
addcasetypes.url=editcasetypes
In which, I'm trying to reuse the addcasetype page for edit. Add functionality is working fine. But for edit, upon clicking the link, I'm getting this error:
INFO: CsrfGuard analyzing request /cctns/editcasetypes.htm
INFO: 2016-07-19 18:47:28,863|INFO |httpSSLWorkerThread-8080-2|org.additionalmaster.spring.ManageCaseTasksController|189|:INSIDE loadEditCaseTypePage()
INFO: 2016-07-19 18:47:28,863|INFO |httpSSLWorkerThread-8080-2|org.cctns.additionalmaster.spring.ManageCaseTasksController|193|:ID TO EDIT >> 20
INFO: 2016-07-19 18:47:28,863|INFO |httpSSLWorkerThread-8080-2|org.additionalmaster.dao.CaseTypesDAOImpl|276|:TO EDIT >> 20
SEVERE: StandardWrapperValve[dispatcher]: PWC1406: Servlet.service() for servlet dispatcher threw exception
javax.servlet.ServletException: Could not resolve view with name 'editcasetypes' in servlet with name 'dispatcher'
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1029)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:333)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.owasp.csrfguard.CsrfGuardFilter.doFilter(CsrfGuardFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.cctns.cas.state.online.filter.ResponseFilter.doFilter(ResponseFilter.java:74)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at com.sun.identity.agents.filter.AmAgentBaseFilter.allowRequestToContinue(AmAgentBaseFilter.java:130)
at com.sun.identity.agents.filter.AmAgentBaseFilter.doFilter(AmAgentBaseFilter.java:80)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.cctns.cas.state.online.filter.MultipartFilter.doFilter(MultipartFilter.java:114)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.cctns.cas.state.online.filter.CrossScriptingFilter.doFilter(CrossScriptingFilter.java:26)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.cctns.cas.state.online.filter.AuthFilter.doFilter(AuthFilter.java:166)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
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:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:313)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1093)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1093)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:291)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:666)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:597)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:872)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:382)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:264)
at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
INFO: 2016-07-19 18:47:28,878|DEBUG|httpSSLWorkerThread-8080-2|org.apache.tiles.impl.BasicTilesContainer|615|:Render request recieved for definition 'standardhttperror'
Can someone please help me?

heyy, thanks for the quick response. I'm adding web.xml part below..
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
<!-- /WEB-INF/applicationContext-security.xml-->
</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>JavaScriptServlet</servlet-name>
<url-pattern>/JavaScriptServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/errors/404.htm</location>
</error-page>
</error-page>
</web-app>

Related

JSF 2 Managed bean concurrent access between logged in users

Basic example to showcase my problem :
Two users A and B connect to the JSF web app from different browsers, and the welcoming page shows their documents and a search panel.
Both of them want to search for documents using a word or sentence.
(for instance) A wants to search for the word "sheets" and B wants to search for the word "virus".
They write down the word in the form input and they simultaneously submit the form.
A gets the result of her search, while B suddenly gets also the same result as A with a word he didn't type which is "sheets".
Here's my managedBean :
#ManagedBean
#RequestScoped
public class DocumentController implements Serializable {
private String motSearch= null;
private boolean searching = false;
private boolean rechercheStructure = true;
private DocumentDao dao; //Dependency injection with Spring
public void onload(Utilisateur user)
{
if(!searching)
{
motSearch = null;
documentsListForConnectedUser(user);
}
else{
search(user);
}
}
public void search(Utilisateur user)
{
documentsListForConnectedUser(user);// getting documents list from database
searching = true;
List<Document> list = new ArrayList<>();
list.addAll(user.getDocuments());
user.setDocuments(new ArrayList<>());
//...
if(motSearch != null && !motSearch.isEmpty())
{
LOGGER.info("motSearch : "+motSearch.toLowerCase());
List<Document> docs = user.getDocuments();
for(Document doc : list)
{
if(!docs.contains(doc) && (doc.getNom().toLowerCase().contains(motSearch.toLowerCase()) ||
doc.getDescription().toLowerCase().contains(motSearch.toLowerCase()) ||
doc.getTheme().toLowerCase().contains(motSearch.toLowerCase()) ||
doc.getKeywords().contains(motSearch.toLowerCase())))
{
docs.add(doc);
}
}
docs = filter(docs);
if(docs.size() == 0)
{
user.setDocuments(null);
}
}
else
{
user.setDocuments(list);
}
}
}
The JSF page ListeDocuments.xhtml :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<f:metadata>
<f:viewParam name="searching" value="#{documentController.searching}" />
<f:viewParam name="structure" value="#{documentController.rechercheStructure}"/>
<f:viewParam name="q" value="#{documentController.motSearch}"/>
<f:viewAction action="#{documentController.onload(user)}"/>
</f:metadata>
</h:head>
<h:body>
<h:form id="myForm" prependId="false" >
<h:inputHidden value="true" id="searching"/>
<div class="center">
<h:selectOneRadio converter="javax.faces.Boolean"
value="#{documentController.rechercheStructure}" onchange="check()" id="structure">
<f:selectItem itemLabel="Recherche structurée" itemValue="true" />
<f:selectItem itemLabel="Recherche plein texte" itemValue="false" />
</h:selectOneRadio>
</div>
<div class="row">
<div class="input-field col s12 m7 l8">
<p:inputTextarea styleClass="materialize-textarea" id="q" value="#{documentController.motSearch}"/>
<label for="q">Mot/phrase à chercher</label>
</div>
</div>
<p:commandButton styleClass="btn blue-grey" update=":table"
type="submit" value="Chercher"
action="ListeDocuments?faces-redirect=true&includeViewParams=true" />
</h:form>
<p:dataTable id="table" tableStyleClass="hoverable striped" rows="10" paginator="true"
value="#{user.documents}" var="doc"
paginatorPosition="bottom" paginatorAlwaysVisible="false" styleClass="borderless">
<!--Columns-->
</p:dataTable>
</h:body>
</html>
My web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<session-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<error-page>
<error-code>404</error-code>
<location>/404.html</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/serverError.xhtml</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/serverError.xhtml</location>
</error-page>
<!-- Add Support for Spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>none</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
</web-app>
faces-config.xml file :
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
PS : I'm using :
Mojarra 2.2.9 JSF implementation.
Apache Tomcat 7 server with Servlet 3.0.
Spring but I only use it to inject interface implementations like DAOs.
Hibernate 4/JPA as ORM.
Since I needed to use Omnifaces 2.4 library for its converters I was obliged to integrate CDI (weld-servlet-2.3.5 final) and create an empty beans.xml (guidelines from BalusC blog), and I don't use any of its annotations in my managedBeans.
The only annotations I use are #ManagedBean and #xxxxScoped from javax.faces.bean and sometimes #PostConstruct.
Finally Primefaces 6.0
Any help is appreciated !

Spring Security error

Hi i am new to spring security and trying to apply authentication and authorization through spring security.
While running the application i am getting this exception:
javax.servlet.ServletException: java.lang.NoClassDefFoundError:org/springframework/security/access/expression/SecurityExpressionHandler
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/springframework/security/access/expression/SecurityExpressionHandler
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:263)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.access.channel.ChannelProcessingFilter.doFilter(ChannelProcessingFilter.java:109)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
web.xml file is :
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>bsolPortalWebApp</display-name>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>springDispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/spring-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springDispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/spring-context.xml,
/WEB-INF/config/spring-security.xml
</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
my spring-security.xml file is
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">
<http auto-config="true">
<intercept-url pattern="/PoolB/*" requires-channel="http" access="ROLE_USER,ROLE_ADMIN" />
<form-login login-page="/login" default-target-url="/PoolB/Welcome" authentication-failure-url="/loginfailed" />
logout logout-success-url="/logout" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="abc" password="abc" authorities="ROLE_USER" />
<user name="xyz" password="xyz" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
login.jsp file is :
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>Login Page</title>
<link href="${pageContext.request.contextPath}/resources/css/background.css" rel="stylesheet" >
<style>
.errorblock {
color: #ff0000;
background-color: #ffEEEE;
border: 3px solid #ff0000;
padding: 8px;
margin: 16px;
margin-right:500px;
margin-left:500px;
}
</style>
</head>
<body onload='document.f.j_username.focus();'>
<h3>Login with Username and Password (Authentication with Database)</h3>
<c:if test="${not empty error}">
<div class="errorblock">
Your login attempt was not successful, try again.<br /> Caused :
${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message}
</div>
</c:if>
<form name='f' action="<c:url value='j_spring_security_check' />" method='POST'>
<table align="center">
<tr>
<td>User:</td>
<td><input type='text' name='j_username' value='' id='uname'>
</td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='j_password' id='pword'/>
</td>
</tr>
<tr>
<td><input type="submit" value="Login"></td>
<td><input name="reset" type="Reset" /></td>
</tr>
</table>
</form>
</body>
</html>
Welcome.jsp file is :
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO- 8859-1"%>
<%# taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Hi U R Succesfully Loged in.
<br/>
<security:authorize access="hasRole('ROLE_ADMIN')">
<p>
InsertRecord
</p>
</security:authorize>
RetriveRecord
</body>
and the added jars are:
1.com.springsource.org.apache.commons.logging-1.1.1.jar
2.com.springsource.org.apache.log4j-1.2.15.jar
3.javax.servlet.jsp.jstl-1.2.1.jar
4.jstl-1.2.jar
5.log4j-1.2.11.jar
6.log4j.jar
7.spring-aop-3.0.3.RELEASE.jar
8.spring-aop-3.2.5.RELEASE.jar
9.spring-aspects-3.2.5.RELEASE.jar
10.spring-beans-3.2.5.RELEASE.jar
11.spring-build-src-3.2.5.RELEASE.jar
12.spring-context-3.2.5.RELEASE.jar
13.spring-context-support-3.2.5.RELEASE.jar
14.spring-core-3.2.5.RELEASE.jar
15.spring-expression-3.2.5.RELEASE.jar
16.spring-instrument-3.2.5.RELEASE.jar
17.spring-instrument-tomcat-3.2.5.RELEASE.jar
18.spring-jdbc-3.2.5.RELEASE.jar
19.spring-jms-3.2.5.RELEASE.jar
20.spring-mobile-device-1.1.0.RELEASE.jar
21.spring-orm-3.2.5.RELEASE.jar
22.spring-oxm-3.2.5.RELEASE.jar
23.spring-security-config-3.0.5.RELEASE.jar
24.spring-security-core-3.0.5.RELEASE.jar
25.spring-security-taglibs-3.1.0.RELEASE.jar
26.spring-security-web-3.0.5.RELEASE.jar
27.spring-struts-3.2.5.RELEASE.jar
28.spring-test-3.2.5.RELEASE.jar
29.spring-tx-3.2.5.RELEASE.jar
30.spring-web-3.2.5.RELEASE.jar
31.spring-webmvc-3.2.5.RELEASE.jar
32.spring-webmvc-portlet-3.2.5.RELEASE.jar
33.sqljdbc4.jar
Can anyone please help me to resolve this issue..
It was the problem with jar only. I added 3.1.0 version of all spring security jars and as per the suggestiong from other users added the following bean to spring configuration
<bean id="webexpressionHandler" class="org.springframework.security.web.access.exp
The problem seems to be that you have Spring Security 3.0.x dependencies added to your classpath while you also use security-taglibs-3.1.0.RELEASE.
Try using Spring Security 3.1.x for all the dependencies
The class SecurityExpressionHandler was added to Spring Security 3.1
UPDATE
You also need to update the xsd references in spring.security.xml
and add the following bean to spring configuration
<bean id="webexpressionHandler" class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler" />

Can't subscribe to server-sent event using Jersey and Tomcat 7

I am deploying Server-Sent-Event resource with jersey 2.41 / Java 7 / tomcat 7.
I am getting error as
Dec 16, 2013 4:04:40 AM org.apache.catalina.core.StandardWrapperValve
invoke SEVERE: Servlet.service() for servlet [ServletAdaptor] in
context with path [/trackapp] threw exception
[java.lang.UnsupportedOperationException: Asynchronous processing not
supported on Servlet 2.x container.] with root cause
java.lang.UnsupportedOperationException: Asynchronous processing not
supported on Servlet 2.x container. at
org.glassfish.jersey.servlet.WebComponent$3.suspend(WebComponent.java:123)
at
org.glassfish.jersey.servlet.internal.ResponseWriter.suspend(ResponseWriter.java:109)
at
org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:619)
at
org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:381)
at
org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:371)
at
org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:262)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) at
org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) at
org.glassfish.jersey.internal.Errors.process(Errors.java:315) at
org.glassfish.jersey.internal.Errors.process(Errors.java:297) at
org.glassfish.jersey.internal.Errors.process(Errors.java:267) at
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:318)
at
org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:236)
at
org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:983)
at
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:361)
at
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:372)
at
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:335)
at
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:218)
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:225)
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:98)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
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:1001)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
my Resource
#POST
#Produces(MediaType.APPLICATION_JSON)
#Consumes(MediaType.APPLICATION_JSON)
public String broadcastMessage(String message) {
OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
OutboundEvent event = eventBuilder.name("message")
.mediaType(MediaType.TEXT_PLAIN_TYPE)
.data(String.class, message)
.build();
broadcaster.broadcast(event);
System.out.println("broadcasting listen [" +message+ "]");
return "Message was '" + message + "' broadcast.";
}
#GET
#Produces(SseFeature.SERVER_SENT_EVENTS)
#Path("/listen")
public EventOutput listenToBroadcast() {
System.out.println("will listen");
final EventOutput eventOutput = new EventOutput();
this.broadcaster.add(eventOutput);
return eventOutput;
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="false">
<servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>
org.glassfish.jersey.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>net.jigarshah.mse.tracker</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
client JS
<script>
var url="http://localhost:8080/trackapp/webapi/broadcast/listen";
var source=new EventSource(url);
source.onerror=function(event)
{
console.log("error");
};
source.onmessage=function(event)
{
console.log(event.data);
document.getElementById("result").innerHTML+=event.data + "<br>";
};
</script>
</head>
<body>
<div id="result">
test
</div>
One possibility is to check the maven dependencies as listed here
https://jersey.java.net/documentation/latest/modules-and-dependencies.html
You can also check that through this message from jersey mailing list https://java.net/projects/jersey/lists/users/archive/2013-11/message/63
Hope this helps.
I had the same trouble, my issue was that I used the wrong jersey servlet implementation. Add to replace
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
</dependency>
by (note the missing -core)
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
</dependency>

Wicket-atmosphere EventBus.post causes NullPointerException at ServletWebRequest.getContextRelativeUrl()

I made a wicket-atmosphere webapp via maven and it works. If i create a new webapp without maven and i copy all of dependencies as jars, it doesn't work anymore.
in onClick of AjaxLink i call EventBus.get().post() and it causes NullPoiinterException. You can read full stacktrace below. What did i just miss?
public void onClick(AjaxRequestTarget art){
EventBus.get().post( message = getRandomText() );
}
jars:
javax.servlet-api-3.0.1.jar
slf4j-simple-1.6.4.jar
slf4j-api-1.6.4.jar
wicket-core-6.9.0.jar
wicket-request-6.9.0.jar
wicket-util-6.9.0.jar
wicket-atmosphere-0.10.jar
atmosphere-compat-jbossweb-1.0.8.jar
atmosphere-compat-tomcat-1.0.8.jar
atmosphere-compat-tomcat7-1.0.8.jar
atmosphere-runtime-1.0.8.jar
guava-11.0.0.jar
jsr305-1.3.9.jar
My xmls:
META-INF/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!-- <Loader className="org.atmosphere.util.AtmosphereClassloader"/> -->
<Loader delegate="true"/>
</Context>
META-INF/atmosphere.xml
<atmosphere-handlers>
<atmosphere-handler context-root="/*"
class-name="org.atmosphere.handler.ReflectorServletProcessor">
<property name="filterClassName" value="com.myapp.wicket.DebugWicketFilter" />
</atmosphere-handler>
</atmosphere-handlers>
WEB-INF/web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>myproject</display-name>
<servlet>
<description>Atmospherefilter</description>
<servlet-name>Atmospherefilter</servlet-name>
<servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
<init-param>
<param-name>applicationClassName</param-name>
<param-value>com.myapp.wicket.Application</param-value>
</init-param>
<init-param>
<param-name>configuration</param-name>
<param-value>development</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.useWebSocket</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.useNative</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.cpr.CometSupport.maxInactiveActivity</param-name>
<param-value>30000</param-value>
</init-param>
<init-param>
<param-name>filterMappingUrlPattern</param-name>
<param-value>/*</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.websocket.WebSocketProtocol</param-name>
<param-value>org.atmosphere.websocket.protocol.EchoProtocol</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.cpr.broadcastFilterClasses</param-name>
<param-value>org.apache.wicket.atmosphere.TrackMessageSizeFilter</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Atmospherefilter</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
WEB-INF/beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>
WEB-INF/glassfish-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<parameter-encoding default-charset="UTF-8"/>
<class-loader delegate="true"/>
</glassfish-web-app>
com/myapp/wicket/DebugWicketFilter.java
public class DebugWicketFilter extends WicketFilter {
private static final Logger log = LoggerFactory.getLogger(DebugWicketFilter.class);
#Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
log.info("URI: " + request.toString());
super.doFilter(request, response, chain);
}
}
Full stacktrace:
WicketMessage: Method onRequest of interface org.apache.wicket.behavior.IBehaviorListener targeted at org.apache.wicket.ajax.markup.html.AjaxLink$1#32048 on component [AjaxLink [Component id = link]] threw an exception
java.lang.NullPointerException
at org.apache.wicket.protocol.http.servlet.ServletWebRequest.getContextRelativeUrl(ServletWebRequest.java:194)
at org.apache.wicket.protocol.http.servlet.ServletWebRequest.<init>(ServletWebRequest.java:113)
at org.apache.wicket.protocol.http.servlet.ServletWebRequest.<init>(ServletWebRequest.java:83)
at org.apache.wicket.protocol.http.WebApplication.newWebRequest(WebApplication.java:448)
at org.apache.wicket.atmosphere.EventBus.post(EventBus.java:318)
at org.apache.wicket.atmosphere.EventBus.postToSingleResource(EventBus.java:298)
at org.apache.wicket.atmosphere.EventBus.post(EventBus.java:273)
at com.myapp.wicket.HomePage$1.onClick(HomePage.java:28)
at org.apache.wicket.ajax.markup.html.AjaxLink$1.onEvent(AjaxLink.java:86)
at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:123)
at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:626)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:258)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:241)
at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:247)
at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:226)
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:861)
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261)
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)
at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:201)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:282)
at com.myapp.wicket.DebugWicketFilter.doFilter(DebugWicketFilter.java:34)
at org.atmosphere.util.AtmosphereFilterChain.doFilter(AtmosphereFilterChain.java:155)
at org.atmosphere.util.AtmosphereFilterChain.invokeFilterChain(AtmosphereFilterChain.java:132)
at org.atmosphere.handler.ReflectorServletProcessor$FilterChainServletWrapper.service(ReflectorServletProcessor.java:314)
at org.atmosphere.handler.ReflectorServletProcessor.onRequest(ReflectorServletProcessor.java:172)
at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:256)
at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:166)
at org.atmosphere.container.GrizzlyCometSupport.service(GrizzlyCometSupport.java:119)
at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:1307)
at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:293)
at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:279)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)

The spring bean is not injected if I call a method in the post-constructed class

I am doing a spring bean injection to my jsf managed bean property for which am getting the above mentioned error. The following is the full stack trace:
SEVERE: Error Rendering View[/sample.xhtml]
javax.faces.FacesException: Could not retrieve value of component with path : {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /sample.xhtml][Class: javax.faces.component.html.HtmlForm,Id: j_id1848100722_6e27c746][Class: javax.faces.component.html.HtmlBody,Id: j_id1848100722_6e27c740][Class: javax.faces.component.html.HtmlInputText,Id: j_id1848100722_6e27c7f4]}
at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getValue(RendererUtils.java:347)
at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getStringValue(RendererUtils.java:291)
at org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.renderInputBegin(HtmlTextRendererBase.java:169)
at org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.renderInput(HtmlTextRendererBase.java:158)
at org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.encodeEnd(HtmlTextRendererBase.java:75)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:618)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1159)
at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:263)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:85)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
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:225)
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:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
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:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
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)
Caused by: javax.faces.FacesException: java.lang.reflect.InvocationTargetException
at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:228)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.createManagedBean(ManagedBeanResolver.java:303)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.getValue(ManagedBeanResolver.java:266)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
at org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:65)
at org.apache.myfaces.el.convert.VariableResolverToELResolver.getValue(VariableResolverToELResolver.java:96)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:72)
at org.apache.el.parser.AstValue.getValue(AstValue.java:147)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at org.apache.myfaces.view.facelets.el.TagValueExpression.getValue(TagValueExpression.java:85)
at javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:243)
at javax.faces.component.UIOutput.getValue(UIOutput.java:71)
at javax.faces.component.UIInput.getValue(UIInput.java:143)
at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getValue(RendererUtils.java:343)
... 30 more
Caused by: java.lang.reflect.InvocationTargetException
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.apache.catalina.core.DefaultInstanceManager.postConstruct(DefaultInstanceManager.java:212)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:154)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:146)
at org.apache.myfaces.config.annotation.Tomcat7AnnotationLifecycleProvider.newInstance(Tomcat7AnnotationLifecycleProvider.java:68)
at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:162)
... 46 more
Caused by: java.lang.NullPointerException
at common.beans.StartBean.fillTable(StartBean.java:35)
... 55 more
My web xml is the following:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>testjsf</display-name>
<welcome-file-list>
<welcome-file>sample.xhtml</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener- class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
My application context is the following:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="springb" class="common.springbeans.Springbean">
</bean>
</beans>
My faces-config is the following:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<managed-bean>
<managed-bean-name>userbean</managed-bean-name>
<managed-bean-class>common.beans.StartBean</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
<managed-property>
<property-name>ispringBeans</property-name>
<value>#{springb}</value>
</managed-property>
</managed-bean>
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
</faces-config>
The jars I included are the following:
Lastly this is the piece of code where I am trying to inject:
public class StartBean implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String value;
private boolean val;
private ArrayList<TestModel> list;
private TestModel tm;
private IDataFillBean bean;
private IspringBeans ispringBeans;
#PostConstruct
public void fillTable(){
setList(new ArrayList<TestModel>(0));
list = (ArrayList<TestModel>) ispringBeans.fillDatamodel();
}
}
It seems a direct injection. Am I missing anything here?
Please guide me. Thanks in advance.
EDIT: Now, I removed #postConstruct annotation from the class fillTable, called fillTable from "action" of commandButton and this exception goes off, Does this mean during #postConstruct method call the spring bean still wont be injected into the properties?
I have tested with a new application with new eclipse juno having mojarra and it seem to work fine. So the problem turns out to be Myfaces.

Resources