Hi
I think the 1st option is better,
sf.setAddress(...) sets a relative address, this is equivalent to
jaxrs:server/@address (in Spring/Blueprint)
and then you can do setServiceBeans() with as many beans as needed, with
unique Path expressions
ResourceProvider manages a lifecycle, default is per-request.
FYI, Andriy Redko did a CDI integration, I haven't followed all the
developments for a while, but can CDI offer what Guice does ?
Perhaps CXF should ship a Guice integration module too...
Cheers, Sergey
On 27/07/15 03:19, KimJohn Quinn wrote:
I have a question about setting up CXF to provide RESTful endpoints through
Guice.
Is this along the right path?
Should I be injecting all of my resources like this or should I set each one up
individually using a new JAXRSServerFactoryBean?
Inject all of my resources using a single JAXRSServerFactoryBean:
@Inject
@WebResource
private Map<String, Provider<Object>> resources;
@Override
protected void loadBus(ServletConfig sc)
{
super.loadBus(sc);
final JAXRSServerFactoryBean sf = new
JAXRSServerFactoryBean();
sf.setBus(getBus());
sf.setAddress("/");
sf.setProvider(new JacksonJsonProvider());
sf.setResourceProviders(…);
sf.create();
}
Inject each of my resources using a new JAXRSServerFactoryBean:
for (String key : resources.keySet())
{
try
{
LOG.debug("------------------ {}", key);
final Provider<?> bean = resources.get(key);
final JAXRSServerFactoryBean sf = new
JAXRSServerFactoryBean();
sf.setBus(getBus());
sf.setAddress(key);
sf.setProvider(new JacksonJsonProvider());
sf.setResourceProvider(new
SingletonResourceProvider(bean.get()));
sf.create();
}
catch (Exception x)
{
LOG.error("Cannot start endpoint: ",
x.getMessage());
}
}
It looks like when I do it this way it will iterate through all of the resources for
a match where as when I set up each endpoint individually it matches that one only.
The problem I had with setting each up individually was that I could not get the
“setAddress(“http://localhost:8080/ <http://localhost:8080/>“)” and the root
resources @Path(“some-root”) to work properly…i ended up with the path twice (because
I set the address to “/some-root”).
Also, what is the difference between returning a ResourceProvider vs.
setServiceBean?