Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSGi Declarative Services, Component Reference, Target Parse Error for LDAP AND-Filter #26

Closed
boeffi opened this issue Oct 24, 2010 · 11 comments

Comments

@boeffi
Copy link

boeffi commented Oct 24, 2010

copy from [equinox-dev]
http://dev.eclipse.org/mhonarc/lists/equinox-dev/msg06472.html

Hello Boeffi,

Thank you for your kind words about bndtools :-)

The ampersand does need to be escaped as & in the generated
component XML, to comply with normal XML rules. This sounds like a bug
in bnd's annotation processor, it should be escaping the string that
you provide via the annotation.

Please could you raise a bug against bnd via its issue tracker on
GitHub: http://github.com/bnd/bnd/issues

Until the problem is fixed, it should be possible workaround it by
simply writing & directly in the annotation property.

Regards,
Neil

On Sun, Oct 24, 2010 at 7:32 PM, cu@xxxxxxxxxx cu@xxxxxxxxxx wrote:

Hello from Germany,

this is my first post to this list. I hope you can help me or we can help us
together.

I get an IOException if I define a LDAP AND-Filter-Expression for selection
an appropriate target service (details see below):
...target='(&(test=A)(test2=B1))'

The problem is the boolean ldap-and-operator, the ampersand.

After adjusting the "&" to "& amp;" (without the white space) the parse error is gone as expected.
I'm not sure, but can this be the intention? Must the filter definition
(with the original LDAP syntax) adjusted to make it compatible to the xml
universum?

The component.xml was generated from my sources by the great Bndtools from
Neil Bartlett (a small advert ;-)
:
@reference(name="testRef",optional=true,dynamic=true,target="(&(test=A)(test2=B1))")
private void bind(ITest test, Map<String, ?> configuration) {...}

I'm pleased to read your suggestions?

cu
Boeffi

using the jars from helios 3.6.1

  • org.eclipse.osgi_3.6.1.R36x_v20100806.jar
  • org.eclipse.equinox.ds_1.2.1.R36x_v20100803.jar
  • org.eclipse.equinox.util_1.0.200.v20100503.jar
  • org.eclipse.osgi.services_3.2.100.v20100503.jar

copy'n'paste corrected for readability:

< component name='test.TestComponent' xmlns='http://www.osgi.org/xmlns/scr/v1.1.0' immediate='true' activate='activate' deactivate='deactivate' >
< implementation class='test.TestComponent' />

< reference name='testRef' interface='test.ITest' cardinality='0..1' bind='bind' unbind='unbind' policy='dynamic' target='(&(test=A)(test2=B1))' />

< reference name='testRef2' interface='test.ITest' cardinality='0..1' bind='bind2' unbind='unbind2' policy='dynamic' target='(test2=B2)' />

< /component>

osgi> !SESSION 2010-10-24 19:36:01.914

eclipse.buildId=unknown
java.version=1.6.0_21
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=de_DE

!ENTRY test.a.service 4 0 2010-10-24 19:36:01.916
!MESSAGE [SCR] Error occurred while opening component definition file
bundleentry://4.fwk724000057/OSGI-INF/test.TestComponent.xml
!STACK 0
java.io.IOException: [Line: 4, Pos: 169] ';' expected.
at org.eclipse.equinox.internal.util.xml.impl.XMLParserImpl.err(XMLParserImpl.java:1062)
at org.eclipse.equinox.internal.util.xml.impl.XMLParserImpl.err(XMLParserImpl.java:1048)
at org.eclipse.equinox.internal.util.xml.impl.XMLParserImpl.parse_EntityRef(XMLParserImpl.java:978)
at org.eclipse.equinox.internal.util.xml.impl.XMLParserImpl.parse_attr_value(XMLParserImpl.java:303)
at org.eclipse.equinox.internal.util.xml.impl.XMLParserImpl.parse_attr(XMLParserImpl.java:357)
at org.eclipse.equinox.internal.util.xml.impl.XMLParserImpl.parse_attr_list(XMLParserImpl.java:389)
at org.eclipse.equinox.internal.util.xml.impl.XMLParserImpl.parse_tag_normal(XMLParserImpl.java:520)
at org.eclipse.equinox.internal.util.xml.impl.XMLParserImpl.parse_tag(XMLParserImpl.java:814)
at org.eclipse.equinox.internal.util.xml.impl.XMLParserImpl.parse_tag_normal(XMLParserImpl.java:545)
at org.eclipse.equinox.internal.util.xml.impl.XMLParserImpl.parseXML(XMLParserImpl.java:1100)
at org.eclipse.equinox.internal.util.xml.XMLParser.parseXML(XMLParser.java:95)
at org.eclipse.equinox.internal.ds.model.DeclarationParser.parse(DeclarationParser.java:107)
at org.eclipse.equinox.internal.ds.ComponentStorage.parseXMLDeclaration(ComponentStorage.java:87)
at org.eclipse.equinox.internal.ds.storage.file.FileStorage.loadComponentDefinitions(FileStorage.java:92)
at org.eclipse.equinox.internal.ds.SCRManager.startedBundle(SCRManager.java:586)
at org.eclipse.equinox.internal.ds.SCRManager.bundleChanged(SCRManager.java:234)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:919)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:227)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:149)
at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEventPrivileged(Framework.java:1349)
at
org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1300)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:380)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:284)
at bndtools.launcher.BundleInstaller.performStarts(BundleInstaller.java:351)
at bndtools.launcher.BundleInstaller.performAllChanges(BundleInstaller.java:244)
at bndtools.launcher.BundleInstaller.synchronizeBundles(BundleInstaller.java:134)
at bndtools.launcher.BundleInstaller.run(BundleInstaller.java:85)
at java.lang.Thread.run(Thread.java:619)


equinox-dev mailing list
equinox-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/equinox-dev

@boeffi
Copy link
Author

boeffi commented Oct 24, 2010

Until the problem is fixed, it should be possible workaround it by
simply writing & directly in the annotation property.

Unfortunately, I get then this error:
Description Resource Path Location Type
Service-ComponentInvalid Service-Component header: test.TestComponent {}, throws java.lang.IllegalArgumentException: Filter mismatch: expected ) at position 2 : (& amp;(test=A)(test2=B1)) bnd.bnd /test.a.service line 1 Bnd OSGi Problem Marker

It's only working for me, if I adjust the "&" with "& amp;" (without the white space) directly in the generated component.xml.

cu
Boeffi

@njbartlett
Copy link
Member

It looks like many of the escaped string above got substituted for the real thing in the transition to GitHub. To be clear, when bnd sees an [ampersand] in the target property of a @reference annotation, it needs to replace with [ampersand]amp;

The same goes for other XML entities, i.e. quot, apos, lt, gt.

@boeffi
Copy link
Author

boeffi commented Oct 24, 2010

Ok, I have corrected my copy'n'paste because of the substituted characters.

Summarizing:
when I write the [ampersand] directly in the @reference ... target attribute, the syntax checking inside eclipse is ok and the generated component.xml contains the [ampersand]. At runtime I get the (parser) exception.

cu
Boeffi

@njbartlett
Copy link
Member

Sorry that sounds different from what I oriniginally understood.

Are you saying that when the XML contains a properly escaped ampersand, the DS runtime throws an exception? That sounds like a runtime error, you may need to go back and report it against Equinox or Felix.

Could you paste (a) the generated component.xml and (b) the stack trace of the runtime exception?

@boeffi
Copy link
Author

boeffi commented Oct 24, 2010

(a) and (b) see above

My Java Source contains a single ampersand char. Compiling is OK.

The generated component.xml contains then a single(!) ampersand char (not escaped).
In this case I get a runtime exception.

If I do manually correct (in the generated component.xml) the single ampersand to [ampersand] a m p ; (without the white spaces, replace the square brackets with a single ampersand char) I get no runtime exception.

@njbartlett
Copy link
Member

Okay good. That's what I expected, but I got confused.

So bnd just needs to perform the escaping correctly when generating component XMLs. In the meantime you can work around by putting the fully escaped [ampersand]amp; in your source.

Unfortunately your code will then break as soon as the correct escaping is implemented! Bnd would generate: "[ampersand]amp;amp;". Perhaps the fix should include a check to make sure that the string is not already escaped in the source.

@boeffi
Copy link
Author

boeffi commented Oct 24, 2010

As you mentioned above, bnd have to escape the XML entities before storing them into the generated component.xml (that's was I'm doing manually with the [ampersand])
Am I right?

//Sorry, I have written my post parallel to you answer

@boeffi
Copy link
Author

boeffi commented Oct 24, 2010

In the meantime you can work around by putting the
fully escaped [ampersand]amp; in your source.

The "source" is the generated component.xml !

(writing the fully escaped [ampersand]amp; in the java source I get the
"...Filter mismatch: expected ) at position 2...")

Now, you have the workaround confirmed and I'm waiting for the bnd bug fix.
(May be I can help? Is the bug contained in bnd or the bndtools?)

cu
Boeffi

@njbartlett
Copy link
Member

Sorry I'm confused again. When I said "source" I always meant Java source, not component.xml (that file is generated, so it cannot be "source").

Let's try to reconfirm this again. What happens when you put the fully escaped [ampersand]amp; in your JAVA source?

A contributed patch would certainly be welcome. The bug is in bnd, not bndtools, that's why I directed you to this bug tracker. Bndtools is just UI on top of bnd.

@pkriens
Copy link
Member

pkriens commented Oct 25, 2010

You cannot use & because the filter is verified :-( So I made a fix that is in the repo now, version 1.12.0

@pkriens
Copy link
Member

pkriens commented Oct 25, 2010

the & in the previous comment should read "& a m p ;", seems Github changes the entity also

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants