[seam-issues] [JBoss JIRA] Commented: (JBSEAM-4577) Seam Mail looks up template in wrong context on tomcat with shared seam
Erick Menezes (JIRA)
jira-events at lists.jboss.org
Mon Sep 5 22:34:26 EDT 2011
[ https://issues.jboss.org/browse/JBSEAM-4577?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12626311#comment-12626311 ]
Erick Menezes commented on JBSEAM-4577:
---------------------------------------
I had the same problem, not on tomcat, but JBoss AS instead.
I read the same articles on sfwk.org's forum about the shared JARs and was using an _CustomResourceResolver_. Debugging the Seam Mail I found out that the problem seems to come from the _RendererRequest_ class. A moment before the actual rendering of the mail to be send, it calls the method *faceletForViewId()* where it's return clause instantiates a _new DefaultResourcerResolver_ and here is the problem. Since we're using a _CustomResourceResolver_, the Default one will never find our desire resource.
A more generic solution that I have come up with was to extend the _org.jboss.seam.faces.Renderer_ class an installing it with a higher precedence and overriding the render method (that will be implemented by the _FaceletsRenderer_ class), changing only the _RendererRequest_ class that's instantiated for a custom one.
Instead of:
{code:title=RendererRequest.java}
protected Facelet faceletForViewId(String viewId) throws IOException
{
...
return new DefaultFaceletFactory(FaceletCompiler.instance(), new DefaultResourceResolver()).getFacelet(url);
}
{code}
I have:
{code:title=CustomRendererRequest.java}
protected Facelet faceletForViewId(String viewId) throws IOException
{
...
return new DefaultFaceletFactory(FaceletCompiler.instance(), getResourceResolver()).getFacelet(url);
}
{code}
So I implemented the getResourceResolver() method to find the Resolver defined on web.xml:
{code:title=CustomRendererRequest.java}
private ResourceResolver getResourceResolver()
{
String resolverClass = ServletLifecycle.getServletContext().getInitParameter("facelets.RESOURCE_RESOLVER");
try
{
return (ResourceResolver) Class.forName(resolverClass).newInstance();
}
catch (InstantiationException e)
{
e.printStackTrace();
return new DefaultResourceResolver();
}
catch (IllegalAccessException e)
{
e.printStackTrace();
return new DefaultResourceResolver();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
return new DefaultResourceResolver();
}
}
{code}
> Seam Mail looks up template in wrong context on tomcat with shared seam
> ------------------------------------------------------------------------
>
> Key: JBSEAM-4577
> URL: https://issues.jboss.org/browse/JBSEAM-4577
> Project: Seam 2
> Issue Type: Bug
> Components: Mail
> Affects Versions: 2.2.0.GA
> Environment: Tomcat 6.0.18, Seam 2.2.0.GA (shared)
> Reporter: Vasilii Lukoyanov
> Assignee: Pete Muir
> Labels: mail, shared_classloader
>
> I've got Tomcat with Seam jars shared among all projects (shared.loader=${catalina.base}/shared/seam/*.jar in catalina.properties). Each app has it's own vhost, and deployed to ROOT context.
> Layout is the following:
> vhosts/siteA.com/ROOT
> vhosts/siteB.com/ROOT
> Seam application on siteB.com uses seam mail to send confirmation emails. But when it tries to send a message (template is /layout/1email.xhtml)
> the following exception is thrown:
> javax.servlet.ServletException: #{mailer.sendPreActivationEmail}: java.lang.IllegalArgumentException: resource doesn't exist: /layout/1email.xhtml
> at javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
> at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:164)
> at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141)
> at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90)
> at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:406)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
> at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
> at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
> at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
> at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
> at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
> at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
> at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
> at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
> at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
> at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
> at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
> at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
> at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
> at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
> at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
> at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
> at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
> at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
> 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.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
> 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:286)
> at org.apache.coyote.ajp.AjpAprProcessor.process(AjpAprProcessor.java:419)
> at org.apache.coyote.ajp.AjpAprProtocol$AjpConnectionHandler.process(AjpAprProtocol.java:378)
> at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1509)
> at java.lang.Thread.run(Thread.java:619)
> Caused by: javax.faces.FacesException: #{mailer.sendPreActivationEmail}: java.lang.IllegalArgumentException: resource doesn't exist: /layout/1email.xhtml
> at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
> at javax.faces.component.UICommand.broadcast(UICommand.java:387)
> at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
> at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
> at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
> at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
> at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
> at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
> at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
> at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
> ... 39 more
> After some investigation I tried to put message template /layout/1email.xhtml into siteA.com context (vhosts/siteA.com/ROOT). After that I was able to send messages from siteB.com application.
> Seam Component that I use to send messages:
> @Name("mailer")
> @Scope(ScopeType.CONVERSATION)
> public class Mailer {
> @In("renderer")
> private Renderer _renderer;
> public void sendPreActivationEmail(Account aUser) {
> Contexts.getConversationContext().set("account", aUser);
> _renderer.render("/email/eganov_pre_activate.xhtml");
> }
> }
> Important note: when tomcat is starting, siteA.com loads first.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the seam-issues
mailing list