You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Ephemeris Lappis <ep...@gmail.com> on 2012/07/24 12:23:58 UTC

Property in OSGi service reference filter attribute

Hello.

I've tried to define in a blueprint a reference to an OSGi service using a
filter which value should be a property configured in an external
configuration file (etc/*.cfg).

It works as expected and the service is actually found when the filter value
is just given as a simple string.

	<reference
		id="my.db"
		interface="javax.sql.DataSource"
		filter="(osgi.jndi.service.name=jdbc/derby)" />

When I change the filter value using "${my.ds}", it fails, with this logged
error :

org.osgi.service.blueprint.container.ComponentDefinitionException:
org.osgi.framework.InvalidSyntaxException: Invalid operator:
)(objectClass=javax.sql.DataSource))

I've checked my properties placeholder logging the property value from a
camel route, using {{my.ds}}, and the value is actually resolved.

Somebody knows if property expressions are allowed in this filter attribute
?

Thanks for your help.




--
View this message in context: http://servicemix.396122.n5.nabble.com/Property-in-OSGi-service-reference-filter-attribute-tp5713964.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Property in OSGi service reference filter attribute

Posted by Ephemeris Lappis <ep...@gmail.com>.
Hello.

Thanks for your explanations. In this case, what should be a good way to
configure objects names, like the data source of my case, and injects them
throw an indirection, like the bundles properties in my example ?

My idea is to allow the target bundle designer to provide a local name and
resolve it at deployment time using the execution environment objects. This
is the way JEE let you give a local name to reference resources in your
code, and resolve it at deployment time, binding this local name to the
selected global server JNDI name.

Thanks for your help.



--
View this message in context: http://servicemix.396122.n5.nabble.com/Property-in-OSGi-service-reference-filter-attribute-tp5713964p5713986.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Property in OSGi service reference filter attribute

Posted by Hendy Irawan <he...@soluvas.com>.
This is awesome!!!

Thanks for sharing!

Hendy
On Dec 19, 2012 12:54 AM, "spandit2 [via ServiceMix]" <
ml-node+s396122n5715300h88@n5.nabble.com> wrote:

> I was able to solve this issue . I  have added a custom element with its
> own namespace to the service reference .  So My service reference
> definition looks like this
>
> *<reference id="ValidationService"
> interface="com.csc.fs.BreezWay.intf.AppEntryValidation"
>                 availability="optional" filter="(org.name=*)">
>                 <BW:BWExtElement>
>                         <BW:ProcessFilter>true</BW:ProcessFilter>
>                 </BW:BWExtElement>
>         </reference>*
>
> I also registered a namespacehandle for this custom namespace. This
> namespacehandler bean is like any other service which could be initialized
> using the properties .  The service definition for the namespace handler
> looks like this .
>
> *<service auto-export="interfaces" ref="BWNSHandler">
>   <service-properties>
>   <entry key="service.exported.interfaces" value="*"></entry>
>   <entry key="osgi.service.blueprint.namespace" value="
> http://com.csc.fs.bw.services/BWExt">
> </entry></service-properties></service>*
>
> When the Aries parser detects this custom element in the reference , it
> executes decorate method on corresponding namespace handler passing the
> reference metadata that it has created before . In this decorate method
> then I process the filter as I want to using the property values set on the
> namespacehandler bean .
>
> public ComponentMetadata decorate(Node arg0, ComponentMetadata arg1,
>                         ParserContext arg2) {
>                 ReferenceMetadataImpl r = (ReferenceMetadataImpl) arg1;
>                 String f = r.getFilter();
>                 int i=  f.indexOf('*');
>                 if(i>0 && f.contains("org.name") && f.contains("*")){
>                         f= f.replace("*", orgName);
>                 }
>                 r.setFilter(f);
>                 return arg1;
>         }
>
> One issue I ran into was the aries parser was not able to locate  my
> custom schema which I have included in the / resources folder of the bundle
> . So I had to turn off the validation by setting  bundle symbolic name of
> the bundle to AppEntryValidationRoute;blueprint.aries.xml-validation:=false
> .
>
> Hope this helps
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://servicemix.396122.n5.nabble.com/Property-in-OSGi-service-reference-filter-attribute-tp5713964p5715300.html
>  To unsubscribe from Property in OSGi service reference filter attribute, click
> here<http://servicemix.396122.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5713964&code=aGVuZHlAc29sdXZhcy5jb218NTcxMzk2NHwxNTI0Njc4NzUy>
> .
> NAML<http://servicemix.396122.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://servicemix.396122.n5.nabble.com/Property-in-OSGi-service-reference-filter-attribute-tp5713964p5715301.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Property in OSGi service reference filter attribute

Posted by spandit2 <sp...@csc.com>.
I was able to solve this issue . I  have added a custom element with its own
namespace to the service reference .  So My service reference definition
looks like this 

*<reference id="ValidationService"
interface="com.csc.fs.BreezWay.intf.AppEntryValidation"
		availability="optional" filter="(org.name=*)">
		<BW:BWExtElement>
			<BW:ProcessFilter>true</BW:ProcessFilter>
		</BW:BWExtElement>
	</reference>*

I also registered a namespacehandle for this custom namespace. This
namespacehandler bean is like any other service which could be initialized
using the properties .  The service definition for the namespace handler
looks like this . 

*<service auto-export="interfaces" ref="BWNSHandler">
  	<service-properties>
  		<entry key="service.exported.interfaces" value="*"></entry>
  		<entry key="osgi.service.blueprint.namespace"
value="http://com.csc.fs.bw.services/BWExt"></entry></service-properties></service>*

When the Aries parser detects this custom element in the reference , it
executes decorate method on corresponding namespace handler passing the
reference metadata that it has created before . In this decorate method then
I process the filter as I want to using the property values set on the
namespacehandler bean . 

public ComponentMetadata decorate(Node arg0, ComponentMetadata arg1,
			ParserContext arg2) {
		ReferenceMetadataImpl r = (ReferenceMetadataImpl) arg1;
		String f = r.getFilter();
		int i=  f.indexOf('*');
		if(i>0 && f.contains("org.name") && f.contains("*")){
			f= f.replace("*", orgName);
		}
		r.setFilter(f);
		return arg1;
	}

One issue I ran into was the aries parser was not able to locate  my custom
schema which I have included in the / resources folder of the bundle . So I
had to turn off the validation by setting  bundle symbolic name of the
bundle to AppEntryValidationRoute;blueprint.aries.xml-validation:=false .

Hope this helps 




--
View this message in context: http://servicemix.396122.n5.nabble.com/Property-in-OSGi-service-reference-filter-attribute-tp5713964p5715300.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Property in OSGi service reference filter attribute

Posted by spandit2 <sp...@csc.com>.
Freeman 

Is there any other way of dynamically setting the filter value ? This is
permited when you export the services . The service registration can read
the properties from property place holder . 

So my question is is there any way I can set filter dynamically rather than
hardcoding in the camel context ?


Thanks
Sunil



--
View this message in context: http://servicemix.396122.n5.nabble.com/Property-in-OSGi-service-reference-filter-attribute-tp5713964p5715163.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Property in OSGi service reference filter attribute

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

No, it isn't allowed. Placholders in blueprint only works as metadata, that said, only element which actually is underlying  org.osgi.service.blueprint.reflect.ValueMetadata could be substituted during runtime. Those metadata elements generally are some thing like value="xxx" in xml. 

Freeman
-------------
Freeman Fang

FuseSource
Email:ffang@fusesource.com
Web: fusesource.com
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com
http://blog.sina.com.cn/u/1473905042
weibo: http://weibo.com/u/1473905042

On 2012-7-24, at 下午6:23, Ephemeris Lappis wrote:

> Hello.
> 
> I've tried to define in a blueprint a reference to an OSGi service using a
> filter which value should be a property configured in an external
> configuration file (etc/*.cfg).
> 
> It works as expected and the service is actually found when the filter value
> is just given as a simple string.
> 
> 	<reference
> 		id="my.db"
> 		interface="javax.sql.DataSource"
> 		filter="(osgi.jndi.service.name=jdbc/derby)" />
> 
> When I change the filter value using "${my.ds}", it fails, with this logged
> error :
> 
> org.osgi.service.blueprint.container.ComponentDefinitionException:
> org.osgi.framework.InvalidSyntaxException: Invalid operator:
> )(objectClass=javax.sql.DataSource))
> 
> I've checked my properties placeholder logging the property value from a
> camel route, using {{my.ds}}, and the value is actually resolved.
> 
> Somebody knows if property expressions are allowed in this filter attribute
> ?
> 
> Thanks for your help.
> 
> 
> 
> 
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/Property-in-OSGi-service-reference-filter-attribute-tp5713964.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Property in OSGi service reference filter attribute

Posted by Hendy Irawan <he...@soluvas.com>.
Thank you Freeman,

I've posted it at :
http://aries.15396.n3.nabble.com/Property-in-OSGi-service-reference-filter-attribute-td4025643.html

Hendy



--
View this message in context: http://servicemix.396122.n5.nabble.com/Property-in-OSGi-service-reference-filter-attribute-tp5713964p5714877.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Property in OSGi service reference filter attribute

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

I'd say post this question on aries blueprint mailing list first there.

Freeman
-------------
Freeman(Yue) Fang

Red Hat, Inc. 
FuseSource is now part of Red Hat
Web: http://fusesource.com | http://www.redhat.com/
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com
http://blog.sina.com.cn/u/1473905042
weibo: http://weibo.com/u/1473905042

On 2012-11-7, at 下午6:55, Hendy Irawan wrote:

> Hi all,
> 
> I'm also in need of this functionality.
> 
> e.g. we have lots of references like this which we expect to work :
> 
> <reference id="ldapPool" interface="org.apache.commons.pool.ObjectPool"
> 
> filter="(&amp;(tenantId=${tenantId})(tenantEnv=${tenantEnv})(namespace=ldap))"/>
> 
> which actually doesn't work. :-(
> 
> So we need to duplicate a lot of Blueprint XML files and replace the values
> using other means.
> 
> Is this feature planned? This would be very useful. I'm also glad we're not
> the only one needing this feature.
> Should we post a JIRA? (to Aries Blueprint project?)
> 
> Hendy
> 
> 
> 
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/Property-in-OSGi-service-reference-filter-attribute-tp5713964p5714857.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Property in OSGi service reference filter attribute

Posted by Hendy Irawan <he...@soluvas.com>.
No we didn't have a satisfying resolution.

Our "solution" (actually, a cumbersome workaround) is to:
1. Separate bundles with their "global" Blueprint XML vs. tenant-specific
Blueprint XML
2. Hardcode the property values in tenant-specific Blueprint XML and deploy
them individually. Each "module" will have its own blueprint file so these
modules can fail independently.
3. The tenant-specific Blueprint XMLs have hardcoded values for filters,
however most values like config come from CM. The filters are the only
blocker that makes us need to configure each tenant specifically.
Fortunately, the difference of XML due to this filter is quite minimal and
even obvious (i.e. for larger number of tenants, a simple
string-replacement script will do the job).

There is also another complication because cannot use even simple
expressions like string concatenation in property-set values, i.e.
"${tenantId}_${tenantEnv}" won't work, we have to either a) create a new
property with merged values, or b) provide 2 properties independently and
let the constructor do the concatenation.

Here's an example Blueprint that we use, containing 2 references with
hardcoded filters, everything else is provided by CM:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
    xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.1.0"
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
    http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0
      http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.1.0
http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.1.0">

<cm:property-placeholder persistent-id="berbatik" update-strategy="none">
<cm:default-properties>
<cm:property name="neo4jPrefix" value="berbatik_dev" />
</cm:default-properties>
</cm:property-placeholder>

<reference id="graphDb" interface="org.neo4j.graphdb.GraphDatabaseService"
filter="(tenantId=berbatik)" />
<reference id="eventBus" interface="com.google.common.eventbus.EventBus"
filter="(tenantId=berbatik)" ext:proxy-method="classes" />

<!--
PersonLikeShop Repo only handles likes from Person to Shop
-->
<bean id="personLikeShopRepo"
class="id.co.bippo.like.Neo4jPersonLikeShopRepository">
<argument ref="graphDb" />
<argument value="${neo4jPrefix}" />
</bean>
<service ref="personLikeShopRepo" auto-export="interfaces">
<service-properties>
<entry key="clientId" value="${clientId}" />
<entry key="tenantEnv" value="${tenantEnv}" />
<entry key="tenantId" value="${tenantId}" />
<entry key="namespace" value="person-like-shop" />
</service-properties>
</service>

<!--
PersonLikeProduct Repo only handles likes from Person to Product
-->
<bean id="personLikeProductRepo"
class="id.co.bippo.like.Neo4jPersonLikeProductRepository">
<argument ref="graphDb" />
<argument value="${neo4jPrefix}" />
</bean>
<service ref="personLikeProductRepo" auto-export="interfaces">
<service-properties>
<entry key="clientId" value="${clientId}" />
<entry key="tenantEnv" value="${tenantEnv}" />
<entry key="tenantId" value="${tenantId}" />
<entry key="namespace" value="person-like-product" />
</service-properties>
</service>

<!-- LikeManager is Bippo specific, handles everything for Bippo's LIKE -->
<bean id="likeMgr" class="id.co.bippo.like.LikeManagerImpl"
depends-on="personLikeShopRepo personLikeProductRepo">
<argument ref="personLikeShopRepo" />
<argument ref="personLikeProductRepo" />
<argument ref="eventBus" />
</bean>
<service ref="likeMgr" auto-export="interfaces">
<service-properties>
<entry key="clientId" value="${clientId}" />
<entry key="tenantEnv" value="${tenantEnv}" />
<entry key="tenantId" value="${tenantId}" />
<entry key="namespace" value="" />
</service-properties>
</service>
</blueprint>


Hope this helps.

Hendy


On Wed, Dec 5, 2012 at 12:38 PM, Sunil Pandit <sp...@csc.com> wrote:

>
> Hi Hendy
>
> I saw your post at
>
>
> http://aries.15396.n3.nabble.com/Property-in-OSGi-service-reference-filter-attribute-td4025643.html
>
> regarding using property value for filter in service reference .
>
> Were you able to resolve this issue ? If so do you mind sharing your
> solution ?
>
> I am running into exact same situation.
>
> Thanks
> Sunil Pandit
> CSC
>
> 200 West Cesar Chavez., Austin, TX 78701
> Financial Services Sector  |  p: +1-512-2755792 | spandit2@csc.com  |
> www.csc.com
>
> This is a PRIVATE message. If you are not the intended recipient, please
> delete without copying and kindly advise us by e-mail of the mistake in
> delivery. NOTE: Regardless of content, this e-mail shall not operate to
> bind CSC to any order or other contract unless pursuant to explicit written
> agreement or government initiative expressly permitting the use of e-mail
> for such purpose.
>
>


-- 
Hendy Irawan - on Twitter <http://twitter.com/hendybippo> - on
LinkedIn<http://id.linkedin.com/in/hendyirawan>
Web Developer | Bippo Indonesia <http://www.bippo.co.id/> | Akselerator
Bisnis | Bandung




--
View this message in context: http://servicemix.396122.n5.nabble.com/Property-in-OSGi-service-reference-filter-attribute-tp5713964p5715151.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Property in OSGi service reference filter attribute

Posted by Hendy Irawan <he...@soluvas.com>.
Hi all,

I'm also in need of this functionality.

e.g. we have lots of references like this which we expect to work :

<reference id="ldapPool" interface="org.apache.commons.pool.ObjectPool"

filter="(&amp;(tenantId=${tenantId})(tenantEnv=${tenantEnv})(namespace=ldap))"/>

which actually doesn't work. :-(

So we need to duplicate a lot of Blueprint XML files and replace the values
using other means.

Is this feature planned? This would be very useful. I'm also glad we're not
the only one needing this feature.
Should we post a JIRA? (to Aries Blueprint project?)

Hendy



--
View this message in context: http://servicemix.396122.n5.nabble.com/Property-in-OSGi-service-reference-filter-attribute-tp5713964p5714857.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.