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



Reply via email to