You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by Pierre De Rop <pi...@alcatel-lucent.fr> on 2008/07/19 10:28:49 UTC

Need more logs from Declarative Service Runtime

Hello everyone,

We are using Declarative Service for dependency injection in our 
internal A5350 Alcatel-Lucent application server (which is now running 
on Felix! :-) ).

... And most of the time, when we start from scratch writing a new SCR 
service component, we generally fail to get our service activated 
because of stupid syntax errors from our SCR.xml descriptors.
I know there is a maven SCR plugin which uses javadoc tags in order to 
generate SCR.xml, but :

    * We don't use maven at all (for now)
    * For now, we don't wish to add a layer on top of Declarative
      Service -> we just wish to rely on the SCR.xml (and webconsole for
      inspecting component states using a web browser).

For example, last week, I came across the following (stupid) syntax 
error in my SCR.xml file and it took me several hours in order to
find out why my components was not actually enabled by the declarative 
service runtime:

Here is my erroneous SCR.xml, which contains two errors:

<components>  *<!-- **ERROR: this element is not part of the SCR xml 
schema -->*

    <component name='SipContainer'>
      <implementation
    class="com.alcatel_lucent.as.sip.server.SipServerActivator"/>

        <reference name="config"
    interface="java.util.Dictionary"                            
        bind="setConfig"
        target="(service.pid=SipContainer)"/>
     
     *<!-- ERROR: the following ref has the ame ref name as the previous
    one -->*
     
     <reference name='config'
    interface='com.alcatel.sip.stack.TransportService'    
        bind='bind'
        unbind='unbind'/>
    </component>

    <component name="SipApplicationDeployer">
    <implementation
    class="com.alcatel_lucent.as.sip.server.SipApplicationDeployer"/>
      ...
    </component>

</components> -> ERROR !


-> as you can notice, there are two mistakes in that file:

   1. my two components are embedded in a root xml element "<components>
      ... </components>"
   2. the component "SipContainer" contains two references with the SAME
      name: "config" -> it's an error

So, what is really annoying is that even if I activate the ds logger: 
"ds.loglevel=debug" -> the SCR don't logs any thing :-( , mainly because 
my SCR.xml is well formed, and has a correct syntax ...
Now, after having removed the wrong "<components> </components>" 
element, my components are started, but I still get an exception in one 
of my component's activate method, because there are still the second 
error (the two references in the "SipContainer" component do have  the 
same name: "config" !).





-> So, would it be possible to just

   1. add some WARNING message in the SCR xml parser in order to fire an
      exception or logs something
   2. detect duplicated reference names for a given component


It think that this modification is not really a big deal ! for instance, 
in 
felix-trunk/scr/src/main/java/org/apache/felix/scr/impl/XmlHandler.java, 
you could just add the following logs at the end of the startElement method:
 
public void startElement( String uri, String localName, Properties 
attrib ) throws ParseException {
  ....

   if ( localName.equals( "component" ) ) {
      ...
   } else if ( localName.equals( "implementation" ) ) {
      ...
   } else { // -> Raise an exception (or just log a WARN) ->
       throw new ParseException("Invalid xml element found in 
Declarative Service descriptor: " + localName, new Exception());
   }
}


These fix would be very appreciated !
Kind Regards

/Pierre


Re: Need more logs from Declarative Service Runtime

Posted by Carsten Ziegeler <cz...@apache.org>.
Pierre De Rop wrote:
> oups, I missed that point ! you are right: multi-components can be 
> specified in two ways:
> 
> 1/
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
>    <scr:component enabled="true" name="Component1">
>        <scr:implementation class="test.ds.hello.HelloComponent"/>
>        <scr:reference name="logService" 
> interface="org.osgi.service.log.LogService" ...
>    </scr:component>
> 
>    <scr:component enabled="true" name="Component2">
>        <scr:implementation class="test.ds.hello.HelloComponent"/>
>        <scr:reference name="logService" 
> interface="org.osgi.service.log.LogService" ...
>    </scr:component>
> </components>
> 
> 
> as well as:
> 
> 
> 2/
> 
> <?xml version='1.0' encoding='utf-8'?>
>  <component name="Component1">
>    <implementation class="test.ds.hello.HelloComponent"/>
>    <reference name="LOG" interface="org.osgi.service.log.LogService" ...
>  </component>
> 
>  <component name=""Component2">
>    <implementation class="test.ds.hello.HelloComponent"/>
>    <reference name="LOG" interface="org.osgi.service.log.LogService" ...
>  </component>
> 
> 
> I did not know the case 1/ and always used the case 2/
No problem :) I'm actually not sure if case 2 is really allowed. Our scr
implementation is able to read this xml, but it's not a valid xml 
document, so I guess it's safer to use case 1. Please note that actually
the name of the root element can be anything. So even
<foo xmlns:scr=".."/>
    <scr:component...>
</foo>
should work.

Carsten

-- 
Carsten Ziegeler
cziegeler@apache.org

Re: Need more logs from Declarative Service Runtime

Posted by Pierre De Rop <pi...@alcatel-lucent.fr>.
oups, I missed that point ! you are right: multi-components can be 
specified in two ways:

1/

<?xml version="1.0" encoding="UTF-8"?>
<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
    <scr:component enabled="true" name="Component1">
        <scr:implementation class="test.ds.hello.HelloComponent"/>
        <scr:reference name="logService" 
interface="org.osgi.service.log.LogService" ...
    </scr:component>

    <scr:component enabled="true" name="Component2">
        <scr:implementation class="test.ds.hello.HelloComponent"/>
        <scr:reference name="logService" 
interface="org.osgi.service.log.LogService" ...
    </scr:component>
</components>


as well as:


2/

<?xml version='1.0' encoding='utf-8'?>
  <component name="Component1">
    <implementation class="test.ds.hello.HelloComponent"/>
    <reference name="LOG" interface="org.osgi.service.log.LogService" ...
  </component>

  <component name=""Component2">
    <implementation class="test.ds.hello.HelloComponent"/>
    <reference name="LOG" interface="org.osgi.service.log.LogService" ...
  </component>


I did not know the case 1/ and always used the case 2/
Thanks.

/pierre



Carsten Ziegeler wrote:
> Pierre De Rop wrote:
>> I have created a new JIRA issue about that and have provided a patch.
>
>
> Thanks, I've two comments :)
>
> - Could you please provide the patch as an attachment of the bug?
> - Afaik the "components" is allowed as the root element. But if you
>   want to have several component definitions inside this root element,
>   you have to use the scr namespace (see 112.4.1).
>   The SCR Plugin for instance, generates such a "components" root
>   element and this works without problems.
>
> Carsten
>


Re: Need more logs from Declarative Service Runtime

Posted by Carsten Ziegeler <cz...@apache.org>.
Pierre De Rop wrote:
> I have created a new JIRA issue about that and have provided a patch.


Thanks, I've two comments :)

- Could you please provide the patch as an attachment of the bug?
- Afaik the "components" is allowed as the root element. But if you
   want to have several component definitions inside this root element,
   you have to use the scr namespace (see 112.4.1).
   The SCR Plugin for instance, generates such a "components" root
   element and this works without problems.

Carsten

-- 
Carsten Ziegeler
cziegeler@apache.org

Re: Need more logs from Declarative Service Runtime

Posted by Pierre De Rop <pi...@alcatel-lucent.fr>.
I have created a new JIRA issue about that and have provided a patch.
Thanks
/Pierre

Richard S. Hall wrote:
> These sound like some good suggestions. If you haven't already, you 
> should open up a JIRA issue so that it can be tracked. If you have a 
> suggested patch, feel tree to attach it too.
>
> Thanks for the feedback.
>
> -> richard
>
> Pierre De Rop wrote:
>> Hello everyone,
>>
>> We are using Declarative Service for dependency injection in our 
>> internal A5350 Alcatel-Lucent application server (which is now 
>> running on Felix! :-) ).
>>
>> ... And most of the time, when we start from scratch writing a new 
>> SCR service component, we generally fail to get our service activated 
>> because of stupid syntax errors from our SCR.xml descriptors.
>> I know there is a maven SCR plugin which uses javadoc tags in order 
>> to generate SCR.xml, but :
>>
>>    * We don't use maven at all (for now)
>>    * For now, we don't wish to add a layer on top of Declarative
>>      Service -> we just wish to rely on the SCR.xml (and webconsole for
>>      inspecting component states using a web browser).
>>
>> For example, last week, I came across the following (stupid) syntax 
>> error in my SCR.xml file and it took me several hours in order to
>> find out why my components was not actually enabled by the 
>> declarative service runtime:
>>
>> Here is my erroneous SCR.xml, which contains two errors:
>>
>> <components>  *<!-- **ERROR: this element is not part of the SCR xml 
>> schema -->*
>>
>>    <component name='SipContainer'>
>>      <implementation
>>    class="com.alcatel_lucent.as.sip.server.SipServerActivator"/>
>>
>>        <reference name="config"
>>    interface="java.util.Dictionary"                                   
>> bind="setConfig"
>>        target="(service.pid=SipContainer)"/>
>>         *<!-- ERROR: the following ref has the ame ref name as the 
>> previous
>>    one -->*
>>         <reference name='config'
>>    interface='com.alcatel.sip.stack.TransportService'           
>> bind='bind'
>>        unbind='unbind'/>
>>    </component>
>>
>>    <component name="SipApplicationDeployer">
>>    <implementation
>>    class="com.alcatel_lucent.as.sip.server.SipApplicationDeployer"/>
>>      ...
>>    </component>
>>
>> </components> -> ERROR !
>>
>>
>> -> as you can notice, there are two mistakes in that file:
>>
>>   1. my two components are embedded in a root xml element "<components>
>>      ... </components>"
>>   2. the component "SipContainer" contains two references with the SAME
>>      name: "config" -> it's an error
>>
>> So, what is really annoying is that even if I activate the ds logger: 
>> "ds.loglevel=debug" -> the SCR don't logs any thing :-( , mainly 
>> because my SCR.xml is well formed, and has a correct syntax ...
>> Now, after having removed the wrong "<components> </components>" 
>> element, my components are started, but I still get an exception in 
>> one of my component's activate method, because there are still the 
>> second error (the two references in the "SipContainer" component do 
>> have  the same name: "config" !).
>>
>>
>>
>>
>>
>> -> So, would it be possible to just
>>
>>   1. add some WARNING message in the SCR xml parser in order to fire an
>>      exception or logs something
>>   2. detect duplicated reference names for a given component
>>
>>
>> It think that this modification is not really a big deal ! for 
>> instance, in 
>> felix-trunk/scr/src/main/java/org/apache/felix/scr/impl/XmlHandler.java, 
>> you could just add the following logs at the end of the startElement 
>> method:
>>
>> public void startElement( String uri, String localName, Properties 
>> attrib ) throws ParseException {
>>  ....
>>
>>   if ( localName.equals( "component" ) ) {
>>      ...
>>   } else if ( localName.equals( "implementation" ) ) {
>>      ...
>>   } else { // -> Raise an exception (or just log a WARN) ->
>>       throw new ParseException("Invalid xml element found in 
>> Declarative Service descriptor: " + localName, new Exception());
>>   }
>> }
>>
>>
>> These fix would be very appreciated !
>> Kind Regards
>>
>> /Pierre
>>
>>


Re: Need more logs from Declarative Service Runtime

Posted by "Richard S. Hall" <he...@ungoverned.org>.
These sound like some good suggestions. If you haven't already, you 
should open up a JIRA issue so that it can be tracked. If you have a 
suggested patch, feel tree to attach it too.

Thanks for the feedback.

-> richard

Pierre De Rop wrote:
> Hello everyone,
>
> We are using Declarative Service for dependency injection in our 
> internal A5350 Alcatel-Lucent application server (which is now running 
> on Felix! :-) ).
>
> ... And most of the time, when we start from scratch writing a new SCR 
> service component, we generally fail to get our service activated 
> because of stupid syntax errors from our SCR.xml descriptors.
> I know there is a maven SCR plugin which uses javadoc tags in order to 
> generate SCR.xml, but :
>
>    * We don't use maven at all (for now)
>    * For now, we don't wish to add a layer on top of Declarative
>      Service -> we just wish to rely on the SCR.xml (and webconsole for
>      inspecting component states using a web browser).
>
> For example, last week, I came across the following (stupid) syntax 
> error in my SCR.xml file and it took me several hours in order to
> find out why my components was not actually enabled by the declarative 
> service runtime:
>
> Here is my erroneous SCR.xml, which contains two errors:
>
> <components>  *<!-- **ERROR: this element is not part of the SCR xml 
> schema -->*
>
>    <component name='SipContainer'>
>      <implementation
>    class="com.alcatel_lucent.as.sip.server.SipServerActivator"/>
>
>        <reference name="config"
>    interface="java.util.Dictionary"                                   
> bind="setConfig"
>        target="(service.pid=SipContainer)"/>
>         *<!-- ERROR: the following ref has the ame ref name as the 
> previous
>    one -->*
>         <reference name='config'
>    interface='com.alcatel.sip.stack.TransportService'           
> bind='bind'
>        unbind='unbind'/>
>    </component>
>
>    <component name="SipApplicationDeployer">
>    <implementation
>    class="com.alcatel_lucent.as.sip.server.SipApplicationDeployer"/>
>      ...
>    </component>
>
> </components> -> ERROR !
>
>
> -> as you can notice, there are two mistakes in that file:
>
>   1. my two components are embedded in a root xml element "<components>
>      ... </components>"
>   2. the component "SipContainer" contains two references with the SAME
>      name: "config" -> it's an error
>
> So, what is really annoying is that even if I activate the ds logger: 
> "ds.loglevel=debug" -> the SCR don't logs any thing :-( , mainly 
> because my SCR.xml is well formed, and has a correct syntax ...
> Now, after having removed the wrong "<components> </components>" 
> element, my components are started, but I still get an exception in 
> one of my component's activate method, because there are still the 
> second error (the two references in the "SipContainer" component do 
> have  the same name: "config" !).
>
>
>
>
>
> -> So, would it be possible to just
>
>   1. add some WARNING message in the SCR xml parser in order to fire an
>      exception or logs something
>   2. detect duplicated reference names for a given component
>
>
> It think that this modification is not really a big deal ! for 
> instance, in 
> felix-trunk/scr/src/main/java/org/apache/felix/scr/impl/XmlHandler.java, 
> you could just add the following logs at the end of the startElement 
> method:
>
> public void startElement( String uri, String localName, Properties 
> attrib ) throws ParseException {
>  ....
>
>   if ( localName.equals( "component" ) ) {
>      ...
>   } else if ( localName.equals( "implementation" ) ) {
>      ...
>   } else { // -> Raise an exception (or just log a WARN) ->
>       throw new ParseException("Invalid xml element found in 
> Declarative Service descriptor: " + localName, new Exception());
>   }
> }
>
>
> These fix would be very appreciated !
> Kind Regards
>
> /Pierre
>
>