REST - Declarative Services

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

REST - Declarative Services

Guenther Schmidt
Hello All,

I’ve been developing services using Declarative Services for dependency injection and it was a breeze so far. Now I want to expose some of the functionality via a REST API and I’m stuck. So far I’ve deployed my bundles through bundle:install -s man: …. all very easy. But what should be simple, exposing this through REST is becoming difficult. There are tips out there suggesting to use Blueprint, which I don’t want, others seem to suggest that I need to create a “feature” package.

Then there’s also the requirements to “feature” install cxf. That’s OK btw, I only have to do that once. But is there really no simple way to create a simple REST service using merely DS?

Guenther


Reply | Threaded
Open this post in threaded view
|

Re: REST - Declarative Services

jbonofre
Hi Guenther,

You can use CXF registering the CXF JAXRS server using DS.

Another option could be to use Aries JAXRS with the whiteboard pattern.

We are preparing samples about that:

https://github.com/jbonofre/karaf/tree/DEV_GUIDE/examples/karaf-rest-example

I will add an example with Aries JAXRS and DS.

With Aries JAXRS, you can simply do:

@Component(
    property = {
        JaxrsWhiteboardConstants.JAX_RS_APPLICATION_SELECT +
"=(osgi.jaxrs.name=.default)",
        JaxrsWhiteboardConstants.JAX_RS_RESOURCE + "=true"
    },
    service = ExampleRest.class
)
public class ExampleRest {

    @GET
    @Path("/{name}")
    public String sayHello(@PathParam("name") String name) {
        if (_log.isDebugEnabled()) {
            _log.debug("URI: " + _uriInfo.getAbsolutePath());
        }

        return "Hello " + name;
    }

    @Context
    UriInfo _uriInfo;

    private static final Logger _log = LoggerFactory.getLogger(
        ExampleAddon.class);

}

Regards
JB

On 28/05/2018 19:40, Guenther Schmidt wrote:
> Hello All,
>
> I’ve been developing services using Declarative Services for dependency injection and it was a breeze so far. Now I want to expose some of the functionality via a REST API and I’m stuck. So far I’ve deployed my bundles through bundle:install -s man: …. all very easy. But what should be simple, exposing this through REST is becoming difficult. There are tips out there suggesting to use Blueprint, which I don’t want, others seem to suggest that I need to create a “feature” package.
>
> Then there’s also the requirements to “feature” install cxf. That’s OK btw, I only have to do that once. But is there really no simple way to create a simple REST service using merely DS?
>
> Guenther
>
>

--
--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|

Re: REST - Declarative Services

cschneider
In reply to this post by Guenther Schmidt
Aries JAX-RS should work. It is not yet released though. So currently there is only a snapshot. A release should follow soon.

Another option is to use CXF-DOSGi. You can find an example below. It is similar to Aries JAX-RS so a later switch should be easy.


Christian

2018-05-28 19:40 GMT+02:00 Guenther Schmidt <[hidden email]>:
Hello All,

I’ve been developing services using Declarative Services for dependency injection and it was a breeze so far. Now I want to expose some of the functionality via a REST API and I’m stuck. So far I’ve deployed my bundles through bundle:install -s man: …. all very easy. But what should be simple, exposing this through REST is becoming difficult. There are tips out there suggesting to use Blueprint, which I don’t want, others seem to suggest that I need to create a “feature” package.

Then there’s also the requirements to “feature” install cxf. That’s OK btw, I only have to do that once. But is there really no simple way to create a simple REST service using merely DS?

Guenther





--
--
Christian Schneider

http://www.liquid-reality.de

Computer Scientist

Reply | Threaded
Open this post in threaded view
|

Re: REST - Declarative Services

Alex Weirig

I'm using the approach Christian is referring to and I can confirm that it's really easy and convenient.

I'm creating DS services to expose selected backend services with a REST API

@Component(
        immediate = true
        , property = {
                "service.exported.interfaces=*",
                "service.exported.configs=org.apache.cxf.rs",
                "org.apache.cxf.rs.address=/room-service"
        }
        , service = GestionInfrastructuresREST.class               
)
public class GestionInfrastructuresRESTImpl implements GestionInfrastructuresREST {

    @Reference private LogService logger;
    @Reference private GestionInfrastructuresService service;        // my backend service
   
    ...

  
    @Override
    public Response getAllRooms() {
        List<GestionInfrastructuresRoomModel> allRooms = service.getAllRooms();    // call to the backend service

        ... // process the result from the backend service

       return Response.ok(json, MediaType.APPLICATION_JSON).build();    // if result is OK

        ...  // do some error processing and return some error .... e.g.      
        return Response.serverError().build();
    }

}


Mat frëndleche Gréiss,
Mit freundlichen Grüßen,
Meilleures salutations,
Kind regards,

Alex Weirig
Responsable Technique
Ville de Luxembourg
Service Enseignement
Centre Technolink

Tel <a href="tel:+35247966127">+352 4796 - 6127
Fax +352 42 88 81
Email [hidden email]
www.vdl.lu // www.technolink.lu

Centre Technolink
2, rue Charles de Tornaco 
L-2623 LUXEMBOURG

On 28/05/2018 23:01, Christian Schneider wrote:
Aries JAX-RS should work. It is not yet released though. So currently there is only a snapshot. A release should follow soon.

Another option is to use CXF-DOSGi. You can find an example below. It is similar to Aries JAX-RS so a later switch should be easy.


Christian

2018-05-28 19:40 GMT+02:00 Guenther Schmidt <[hidden email]>:
Hello All,

I’ve been developing services using Declarative Services for dependency injection and it was a breeze so far. Now I want to expose some of the functionality via a REST API and I’m stuck. So far I’ve deployed my bundles through bundle:install -s man: …. all very easy. But what should be simple, exposing this through REST is becoming difficult. There are tips out there suggesting to use Blueprint, which I don’t want, others seem to suggest that I need to create a “feature” package.

Then there’s also the requirements to “feature” install cxf. That’s OK btw, I only have to do that once. But is there really no simple way to create a simple REST service using merely DS?

Guenther





--
--
Christian Schneider

http://www.liquid-reality.de

Computer Scientist

-- 
This email was Anti Virus checked by SOPHOS UTM


alex_weirig.vcf (348 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: REST - Declarative Services

Alex Weirig

BTW: these should be the features I installed in karaf ...

feature:repo-add cxf-dosgi
feature:install cxf-dosgi-provider-rs


Mat frëndleche Gréiss,
Mit freundlichen Grüßen,
Meilleures salutations,
Kind regards,

Alex Weirig
Responsable Technique
Ville de Luxembourg
Service Enseignement
Centre Technolink

Tel <a href="tel:+35247966127">+352 4796 - 6127
Fax +352 42 88 81
Email [hidden email]
www.vdl.lu // www.technolink.lu

Centre Technolink
2, rue Charles de Tornaco 
L-2623 LUXEMBOURG

On 29/05/2018 08:36, Alex Weirig wrote:

I'm using the approach Christian is referring to and I can confirm that it's really easy and convenient.

I'm creating DS services to expose selected backend services with a REST API

@Component(
        immediate = true
        , property = {
                "service.exported.interfaces=*",
                "service.exported.configs=org.apache.cxf.rs",
                "org.apache.cxf.rs.address=/room-service"
        }
        , service = GestionInfrastructuresREST.class               
)
public class GestionInfrastructuresRESTImpl implements GestionInfrastructuresREST {

    @Reference private LogService logger;
    @Reference private GestionInfrastructuresService service;        // my backend service
   
    ...

  
    @Override
    public Response getAllRooms() {
        List<GestionInfrastructuresRoomModel> allRooms = service.getAllRooms();    // call to the backend service

        ... // process the result from the backend service

       return Response.ok(json, MediaType.APPLICATION_JSON).build();    // if result is OK

        ...  // do some error processing and return some error .... e.g.      
        return Response.serverError().build();
    }

}


Mat frëndleche Gréiss,
Mit freundlichen Grüßen,
Meilleures salutations,
Kind regards,

Alex Weirig
Responsable Technique
Ville de Luxembourg
Service Enseignement
Centre Technolink

Tel <a href="tel:+35247966127" moz-do-not-send="true">+352 4796 - 6127
Fax +352 42 88 81
Email [hidden email]
www.vdl.lu // www.technolink.lu

Centre Technolink
2, rue Charles de Tornaco 
L-2623 LUXEMBOURG

On 28/05/2018 23:01, Christian Schneider wrote:
Aries JAX-RS should work. It is not yet released though. So currently there is only a snapshot. A release should follow soon.

Another option is to use CXF-DOSGi. You can find an example below. It is similar to Aries JAX-RS so a later switch should be easy.


Christian

2018-05-28 19:40 GMT+02:00 Guenther Schmidt <[hidden email]>:
Hello All,

I’ve been developing services using Declarative Services for dependency injection and it was a breeze so far. Now I want to expose some of the functionality via a REST API and I’m stuck. So far I’ve deployed my bundles through bundle:install -s man: …. all very easy. But what should be simple, exposing this through REST is becoming difficult. There are tips out there suggesting to use Blueprint, which I don’t want, others seem to suggest that I need to create a “feature” package.

Then there’s also the requirements to “feature” install cxf. That’s OK btw, I only have to do that once. But is there really no simple way to create a simple REST service using merely DS?

Guenther





--
--
Christian Schneider

http://www.liquid-reality.de

Computer Scientist

-- 
This email was Anti Virus checked by SOPHOS UTM



alex_weirig.vcf (348 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: REST - Declarative Services

Steinar Bang
In reply to this post by Guenther Schmidt
>>>>> Guenther Schmidt <[hidden email]>:

> Then there’s also the requirements to “feature” install cxf. That’s OK
> btw, I only have to do that once. But is there really no simple way to
> create a simple REST service using merely DS?

Take a look at these two:

 https://github.com/steinarb/post-body-capture
   A super-simple REST service/debug tool that just writes the POSTed
   body to a file, and the file name to the injected OSGi log service (I
   used it to see what sonarcloud was sending to its webhooks)

 https://github.com/steinarb/sonar-collector
  A REST service intended to be used as a postbuild SonarCloud/SonarQube
  webhook.  The service will store key numbers from the build in a
  PostgreSQL database.
  Nifty things here are using liquibase to initialize the PostgreSQL
  database and injecting config in the @Activate method, allowing the
  JDBC connection info to be configured from the karaf console.

Build and install information can be found in the README files.

Reply | Threaded
Open this post in threaded view
|

Re: REST - Declarative Services

Scott Lewis
In reply to this post by Guenther Schmidt
On 5/28/2018 10:40 AM, Guenther Schmidt wrote:
> Hello All,
>
> I’ve been developing services using Declarative Services for dependency injection and it was a breeze so far. Now I want to expose some of the functionality via a REST API and I’m stuck. So far I’ve deployed my bundles through bundle:install -s man: …. all very easy. But what should be simple, exposing this through REST is becoming difficult. There are tips out there suggesting to use Blueprint, which I don’t want, others seem to suggest that I need to create a “feature” package.
>
> Then there’s also the requirements to “feature” install cxf. That’s OK btw, I only have to do that once. But is there really no simple way to create a simple REST service using merely DS?
>
> Guenther
>
>
Hi Guenther,

Another option would be ECF Remote Services [1].   It's a full
implementation of the OSGi Remote Services and Remote Service Admin
(R7/latest) specifications [2].   These specifications standardize the
remoting of OSGi services (meta-data and dynamics), so it works
seemlessly with DS and other frameworks that use the OSGi service registry.

ECF has a provider architecture so allows the use of a variety of
distribution providers [3], including CXF [4].

We have features defined for Karaf [5] and we also now have support for
bndtools-based development [6] (workspace and project templates).

Caveat:   ECF is in the middle of 'release season' for the Eclipse
simultaneous release (late June), so the transition to ECF 3.14.0 is not
yet complete.  For example, the Karaf features don't yet point to 3.14.0
at maven central only because we have to wait for the SR  process before
deployment of the release to maven central.   However, I'm happy to
provide needed support via [7].

Scott

[1] https://wiki.eclipse.org/Eclipse_Communication_Framework_Project

[2]
https://osgi.org/specification/osgi.cmpn/7.0.0/service.remoteserviceadmin.html

[3] https://wiki.eclipse.org/Distribution_Providers

[4] https://github.com/ECF/JaxRSProviders

[5] https://wiki.eclipse.org/EIG:Install_into_Apache_Karaf

[6]
https://wiki.eclipse.org/Bndtools_Support_for_Remote_Services_Development

[7] https://accounts.eclipse.org/mailing-list/ecf-dev

[8] http://eclipseecf.blogspot.com/

Reply | Threaded
Open this post in threaded view
|

Re: REST - Declarative Services

Tim Ward-2
Almost certainly the simplest option has already been suggested. The OSGi JAX-RS whiteboard provides a simple, standard mechanism for registering JAX-RS applications, resources, and extensions using the OSGi service registry. The Aries JAX-RS whiteboard is the Reference Implementation of this spec, and is in the process of being released (it should be available within the next three weeks). Using the JAX-RS whiteboard gives you more control over your resources, gives you access to more of the JAX-RS specification, and is more portable than using RSA.

There’s a simple set of tutorials using the R7 specifications provided by OSGi enRoute:


The quickstart application should provide you with everything you need.

Best Regards,

Tim

On 29 May 2018, at 17:03, Scott Lewis <[hidden email]> wrote:

On 5/28/2018 10:40 AM, Guenther Schmidt wrote:
Hello All,

I’ve been developing services using Declarative Services for dependency injection and it was a breeze so far. Now I want to expose some of the functionality via a REST API and I’m stuck. So far I’ve deployed my bundles through bundle:install -s man: …. all very easy. But what should be simple, exposing this through REST is becoming difficult. There are tips out there suggesting to use Blueprint, which I don’t want, others seem to suggest that I need to create a “feature” package.

Then there’s also the requirements to “feature” install cxf. That’s OK btw, I only have to do that once. But is there really no simple way to create a simple REST service using merely DS?

Guenther


Hi Guenther,

Another option would be ECF Remote Services [1].   It's a full implementation of the OSGi Remote Services and Remote Service Admin (R7/latest) specifications [2].   These specifications standardize the remoting of OSGi services (meta-data and dynamics), so it works seemlessly with DS and other frameworks that use the OSGi service registry.

ECF has a provider architecture so allows the use of a variety of distribution providers [3], including CXF [4].

We have features defined for Karaf [5] and we also now have support for bndtools-based development [6] (workspace and project templates).

Caveat:   ECF is in the middle of 'release season' for the Eclipse simultaneous release (late June), so the transition to ECF 3.14.0 is not yet complete.  For example, the Karaf features don't yet point to 3.14.0 at maven central only because we have to wait for the SR  process before deployment of the release to maven central.   However, I'm happy to provide needed support via [7].

Scott

[1] https://wiki.eclipse.org/Eclipse_Communication_Framework_Project

[2] https://osgi.org/specification/osgi.cmpn/7.0.0/service.remoteserviceadmin.html

[3] https://wiki.eclipse.org/Distribution_Providers

[4] https://github.com/ECF/JaxRSProviders

[5] https://wiki.eclipse.org/EIG:Install_into_Apache_Karaf

[6] https://wiki.eclipse.org/Bndtools_Support_for_Remote_Services_Development

[7] https://accounts.eclipse.org/mailing-list/ecf-dev

[8] http://eclipseecf.blogspot.com/


Reply | Threaded
Open this post in threaded view
|

Re: REST - Declarative Services

Scott Lewis
On 5/30/2018 2:17 AM, Tim Ward wrote:
Almost certainly the simplest option has already been suggested. The OSGi JAX-RS whiteboard provides a simple, standard mechanism for registering JAX-RS applications, resources, and extensions using the OSGi service registry. The Aries JAX-RS whiteboard is the Reference Implementation of this spec, and is in the process of being released (it should be available within the next three weeks). Using the JAX-RS whiteboard gives you more control over your resources, gives you access to more of the JAX-RS specification, and is more portable than using RSA.

It's debatable to say that the JAX-RS whiteboard spec is more portable than using RSA.   Portability can mean multiple things...e.g. across impls (e.g. CXF or Jersey), or service contracts across transports (http vs. mqtt).   Further, RSA does have things that JAXRS currently lacks...e.g. proxys, mgmt agent, topology mgr, discovery/edef. 

But I don't wish to debate.   I'll just point to an example running on Karaf that uses Jersey, CXF, JAX-RS, OSGi R7 RSA:  https://wiki.eclipse.org/Tutorial:_JaxRS_Remote_Services_on_Karaf

Scott


There’s a simple set of tutorials using the R7 specifications provided by OSGi enRoute:


The quickstart application should provide you with everything you need.

Best Regards,

Tim

On 29 May 2018, at 17:03, Scott Lewis <[hidden email]> wrote:

On 5/28/2018 10:40 AM, Guenther Schmidt wrote:
Hello All,

I’ve been developing services using Declarative Services for dependency injection and it was a breeze so far. Now I want to expose some of the functionality via a REST API and I’m stuck. So far I’ve deployed my bundles through bundle:install -s man: …. all very easy. But what should be simple, exposing this through REST is becoming difficult. There are tips out there suggesting to use Blueprint, which I don’t want, others seem to suggest that I need to create a “feature” package.

Then there’s also the requirements to “feature” install cxf. That’s OK btw, I only have to do that once. But is there really no simple way to create a simple REST service using merely DS?

Guenther


Hi Guenther,

Another option would be ECF Remote Services [1].   It's a full implementation of the OSGi Remote Services and Remote Service Admin (R7/latest) specifications [2].   These specifications standardize the remoting of OSGi services (meta-data and dynamics), so it works seemlessly with DS and other frameworks that use the OSGi service registry.

ECF has a provider architecture so allows the use of a variety of distribution providers [3], including CXF [4].

We have features defined for Karaf [5] and we also now have support for bndtools-based development [6] (workspace and project templates).

Caveat:   ECF is in the middle of 'release season' for the Eclipse simultaneous release (late June), so the transition to ECF 3.14.0 is not yet complete.  For example, the Karaf features don't yet point to 3.14.0 at maven central only because we have to wait for the SR  process before deployment of the release to maven central.   However, I'm happy to provide needed support via [7].

Scott

[1] https://wiki.eclipse.org/Eclipse_Communication_Framework_Project

[2] https://osgi.org/specification/osgi.cmpn/7.0.0/service.remoteserviceadmin.html

[3] https://wiki.eclipse.org/Distribution_Providers

[4] https://github.com/ECF/JaxRSProviders

[5] https://wiki.eclipse.org/EIG:Install_into_Apache_Karaf

[6] https://wiki.eclipse.org/Bndtools_Support_for_Remote_Services_Development

[7] https://accounts.eclipse.org/mailing-list/ecf-dev

[8] http://eclipseecf.blogspot.com/