This should work very well! Thank you so much! I'll code it up tonight. I
will write an open source version of this in the very near future
On Sun, Mar 6, 2016 at 5:45 PM Benson Margulies <[email protected]>
wrote:

> On Sun, Mar 6, 2016 at 5:18 PM, James Carman <[email protected]>
> wrote:
> > It's karaf. I'm building a service that looks up at runtime the
> > configuration of the services and then "exports" them accordingly. I'd
> like
> > to support exporting via CXF and was looking for inspiration.
> > On Sun, Mar 6, 2016 at 5:16 PM Benson Margulies <[email protected]>
>
> I had built what you describe (DS component that had a
> multiple-cardinality reference that collected resources, and then set
> up a CXF service), but it could never work out the timing of startup.
> So, instead, I allow each service to export itself. The base class of
> all the services has the following. The depends on having the latest
> SCR from 4.0.4 and the following maven-bundle-plugin options.
>
> <_dsannotations>*</_dsannotations>
> <_dsannotations-options>inherit</_dsannotations-options>
>
> ......
>
>
> /**
>  * Start the service.
>  * @param resourcePath the resource path.
>  */
> protected void startService(String resourcePath) {
>
>     JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
>     // Setting the bus ensures that the TCCL is this bundle when our
> resource classes are called.
>     sf.setBus(cxfBus.bus());
>     sf.setProvider(new JacksonJaxbJsonProvider(JsonUtils.getObjectMapper(),
>             JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS));
>     sf.setProvider(new JsonExceptionMapper());
>     sf.setProvider(new WebApplicationExceptionMapper());
>     sf.setProvider(new GenericExceptionMapper());
>     sf.setServiceBeans(Collections.singletonList(this));
>
>     String url = sharedService.getUrlPathPrefix() + resourcePath;
>     LOG.info(String.format("%s at %s", getClass().getName(), url));
>     sf.setAddress(url);
>     server = sf.create();
> }
>
> @Activate
> public void activate(ComponentContext context) {
>     LOG.info("Activating " + getClass().getName());
>     startService(getPath());
> }
>
> @Deactivate
> public void shutdown() {
>     if (server != null) {
>         server.destroy();
>         server = null;
>     }
> }
>

Reply via email to