RE: Embedded portlet in theme throwing an

Siva Yedida, modified 8 Months ago. New Member Posts: 3 Join Date: 6/23/20 Recent Posts
We embedded our custom portlet in our theme. It worked without any issues/errors in dev environment. But in PROD, we're seeing the following error lot many times


Error executing FreeMarker template
FreeMarker template error:
Error while invoking the "runtime" JSP custom tag; see cause exception----
FTL stack trace ("~" means nesting-related):
    - Failed at: @liferay_portlet["runtime"] defaultPr...  [in template "my-theme_SERVLET_CONTEXT_/templates/portal_normal.ftl" at line 228, column 41]

So, at line 228 I embedded my portlet with the following code,
<#assign preferences = freeMarkerPortletPreferences.setValue("portletSetupPortletDecoratorId", "barebone")>
                    <@liferay_portlet["runtime"]
                    defaultPreferences="${preferences}"
                    portletProviderAction=portletProviderAction.VIEW
                    instanceId="myportletInstanceId"
                    portletName="myportlet" />
                    ${freeMarkerPortletPreferences.reset()}
I do not understand what is the issue, I've checked in so many liferay forums, what I did is correct. Can someone point out what could be the issue.
Thank you
thumbnail
Dominik Marks, modified 5 Years ago. Regular Member Posts: 149 Join Date: 8/29/12 Recent Posts
There is an error while executing the RuntimeTag. The server log would be helpful to see what is really causing the issue.
Siva Yedida, modified 8 Months ago. New Member Posts: 3 Join Date: 6/23/20 Recent Posts
Hi Dominik,
I don't see any errors in my local or dev environment with that code, I only see this error in PROD , that too not every time.Adding the server log,
FreeMarker template error:
Error while invoking the "runtime" JSP custom tag; see cause exception----
FTL stack trace ("~" means nesting-related):
    - Failed at: @liferay_portlet["runtime"] defaultPr...  [in template "my-theme_SERVLET_CONTEXT_/templates/portal_normal.ftl" at line 228, column 41]
----Java stack trace (for programmers):
----
freemarker.core._TemplateModelException: [... Exception message was already printed; see it above ...]
    at freemarker.ext.jsp.JspTagModelBase.toTemplateModelExceptionOrRethrow(JspTagModelBase.java:154)
    at freemarker.ext.jsp.TagTransformModel$TagWriter.onStart(TagTransformModel.java:367)
    at freemarker.core.Environment.visitAndTransform(Environment.java:422)
    at freemarker.core.UnifiedCall.accept(UnifiedCall.java:107)
    at freemarker.core.Environment.visit(Environment.java:324)
    at freemarker.core.MixedContent.accept(MixedContent.java:54)
    at freemarker.core.Environment.visitByHiddingParent(Environment.java:345)
    at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:48)
    at freemarker.core.Environment.visitByHiddingParent(Environment.java:345)
    at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:48)
    at freemarker.core.Environment.visit(Environment.java:324)
    at freemarker.core.MixedContent.accept(MixedContent.java:54)
    at freemarker.core.Environment.visit(Environment.java:324)
    at freemarker.core.Environment.process(Environment.java:302)
    at freemarker.template.Template.process(Template.java:325)
    at com.liferay.portal.template.freemarker.internal.FreeMarkerTemplate.processTemplate(FreeMarkerTemplate.java:123)
    at com.liferay.portal.template.AbstractSingleResourceTemplate.processTemplate(AbstractSingleResourceTemplate.java:78)
    at com.liferay.taglib.util.ThemeUtil.doIncludeFTL(ThemeUtil.java:280)
    at com.liferay.taglib.util.ThemeUtil.doDispatch(ThemeUtil.java:158)
    at com.liferay.taglib.util.ThemeUtil.includeFTL(ThemeUtil.java:97)
    at com.liferay.taglib.util.ThemeUtil.include(ThemeUtil.java:82)
    at com.liferay.taglib.theme.IncludeTag.doEndTag(IncludeTag.java:34)
    at org.apache.jsp.html.common.themes.portal_jsp._jspx_meth_liferay_002dtheme_005finclude_005f1(portal_jsp.java:713)
    at org.apache.jsp.html.common.themes.portal_jsp._jspService(portal_jsp.java:650)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:402)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:346)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:119)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:188)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:96)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:144)
    at com.liferay.frontend.compatibility.ie.servlet.filter.IEMimeTypeCompatibilityFilter.processFilter(IEMimeTypeCompatibilityFilter.java:56)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:49)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
    at com.liferay.portal.servlet.filters.password.modified.PasswordModifiedFilter.processFilter(PasswordModifiedFilter.java:58)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:49)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
    at com.liferay.saml.runtime.internal.servlet.filter.SamlSpSsoFilter.doProcessFilter(SamlSpSsoFilter.java:143)
    at com.liferay.saml.runtime.internal.servlet.filter.BaseSamlPortalFilter.processFilter(BaseSamlPortalFilter.java:47)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:49)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:144)
    at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.processFilter(VirtualHostFilter.java:377)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:49)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:188)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:96)
    at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
    at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
    at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:389)
    at com.liferay.portal.servlet.filters.urlrewrite.UrlRewriteFilter.processFilter(UrlRewriteFilter.java:65)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:49)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:168)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:96)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:168)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:96)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:101)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.jsp.JspFileHandler.handleRequest(JspFileHandler.java:32)
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51)
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:59)
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
    at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
    at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:285)
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:264)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:175)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:324)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:803)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: javax.servlet.jsp.JspException: com.liferay.portal.kernel.portlet.PortletContainerException: java.lang.IllegalStateException: UT010006: Cannot call getWriter(), getOutputStream() already called
    at com.liferay.taglib.portletext.RuntimeTag.doEndTag(RuntimeTag.java:353)
    at freemarker.ext.jsp.TagTransformModel$TagWriter.endEvaluation(TagTransformModel.java:400)
    at freemarker.ext.jsp.TagTransformModel$TagWriter.onStart(TagTransformModel.java:344)
    ... 99 more
thumbnail
Olaf Kock, modified 5 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
Siva Yedida:

Hi Dominik,
I don't see any errors in my local or dev environment with that code, I only see this error in PROD , that too not every time.Adding the server log,
...
Caused by: javax.servlet.jsp.JspException: com.liferay.portal.kernel.portlet.PortletContainerException: java.lang.IllegalStateException: UT010006: Cannot call getWriter(), getOutputStream() already called
    at com.liferay.taglib.portletext.RuntimeTag.doEndTag(RuntimeTag.java:353)
    at freemarker.ext.jsp.TagTransformModel$TagWriter.endEvaluation(TagTransformModel.java:400)
    at freemarker.ext.jsp.TagTransformModel$TagWriter.onStart(TagTransformModel.java:344)
    ... 99 more

It's a good guess that this is the root cause for your problem: It's also an explanation why it doesn't appear every single time.
One possibility is that your custom implementation tries to mock with the output stream, e.g. add a header, or wrap the stream, while some data has already been written to it and potentially processed or sent to the browser.
This often is environment dependent, e.g. caches are flushed based on available memory, OS parameters, or other circumstances. Thus they only appear once the environment changes (in load, OS, or configuration).
Not 100% sure, but these circumstances have bitten me ages ago. Does the portlet that you embed do any trickery with the output stream?
Also: Does your stacktrace continue with another "Caused by" clause? Because it seems that the exception reported here is another one further down the stream, that's just wrapped by RuntimeTag.doEndTag().
Which (exact) version are you using? Because line 353 doesn't match the source code that I looked up the tag's implementation