[
https://issues.apache.org/jira/browse/FELIX-990?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12683412#action_12683412
]
Clement Escoffier commented on FELIX-990:
-----------------------------------------
Hi,
The issue makes sense, but the error message should be better.
In fact, inside a composite bind/unbind methods receives service reference from
the local service context (local service registry). In the above code, you try
to get the service from the global context by using the local service
reference. So, the getservice method fails. The error message should be
something like : "Cannot get a local service from the global service registry".
To fix it, just get the factory service from the "regular" bundle context (the
one injected in your constructor).
Regards,
Clement
> ServiceReference cast exception, in Composite
> ---------------------------------------------
>
> Key: FELIX-990
> URL: https://issues.apache.org/jira/browse/FELIX-990
> Project: Felix
> Issue Type: Bug
> Components: iPOJO
> Affects Versions: iPOJO-1.2.0
> Environment: Java 1.6, Felix 1.4.0
> Reporter: Jonathan Bardin
>
> This bug appear in a composite while you try to get an iPOJO Factory Service
> with its "composite ServiceReference" from the Global BundleContext.
> Metadata:
> -----------------------------------------------------------------------------------------------
> ...
> <wbp:wbp
> filter="(&(remote.proxy=true)(factory.state=1)(objectClass=org.apache.felix.ipojo.Factory))"
>
> onArrival="bindFactory"
> onDeparture="unbindFactory" />
> ...
> -----------------------------------------------------------------------------------------------
> Code:
> -----------------------------------------------------------------------------------------------
> BundleContext m_globalcontext;
> ....
> public IpojoProxyManager(BundleContext bc) {
> m_globalcontext = ((IPojoContext) bc).getGlobalContext();
> ....
> }
> private void bindFactory(ServiceReference factoryref) {
> ....
> Factory factory = (Factory) m_globalcontext.getService(factoryref);
> // <--- ClassCastException
> ....
> }
> ------------------------------------------------------------------------------------------------
> Exception:
> ------------------------------------------------------------------------------------------------
> -> [Thread-4] ERROR homega.remote.proxymanagers.ipojoproxymanager - [ERROR]
> homega.remote.proxymanagers.IpojoProxyManager : The onArrival method
> bindFactory has thrown an exception
> java.lang.ClassCastException:
> org.apache.felix.ipojo.context.ServiceReferenceImpl cannot be cast to
> org.apache.felix.framework.ServiceReferenceImpl
> at
> org.apache.felix.framework.ServiceRegistry.getService(ServiceRegistry.java:222)
> at org.apache.felix.framework.Felix.getService(Felix.java:2853)
> at
> org.apache.felix.framework.BundleContextImpl.getService(BundleContextImpl.java:357)
> at
> homega.remote.proxymanagers.IpojoProxyManager.__bindFactory(IpojoProxyManager.java:216)
> ------------------------------------------------------------------------------------------------
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.