Expand my Community achievements bar.

SOLVED

Enable transformer only on publish

Avatar

Level 5

Hi guys,

 

I have set up an html transformer, but I only want to run it on publish. So I add my config under /apps/APPNAME/config/rewriter.publish like so

{
   "jcr:primaryType":"sling:Folder",
   "jcr:createdBy":"admin",
   "jcr:created":"Mon Jun 07 2021 15:56:31 GMT-0500",
   "panerabread":{
      "jcr:primaryType":"nt:unstructured",
      "enabled":true,
      "serializerType":"htmlwriter",
      "transformerTypes":[
         "linkchecker",
         "jsonlinksmapper"
      ],
      "path":[
         "/content/panerabread_com",
         "/content/panerabread_ca"
      ],
      "order":1,
      "contentTypes":[
         "text/html"
      ],
      "generatorType":"htmlparser",
      "generator-htmlparser":{
         "jcr:primaryType":"nt:unstructured",
         "includeTags":[
            "BUTTON",
            "IW-ORDER-SETUP-FLOW",
            "DIV",
            "META",
            "/META",
            "A",
            "/A",
            "/AREA",
            "FORM",
            "BASE",
            "LINK",
            "SCRIPT",
            "BODY",
            "/BODY",
            "VIDEO",
            "/VIDEO",
            "ASIDE",
            "/ASIDE",
            "SECTION",
            "/SECTION"
         ]
      }
   }
}

 

But it doesn't work. If I add another rewriter config under /apps/APPNAME/config/rewriter it works but it still picks up the attributes from the transformer under rewriter.publish.

 

Why is that?

 

BTW, I pulled the config from /apps/APPNAME/config/rewriter because often is there is some issue with the transformer factory components, it makes the application nearly unusable. As in, when it tries to render the login page, you get the following exception (or one very similar):

 

org.apache.sling.servlets.resolver.internal.SlingServletResolver Calling the error handler resulted in an error
org.apache.sling.api.scripting.ScriptEvaluationException: 
	at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:416)
	at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:184)
	at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:491)
	at org.apache.sling.servlets.resolver.internal.SlingServletResolver.handleError(SlingServletResolver.java:756)
	at org.apache.sling.servlets.resolver.internal.SlingServletResolver.handleError(SlingServletResolver.java:492)
	at org.apache.sling.engine.impl.DefaultErrorHandler.handleError(DefaultErrorHandler.java:133)
	at org.apache.sling.engine.impl.SlingRequestProcessorImpl$2.render(SlingRequestProcessorImpl.java:377)
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:77)
	at org.apache.sling.rewriter.impl.RewriterFilter.doFilter(RewriterFilter.java:83)
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)
	at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:138)
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)
	at org.apache.sling.engine.impl.SlingRequestProcessorImpl.handleError(SlingRequestProcessorImpl.java:384)
	at org.apache.sling.engine.impl.SlingRequestProcessorImpl.doProcessRequest(SlingRequestProcessorImpl.java:186)
	at org.apache.sling.engine.impl.SlingMainServlet.service(SlingMainServlet.java:219)
	at org.apache.felix.http.base.internal.handler.ServletHandler.handle(ServletHandler.java:85)
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:79)
	at com.adobe.granite.cors.impl.CORSHandler.doFilter(CORSHandler.java:118)
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)
	at com.adobe.granite.license.impl.LicenseCheckFilter.doFilter(LicenseCheckFilter.java:308)
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)
	at org.apache.felix.http.sslfilter.internal.SslFilter.doFilter(SslFilter.java:96)
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)
	at org.apache.sling.security.impl.ReferrerFilter.doFilter(ReferrerFilter.java:295)
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)
	at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:138)
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)
	at org.apache.sling.featureflags.impl.FeatureManager.doFilter(FeatureManager.java:116)
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)
	at org.apache.sling.engine.impl.log.RequestLoggerFilter.doFilter(RequestLoggerFilter.java:72)
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)
	at org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:128)
	at org.apache.felix.http.base.internal.dispatch.DispatcherServlet.service(DispatcherServlet.java:49)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
	at org.eclipse.jetty.server.Server.handle(Server.java:499)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
	at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.sling.api.SlingException: 
	at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspExceptionInternal(JspServletWrapper.java:691)
	at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:608)
	at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:533)
	at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:449)
	at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:346)
	at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:101)
	at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:607)
	at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:388)
	... 57 common frames omitted
Caused by: org.apache.sling.api.SlingException: Unable to setup processor: Unable to get component of class 'interface org.apache.sling.rewriter.Transformer' with type 'jsonlinksmapper'.
	at org.apache.sling.rewriter.impl.ProcessorManagerImpl.getProcessor(ProcessorManagerImpl.java:485)
	at org.apache.sling.rewriter.impl.RewriterResponse.getProcessor(RewriterResponse.java:172)
	at org.apache.sling.rewriter.impl.RewriterResponse.getWriter(RewriterResponse.java:110)
	at org.apache.sling.scripting.core.impl.helper.OnDemandWriter.getWriter(OnDemandWriter.java:38)
	at org.apache.sling.scripting.core.impl.helper.OnDemandWriter.write(OnDemandWriter.java:61)
	at java.io.PrintWriter.write(PrintWriter.java:426)
	at org.apache.sling.scripting.jsp.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:119)
	at org.apache.sling.scripting.jsp.jasper.runtime.PageContextImpl.release(PageContextImpl.java:191)
	at org.apache.sling.scripting.jsp.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:99)
	at org.apache.sling.scripting.jsp.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:71)
	at org.apache.sling.scripting.jsp.jasper.compiler.JspRuntimeContext$JspFactoryHandler.releasePageContext(JspRuntimeContext.java:112)
	at org.apache.jsp.libs.sling.servlet.errorhandler.default_jsp._jspService(default_jsp.java:323)
	at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
	at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:502)
	... 62 common frames omitted
Caused by: java.io.IOException: Unable to get component of class 'interface org.apache.sling.rewriter.Transformer' with type 'jsonlinksmapper'.
	at org.apache.sling.rewriter.impl.PipelineImpl.getPipelineComponent(PipelineImpl.java:160)
	at org.apache.sling.rewriter.impl.PipelineImpl.init(PipelineImpl.java:102)
	at org.apache.sling.rewriter.impl.ProcessorManagerImpl.getProcessor(ProcessorManagerImpl.java:478)
	... 76 common frames omitted

 

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Unfortunately the rewriter definition does not support runmodes. So you need to have your rewriter configured in both author and publish; and then add some runmode-based logic, which disables the actual rewriting process on author.

View solution in original post

6 Replies

Avatar

Correct answer by
Employee Advisor

Unfortunately the rewriter definition does not support runmodes. So you need to have your rewriter configured in both author and publish; and then add some runmode-based logic, which disables the actual rewriting process on author.

Avatar

Level 5
What about the issue with not being able to log in if a tranformer component fails to start? It sure makes troubleshooting things difficult.

Avatar

Employee Advisor
If a transformer is configured but not starting up, it's indeed an iusse. But I wonder if it's acceptable to ignore errors in the transformer and still try to render content. I rather prefer to fail early and loud instead of pretending everything is fine and it actually is not..

Avatar

Level 5
I prefer to fail early and loud on site pages but when it takes down the login page, that's a problem. Sure there are work arounds but it makes troubleshooting very, very difficult. And why are transformers special in that regard? If other components fail, AEM goes about its business without them.

Avatar

Community Advisor

Hi @jkpanera 

 

As @Jörg_Hoh mentioned earlier rewriter does not work based on runmode. So any transformer type you are using in your rewriter, there should be a mapping defined for each n every transformer type in your OSGi config. If any specific environment, it will not find the transfromer defined or missing, it will throw the exception like you see here for "jsonlinksmapper".

 

To fix the issue, you need to add a default config with "jsonlinksmapper" name in your "config" run mode which is applicable for all environments and then override the properties on the respective environemnt as required. This will ensure the component is present in all instance and your application will not fail.

 

Thanks!