Eclipse RCP/RAP and Remoting with JAX-RS, Spring Data JPA and CXF DOSGi [step2]
In [step1] we have downloaded CXF DOSGi “Multi Bundle Distribution” and created the fr.opensagres.remoting.exporter.dosgi.jaxrs bundle
to export on server side the UserService#findAll() with JAX-RS:
@Path("/user")
public interface UserService {
@GET
@Path("/findAll")
@Produces(MediaType.APPLICATION_JSON)
Collection<User> findAll();
...
}
In this article we will create the importer bundle fr.opensagres.remoting.importer.dosgi.jaxrs which will create a JAX-RS Client with Spring bean :
<jaxrs:client id="jaxrsUserService" address="http://127.0.0.1:9000/fr/opensagres/services/UserService" serviceClass="fr.opensagres.services.UserService" inheritHeaders="true"> </jaxrs:client>
and will register this JAX-RS Client in the OSGi register services as UserService :
<osgi:service ref="jaxrsUserService" interface="fr.opensagres.services.UserService" />
For recall, the Simple Client bundle fr.opensagres.simpleclient consumes a UserService in the Thread FindAllUsersThread from the OSGi registry services and display User list every 5 seconds. In our case the UserService instance will be the JAX-RS Client retrieved from the OSGi registry services :
<osgi:reference id="userService" interface="fr.opensagres.services.UserService" cardinality="0..1" timeout="1000" />
This JAX-RS Client UserService will be setted in the FindAllUsersThread with Dependency Injection :
<bean id="FindAllUsersThread" class="fr.opensagres.simpleclient.FindAllUsersThread" init-method="start" destroy-method="interrupt"> <property name="userService" ref="userService"></property> </bean>
This FindAllUsersThread (client side) consumes the UserService#findAll() every 5 seconds to display user list on the console :
// 1) findAll
users = userService.findAll();
displayUsers("findAll", users);

