Question

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.

  • com.wordnik.swagger.jaxrs.config
  • com.wordnik.swagger.jaxrs.listing
  • org.apache.ws.commons.schema
  • org.apache.ws.commons.schema.constants
  • org.apache.ws.commons.schema.extensions
  • org.apache.ws.commons.schema.resolver
  • org.apache.ws.commons.schema.utils

Sincerely

Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top