Problem with custom RenderViewHandler after upgrading from 5.1 to 5.3

We’ve extended RenderViewHandler with a custom RenderViewHandler as we need some custom view functions.

This worked just fine in 5.1, but failed after upgrading to 5.3.

Logs:

ERROR uppercase.xp.modules.bokstavenk - [uppercase.xp.modules.bokstavenk.thymeleaf.CustomRenderViewHandler] Cannot register Component
java.lang.IllegalStateException: Invalid BundleContext.
        at org.apache.felix.framework.BundleContextImpl.checkValidity(BundleContextImpl.java:514) ~[org.apache.felix.framework-4.4.1.jar:na]
        at org.apache.felix.framework.BundleContextImpl.getBundle(BundleContextImpl.java:112) ~[org.apache.felix.framework-4.4.1.jar:na]
        at org.apache.felix.scr.impl.ComponentRegistry.checkComponentName(ComponentRegistry.java:357) ~[org.apache.felix.scr-1.8.2.jar:na]

[...]

ERROR c.e.x.p.i.e.PortalExceptionMapper - Command [uc.render] not found
com.enonic.xp.resource.ResourceProblemException: Command [uc.render] not found
        at com.enonic.xp.resource.ResourceProblemException$Builder.build(ResourceProblemException.java:131) ~[na:na]
        at com.enonic.xp.portal.impl.script.error.ErrorHelper.doHandleException(ErrorHelper.java:54) ~[na:na]
package uppercase.xp.modules.bokstavenk.thymeleaf;

import com.enonic.xp.portal.PortalContextAccessor;
import com.enonic.xp.portal.script.command.CommandHandler;
import com.enonic.xp.portal.script.command.CommandRequest;
import com.enonic.xp.portal.view.ViewFunctionService;
import com.enonic.xp.resource.ResourceKey;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import uppercase.xp.modules.bokstavenk.thymeleaf.enonic.ThymeleafProcessor;
import uppercase.xp.modules.bokstavenk.thymeleaf.enonic.ThymeleafProcessorFactory;
import uppercase.xp.modules.bokstavenk.thymeleaf.enonic.ThymeleafViewFunctions;

@Component(immediate = true)
public class CustomRenderViewHandler implements CommandHandler {
    private final ThymeleafProcessorFactory factory;

    private ViewFunctionService viewFunctionService;

    public CustomRenderViewHandler()
    {
        this.factory = new ThymeleafProcessorFactory();
    }

    @Override
    public String getName()
    {
        return "uc.render";
    }

    @Override
    public Object execute( final CommandRequest req )
    {
        final ThymeleafProcessor processor = this.factory.newProcessor();
        processor.view( req.param( "view" ).required().value( ResourceKey.class ) );
        processor.parameters(req.param("model").map());
        processor.parameter("portal", createViewFunctions());
        processor.parameter("uc", new UppercaseViewFunctions());
        return processor.process();
    }

    @Reference
    public void setViewFunctionService( final ViewFunctionService value )
    {
        this.viewFunctionService = value;
    }

    private ThymeleafViewFunctions createViewFunctions()
    {
        final ThymeleafViewFunctions functions = new ThymeleafViewFunctions();
        functions.viewFunctionService = this.viewFunctionService;
        functions.context = PortalContextAccessor.get();
        return functions;
    }
}

(We made it work again temporary by building with 5.1 dependencies running on 5.3 instead, but this is probably not the best solution…)

Any ideas?

Hi.

It seems that the OSGi engine cannot register your service. Is it any other exceptions there besides the two you cut’n’pasted? It seems to me that it’s not a problem with the CommandHandler, but the way it registeres into the OSGi engine using declarative services.

This command handler is based on your standard RenderViewHandler, and it is declared more or less identical to RenderViewHandler. This works fine in 5.1.0, but breaks in 5.3.0

But is there another exception in the log? I see from the log that the service cannot be registered. Need to find out why.

No other exceptions, see full stack below:

2015-08-11 17:28:05,324 DEBUG o.a.a.b.container.BlueprintExtender - Starting BlueprintContainer destruction process for bundle uppercase.xp.modules.bokstavenk
2015-08-11 17:28:05,324 DEBUG o.a.a.b.container.BlueprintExtender - Not a blueprint bundle or destruction of BlueprintContainer already finished for uppercase.xp.modules.bokstavenk.
2015-08-11 17:28:05,324 DEBUG o.a.a.b.container.BlueprintExtender - Starting BlueprintContainer destruction process for bundle uppercase.xp.modules.bokstavenk
2015-08-11 17:28:05,324 DEBUG o.a.a.b.container.BlueprintExtender - Not a blueprint bundle or destruction of BlueprintContainer already finished for uppercase.xp.modules.bokstavenk.
2015-08-11 17:28:05,325 DEBUG o.a.a.b.container.BlueprintExtender - Scanning bundle uppercase.xp.modules.bokstavenk for blueprint application
2015-08-11 17:28:05,325 DEBUG o.a.a.b.container.BlueprintExtender - No blueprint application found in bundle uppercase.xp.modules.bokstavenk
2015-08-11 17:28:05,365 ERROR uppercase.xp.modules.bokstavenk - [uppercase.xp.modules.bokstavenk.thymeleaf.CustomRenderViewHandler] Cannot register Component
java.lang.IllegalStateException: Invalid BundleContext.
        at org.apache.felix.framework.BundleContextImpl.checkValidity(BundleContextImpl.java:514) ~[org.apache.felix.framework-4.4.1.jar:na]
        at org.apache.felix.framework.BundleContextImpl.getBundle(BundleContextImpl.java:112) ~[org.apache.felix.framework-4.4.1.jar:na]
        at org.apache.felix.scr.impl.ComponentRegistry.checkComponentName(ComponentRegistry.java:357) ~[org.apache.felix.scr-1.8.2.jar:na]
        at org.apache.felix.scr.impl.BundleComponentActivator.loadDescriptor(BundleComponentActivator.java:258) [org.apache.felix.scr-1.8.2.jar:na]
        at org.apache.felix.scr.impl.BundleComponentActivator.initialize(BundleComponentActivator.java:158) [org.apache.felix.scr-1.8.2.jar:na]
        at org.apache.felix.scr.impl.BundleComponentActivator.<init>(BundleComponentActivator.java:120) [org.apache.felix.scr-1.8.2.jar:na]
        at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:258) [org.apache.felix.scr-1.8.2.jar:na]
        at org.apache.felix.scr.impl.Activator.access$000(Activator.java:45) [org.apache.felix.scr-1.8.2.jar:na]
        at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:185) [org.apache.felix.scr-1.8.2.jar:na]
        at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:259) [org.apache.felix.scr-1.8.2.jar:na]
        at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:232) [org.apache.felix.scr-1.8.2.jar:na]
        at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:479) [org.apache.felix.scr-1.8.2.jar:na]
        at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:414) [org.apache.felix.scr-1.8.2.jar:na]
        at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232) [org.apache.felix.scr-1.8.2.jar:na]
        at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:443) [org.apache.felix.scr-1.8.2.jar:na]
        at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:869) [org.apache.felix.framework-4.4.1.jar:na]
        at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:790) [org.apache.felix.framework-4.4.1.jar:na]
        at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:515) [org.apache.felix.framework-4.4.1.jar:na]
        at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4429) [org.apache.felix.framework-4.4.1.jar:na]
        at org.apache.felix.framework.Felix.startBundle(Felix.java:2100) [org.apache.felix.framework-4.4.1.jar:na]
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:976) [org.apache.felix.framework-4.4.1.jar:na]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1245) [org.apache.felix.fileinstall-3.4.2.jar:3.4.2]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1217) [org.apache.felix.fileinstall-3.4.2.jar:3.4.2]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1207) [org.apache.felix.fileinstall-3.4.2.jar:3.4.2]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:504) [org.apache.felix.fileinstall-3.4.2.jar:3.4.2]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:358) [org.apache.felix.fileinstall-3.4.2.jar:3.4.2]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:310) [org.apache.felix.fileinstall-3.4.2.jar:3.4.2]

It seems that it does not hit our code. For me it looks like it’s some sort of mismatch between the SCR descriptors in your JAR file. Is the code available somewhere?