I tried to build an REST Client via CXF. The following code works within the junit environment.
JAXRSClientFactoryBean bean2 = new JAXRSClientFactoryBean();
bean2.setAddress("http://localhost:8181/cxf/treenodeService/");
bean2.setResourceClass(ITreeNodeService.class);
bean2.setProviders( Arrays.asList(new TreeNodeBeanProvider()) );
ITreeNodeService treeService = bean2.create(ITreeNodeService.class);
List<TreeNodeBean> treeNodeBeans = treeService.getNodes();
assertEquals("We expected only one node, the global", 1, treeNodeBeans.size());
But if I try this code within the osgi environment, it fails because of missing dependencies. So what is the minimal set of dependencies I need for this code to run within an equinox / osgi environment?
Currently I have added
javax.ws.rs.javax.ws.rs-api;bundle-version="2.0.0",
org.apache.cxf.cxf-rt-frontend-jaxrs;bundle-version="2.7.10",
org.apache.cxf.cxf-api;bundle-version="2.7.10",
org.apache.cxf.cxf-rt-core;bundle-version="2.7.10",
org.apache.cxf.cxf-rt-bindings-xml;bundle-version="2.7.10",
org.apache.cxf.cxf-rt-transports-http;bundle-version="2.7.10",
org.apache.cxf.cxf-rt-transports-http-jetty;bundle-version="2.7.10",
javax.wsdl;bundle-version="1.6.2",
UPDATE -1- Missing dependencies
These are the missing dependencies I get from the validation from eclipse.
Sincerely
Ok I didn't get it up and running. So I switch to CXF - DOSGI, using the dependencies listed above. (But different version) Then I had to solve another issue due to a missing http transport. In the end the code for accessing a REST service via an OSGI REST client looks like.
JAXRSClientFactoryBean sf = new JAXRSClientFactoryBean();
sf.setResourceClass(serviceClass);
sf.setAddress("http://" + getServerUrl() + "/cxf/" + serviceName);
sf.setProviders(providers);
ConduitInitiatorManager cim = sf.getBus().getExtension(ConduitInitiatorManager.class);
cim.registerConduitInitiator("http://cxf.apache.org/transports/http",
new HTTPTransportFactory(sf.getBus()));
service = sf.create(serviceClass);
Further reading link
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.