2

I'm updating from Apache Felix SCR Annotations to OSGi DS R6 ones and the one is causing me more problem is the @Property inside the class.

Before I had:

@Component (immediate = true)
@Service (A.class)
public class AImpl implements A
{
    @Property (intValue = 604800)
    public static final String A = "a";
    ...
}

Now I have:

@Component (service = A.class, immediate = true)
@Designate (ocd = Configuration.class)
public class AImpl implements A
{
    ...
}

and

@ObjectClassDefinition (name = "Bla")
public @interface Configuration
{
    @AttributeDefinition (name = "A", type = AttributeType.INTEGER)
    int A() default 604800;
}

The most bizarre thing on all of this is:

Before, I could see my AImpl class as a component.

Now, I couldn't see my AImpl class as a component and everyone who uses it cannot start because of unsatisfied references.

How come changing just configurations like this can cause this behaviour ? Maybe I'm missing something ?

The stranger part on all of this is my xml is inside the .jar and seems ok. The scr:info is getting me nullpointer exception and I cannot see my component, meaning the scr:list will no help in anything.

XML BELLOW:

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="AImpl" immediate="true" activate="init" deactivate="stop">
  <implementation class="AImpl"/>
  <service>
    <provide interface="A"/>
  </service>
  <reference name="Bla1" interface="Bla1Service" bind="bindBla1Service" unbind="unbindBla1Service"/>
  <property name="PROP.EVENT.INTERVAL" type="Long" value="900000"/>
</scr:component>

Ps.: The classes are with strange names and so on because it's from a private company.

STACKTRACE:

2017-12-11T16:40:27.689+0100 [Framework Event Dispatcher] ERROR o.o.p.l.l.internal.FrameworkHandler:144 frameworkEvent FrameworkEvent ERROR - org.apache.felix.scr org.osgi.framework.BundleException: The activator org.apache.felix.scr.impl.Activator for bundle org.apache.felix.scr is invalid at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:172) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:679) at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381) at org.eclipse.osgi.framework.internal.core.AbstractBundle.updateWorker(AbstractBundle.java:645) at org.eclipse.osgi.framework.internal.core.AbstractBundle.update(AbstractBundle.java:592) at org.apache.felix.webconsole.internal.core.UpdateHelper.doRun(UpdateHelper.java:60) at org.apache.felix.webconsole.internal.core.BaseUpdateInstallHelper.doRun(BaseUpdateInstallHelper.java:93) at org.apache.felix.webconsole.internal.core.UpdateHelper.doRun(UpdateHelper.java:70) at org.apache.felix.webconsole.internal.core.BaseUpdateInstallHelper.run(BaseUpdateInstallHelper.java:123) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.ClassCastException: org.apache.felix.scr.impl.Activator cannot be cast to org.osgi.framework.BundleActivator at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:167) ... 9 common frames omitted

Part of POM.XML who install on karaf my bundles:

<artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-kar-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <inherited>false</inherited>
                        <configuration>
                            <includeScope>runtime</includeScope>
                            <prependGroupId>true</prependGroupId>
                            <excludeTransitive>true</excludeTransitive>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.osgi</groupId>
                                    <artifactId>org.osgi.framework</artifactId>
                                    <version>${org.osgi.framework.version}</version>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.osgi</groupId>
                                    <artifactId>org.osgi.core</artifactId>
                                    <version>${org.osgi.core.version}</version>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.apache.felix</groupId>
                                    <artifactId>org.apache.felix.scr</artifactId>
                                    <version>${org.apache.felix.scr.version}</version>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
</execution>
</executions>
Tiberio
  • 73
  • 1
  • 6
  • Try to use the scr:list and scr:info commands to get more details on why the component is not coming up. Please add the output of scr:info or scr:details (depending on karaf version) to the question. – Christian Schneider Dec 05 '17 at 06:36
  • If I were you, I would check if the XML files are generated into the JAR file during the build process. After that I would check if the XML files have the right content. If the XML files are there, could you, please, attach them to this question? – Balazs Zsoldos Dec 05 '17 at 08:32
  • In addition to using the `scr:list` and `scr:info` commands, you should look in the OSGi log with the `log error` command. If for example the component threw an exception from its activate method then the details will show up in this log. – Neil Bartlett Dec 05 '17 at 08:49
  • Updated the main post... – Tiberio Dec 05 '17 at 12:11
  • The `scr:info` command should NOT give an NPE. Please show exactly what you typed and the output. Also please post the output of `scr:list`. I know you think that it won't help but just do it. Also please specify which SCR bundle and version you have running in your OSGi Framework, and ensure that it is in ACTIVE state. – Neil Bartlett Dec 06 '17 at 11:03
  • @Tiberio Have you given up? – Neil Bartlett Dec 07 '17 at 15:32
  • @NeilBartlett no ! I didn't, but I'm evolving with some time, I'll post some findings afterwards. What raullalves posted is true, I can see my component as a Configuration... – Tiberio Dec 08 '17 at 13:27
  • That just means that the Metatype service knows about the configuration PID, but it doesn't tell you anything about the state of the component. Still waiting for the output of `scr:list` and the bundle/version of SCR you are using... – Neil Bartlett Dec 08 '17 at 13:29
  • @NeilBartlett, I think now, the problem could be because we are not using the Felix on container, we are using Karaf + Equinox, we get some exception starting the felix.scr, telling me they cannot cast the Activator from osgi.core.framework.BundleActivator to Felix one... – Tiberio Dec 11 '17 at 14:32
  • It sounds like an error in your bundle. Have you included a copy of the `org.osgi.framework` package in your bundle instead of importing it? – Neil Bartlett Dec 11 '17 at 14:58
  • "Some exception" is not very useful, BTW. How about a stack trace? – Neil Bartlett Dec 11 '17 at 14:58
  • @NeilBartlett, the exception was: ClassCastException We removed all the references for felix.scr to test and we are not able to install our bundle, because we are getting some problem on "doesn't have osgi.extender" (the felix.scr provided this one...) – Tiberio Dec 11 '17 at 15:38
  • @Tiberio That's not a stack trace. Wow, you like to keep people guessing don't you :-/ – Neil Bartlett Dec 11 '17 at 15:40
  • @NeilBartlett Edited my question with stack trace – Tiberio Dec 11 '17 at 15:41
  • That's very weird. It suggests that SCR is not importing the `org.osgi.framework` package from the system bundle. But that could only happen if you have mucked about with SCR. Did you repackage the `org.apache.felix.scr` bundle in some way?? – Neil Bartlett Dec 11 '17 at 15:44
  • @NeilBartlett I'm trying to put on my karaf via maven-dependecy-plugin... but is not appearing at all, then I try to install mannualy the felix.scr and got that exception... updated the main question with part of pom.xml – Tiberio Dec 11 '17 at 16:00
  • I don't think you even need to install SCR into a Karaf server because Karaf already includes SCR. Maybe somebody who uses Karaf can confirm. – Neil Bartlett Dec 11 '17 at 16:02
  • @NeilBartlett, we're using Karaf of version 3.0.6, in which i'm not sure it already includes SCR. The SCR support started at 4.1.1 https://github.com/apache/karaf/blob/master/RELEASE-NOTES Unfortunately, we cannot update our Karaf version. – raullalves Dec 11 '17 at 16:12
  • I know nothing about Karaf versions but I don't see any reason why SCR cannot be installed. Just try an empty Karaf plus the SCR bundle and see what happens. Don't repackage or rebuild the SCR jar. – Neil Bartlett Dec 11 '17 at 19:40
  • @NeilBartlett, it perfectly worked at Karaf 4.1.3, as we know supports new SCR by default. However, it doesn't work at Karaf 3.0.6. The question now is how to make Karaf 3.0.6 work with the new SCR (>= 2.0.6) – raullalves Dec 12 '17 at 10:56
  • 1
    @raullalves You can't. Karaf 3.0.x supports only OSGi Release 5 (see https://karaf.apache.org/download.html#container) whereas SCR 2.x requires OSGi Release 6. You need to either upgrade Karaf to version 4.1.x or downgrade SCR to version 1.8.2. – Neil Bartlett Dec 12 '17 at 11:05
  • That's sad. Thanks, @NeilBartlett. – raullalves Dec 12 '17 at 11:16

2 Answers2

1

This part looks like the error: service=AImpl.class. Your component should be published as a service using its interface A, not the implementation class.

This normally happens implicitly because the component directly implements interface A, but you have overridden that.

The solution should be to simply delete the service=AImpl.class attribute from the @Component annotation.

Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77
  • Yes, this is for true some mistake on my part, but I changed to use the interface instead of implementation class and even like this I still cannot see it as component. – Tiberio Dec 05 '17 at 12:06
1

Your AImpl class still being a Component. However, now it's a "Configuration" Component, hence it has a @Designate annotation linking to a @ObjectClassDefinition Property class.

Go to the Configuration tab and you should see your Component and its properties.

raullalves
  • 836
  • 8
  • 20