Hi

I'm sorry, I did not quite get what the problem was,
it appears to be a class loading issue within the pax exam envrironment, given that it otherwise works for you in the production container...

Thanks, Sergey
On 16/04/14 09:45, Adrián Roselló Rey wrote:
Hi all!

I have an OSGI application in which I use Aries Blueprint to publish my
services and dOSGI to publish them through a REST API. My scenario consists
of two bundles: bundle A publishes serviceA and bundleB publish serviceB,
in which serviceA is injected:

*Bundle A / blueprint.xml*












*<bean id="serviceA" class="blabla.ServiceAImpl"/><service ref="serviceA"
interface="blabla.ServiceA">         <service-properties>            <!--
Rest -->            <entry key="service.exported.interfaces" value="*"/>
         <entry key="service.exported.configs" value="org.apache.cxf.rs
<http://org.apache.cxf.rs>"/>             <entry
key="service.exported.intents" value="HTTP"/>            <entry
key="org.apache.cxf.rs.httpservice.context"
value="${ws.rest.url}/serviceA"/>            <entry
key="org.apache.cxf.rs.address" value="/"/>             <entry
key="org.apache.cxf.httpservice.requirefilter" value="true"/>
</service-properties> </service>*

*Bundle B / blueprint.xml*

*<reference id="serviceA" interface="blabla.ServiceA"/>*















*<bean id="serviceB" class="blabla.ServiceBImpl">        <property
name="serviceA" ref="serviceA" /> </bean>  <service ref="serviceB"
interface="blabla.ServiceB">        <service-properties>            <!--
Rest -->            <entry key="service.exported.interfaces" value="*"/>
             <entry key="service.exported.configs" value="org.apache.cxf.rs
<http://org.apache.cxf.rs>"/>            <entry
key="service.exported.intents" value="HTTP"/>                <entry
key="org.apache.cxf.rs.httpservice.context"
value="${ws.rest.url}/serviceB"/>            <entry
key="org.apache.cxf.rs.address" value="/"/>            <entry
key="org.apache.cxf.httpservice.requirefilter" value="true"/>
<entry key="org.apache.cxf.rs.out.interceptors"
value="blabla.ServiceBOutInterceptor" />
</service-properties> </service>*


I deploy it in karaf and everything runs perfectly. The problem resides in
integration tests. I use Pax-Exam 3.4 as my testing platform, and I try to
test serviceB by calling the java interface as well as the REST API
published by dOSGI. Both tests are run in the same container.

In order to test the REST API I generate a client using
JAXRSClientFactoryBean provided by CXF. More specific, in my application
there0s a generic method to create clients with CXF



















*    public static <T> T createRestClient(String uri, Class<T>
clientInterface, List<? extends Object> providers, String username, String
password) {         ProxyClassLoader classLoader = new
ProxyClassLoader();
classLoader.addLoader(clientInterface.getClassLoader());
classLoader.addLoader(JAXRSClientFactoryBean.class.getClassLoader());
     JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(uri);        if (providers != null &&
!providers.isEmpty())            bean.setProviders(providers);
bean.setResourceClass(clientInterface);
bean.setClassLoader(classLoader);        if (username != null && password
!= null) {            bean.setUsername(username);
bean.setPassword(password);        }        return (T) bean.create();     }*


Now, the thing is that, even though the tests run in the same container,
the one testing the REST API fails with a NullPointer on ServiceBImpl,
since it doesn't have the injected serviceA in it. By debugging, I saw that
the ServiceBImpl instance "attacked" by the java interface and the one
"attacked" by the client are different (the object id does not match).

Any idea on why they does mismatch?

Thanks!

Best regards



Reply via email to