[jbossseam-issues] [JBoss JIRA] Commented: (JBSEAM-1023) Looking up a filtered SMPC in non-faces servlet throws NPE
Christian Bauer (JIRA)
jira-events at lists.jboss.org
Sun Mar 18 13:42:37 EDT 2007
[ http://jira.jboss.com/jira/browse/JBSEAM-1023?page=comments#action_12356486 ]
Christian Bauer commented on JBSEAM-1023:
-----------------------------------------
This seems to reproduce it:
FileServlet.java:
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
if (DOWNLOAD_PATH.equals(request.getPathInfo())) {
String id = request.getParameter("fileId");
File file = null;
// TODO: Seam should use its transaction interceptor for java beans: http://jira.jboss.com/jira/browse/JBSEAM-957
UserTransaction userTx = null;
boolean startedTx = false;
try {
userTx = Transactions.getUserTransaction();
if (userTx.getStatus() != javax.transaction.Status.STATUS_ACTIVE) {
startedTx = true;
userTx.begin();
}
// TODO: This is a workaround for http://jira.jboss.com/jira/browse/JBSEAM-1023
System.out.println("##### ACCESS LEVEL: " + org.jboss.seam.Component.getInstance("currentAccessLevel"));
EntityManager em = ((EntityManager)org.jboss.seam.Component.getInstance("restrictedEntityManager"));
em.joinTransaction();
@Factory method:
/**
* Assigns the context variable 'currentAccessLevel' when no user is logged in.
* @return Integer Guest access level.
*/
@Factory(value = "currentAccessLevel", scope = ScopeType.SESSION, autoCreate = true)
public Integer getGuestAccessLevel() {
return ((Role)Component.getInstance("guestRole")).getAccessLevel();
}
components.xml:
<core:filter name="accessLevelFilter">
<core:name>accessLevelFilter</core:name>
<core:parameters>
<key>currentAccessLevel</key>
<value>#{currentAccessLevel}</value>
</core:parameters>
</core:filter>
<core:managed-persistence-context name="restrictedEntityManager"
auto-create="true"
entity-manager-factory="#{wikiEntityManagerFactory}">
<core:filters><value>#{accessLevelFilter}</value></core:filters>
</core:managed-persistence-context>
Exception:
18:38:09,088 DEBUG [ContextFilter] beginning request
18:38:09,088 DEBUG [Lifecycle] >>> Begin web request
18:38:09,088 DEBUG [Manager] No stored conversation, or concurrent call to the stored conversation
18:38:09,089 INFO [STDOUT] ##### ACCESS LEVEL: 0
18:38:09,089 DEBUG [SessionImpl] opened session at timestamp: 11742394890
18:38:09,089 ERROR [ExceptionFilter] uncaught exception
java.lang.RuntimeException: javax.faces.el.EvaluationException: Cannot get value for expression '#{currentAccessLevel}'
at org.jboss.seam.wiki.core.ui.FileServlet.doGet(FileServlet.java:95)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:130)
at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:107)
at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:78)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:383)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
at org.jboss.seam.web.ContextFilter.doFilter(ContextFilter.java:56)
at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:53)
at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:613)
Caused by: javax.faces.el.EvaluationException: Cannot get value for expression '#{currentAccessLevel}'
at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:402)
at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:57)
at org.jboss.seam.persistence.HibernatePersistenceProvider.enableFilter(HibernatePersistenceProvider.java:60)
at org.jboss.seam.core.ManagedPersistenceContext.initEntityManager(ManagedPersistenceContext.java:85)
at org.jboss.seam.core.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:105)
at sun.reflect.GeneratedMethodAccessor832.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.seam.util.Reflections.invoke(Reflections.java:20)
at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:123)
at org.jboss.seam.Component.callComponentMethod(Component.java:1834)
at org.jboss.seam.Component.unwrap(Component.java:1860)
at org.jboss.seam.Component.getInstance(Component.java:1657)
at org.jboss.seam.Component.getInstance(Component.java:1610)
at org.jboss.seam.Component.getInstance(Component.java:1604)
at org.jboss.seam.wiki.core.ui.FileServlet.doGet(FileServlet.java:75)
... 39 more
Caused by: java.lang.NullPointerException
at org.apache.myfaces.el.ValueBindingImpl$ELVariableResolver.resolveVariable(ValueBindingImpl.java:574)
at org.apache.commons.el.NamedValue.evaluate(NamedValue.java:124)
at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:383)
... 54 more
> Looking up a filtered SMPC in non-faces servlet throws NPE
> ----------------------------------------------------------
>
> Key: JBSEAM-1023
> URL: http://jira.jboss.com/jira/browse/JBSEAM-1023
> Project: JBoss Seam
> Issue Type: Bug
> Components: Core
> Reporter: Christian Bauer
> Assigned To: Gavin King
> Priority: Minor
> Fix For: 1.2.1.GA
>
>
> My servlet does:
> EntityManager em = ((EntityManager)org.jboss.seam.Component.getInstance("entityManager"));
> em.joinTransaction();
> file = (!"".equals(id)) ? em.find(File.class, Long.parseLong(id)) : null;
> This worked OK, but after I enabled this filter:
> <core:filter name="accessLevelFilter">
> <core:name>accessLevelFilter</core:name>
> <core:parameters>
> <key>currentAccessLevel</key>
> <value>#{currentAccessLevel}</value>
> </core:parameters>
> </core:filter>
> <core:managed-persistence-context name="entityManager"
> auto-create="true"
> entity-manager-factory="#{wikiEntityManagerFactory}">
> <core:filters><value>#{accessLevelFilter}</value></core:filters>
> </core:managed-persistence-context>
> It fails with:
> Caused by: java.lang.NullPointerException: facesContext
> at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:379)
> at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:57)
> at org.jboss.seam.persistence.HibernatePersistenceProvider.enableFilter(HibernatePersistenceProvider.java:60)
> at org.jboss.seam.core.ManagedPersistenceContext.initEntityManager(ManagedPersistenceContext.java:85)
> at org.jboss.seam.core.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:105)
> at sun.reflect.GeneratedMethodAccessor1775.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
> at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:121)
> at org.jboss.seam.Component.callComponentMethod(Component.java:1834)
> at org.jboss.seam.Component.unwrap(Component.java:1860)
> at org.jboss.seam.Component.getInstance(Component.java:1657)
> at org.jboss.seam.Component.getInstance(Component.java:1610)
> at org.jboss.seam.Component.getInstance(Component.java:1604)
> at org.jboss.seam.wiki.core.ui.FileServlet.doGet(FileServlet.java:70)
> The expression "#{currentAccessLevel}" can either be resolved to a variable in the SESSION context or to a factory method on one of my components.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the seam-issues
mailing list