0

I'm currently trying to expose restful webservice using OSGI remote services, but it seems that i'm missing something from ECF tutorial. below the details here is the impl class:

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.example.api.HelloWorldService;
import org.osgi.service.component.annotations.Component;

@Path("/helloworld")
@Component(property = { "service.exported.interfaces=HTTP", 
"service.exported.configs=ecf.jaxrs.jersey.server",
    "ecf.jaxrs.jersey.server.alias=/jersey" })
public class HelloWorldResource implements HelloWorldService {
@GET
@Produces("text/plain")
public String getMessage() {
    // Return some textual content
    return "Hello World";
}}

I followed this link to know how things can be together but i wasn't able to get HTTP 200 ok message based on the jax-rs path annotation

https://wiki.eclipse.org/Tutorial:_Using_REST_and_OSGi_Standards_for_Micro_Services

enter image description here

Please note that all bundle are resolved correctly. enter image description here

Yazid
  • 108
  • 3
  • 12

4 Answers4

2

I've created a bndtools4 bndrun for something like your hello jaxrs service. First, you need to create a new workspace using the ECF bndtools.workspace template. Just follow the instructions here:

https://wiki.eclipse.org/Bndtools_Support_for_Remote_Services_Development

for creating a workspace from the ECF bndtools.workspace template. Just today I've added the JaxRS bundles to this workspace template.

Then I created an org.example.api project with this interface

package org.example.api;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("/helloworld")
public interface HelloWorldService {

    @GET
    @Path("/hello")
    @Produces("text/plain")
    String getMessage();
}

Note that it differs slightly from yours because it has a @PATH annotation for the getMessage() method.

Then in another project...named org.example.impl there is this class:

package org.example.impl;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.example.api.HelloWorldService;
import org.osgi.service.component.annotations.Component;

@Path("/helloworld")
@Component(property = { "service.exported.interfaces=*", 
"service.intents=jaxrs" })
public class HelloWorldResource implements HelloWorldService {
    @GET
    @Path("/hello")
    @Produces("text/plain")
public String getMessage() {
    // Return some textual content
    return "Hello World";
}}

The jaxrs annotations are the same as with the interface (as they should be). There are fewer

And here's the bndrun (which I've called jettyserver.bndrun):

-runrequires: \
    bnd.identity;id='org.eclipse.ecf.provider.jersey.server',\
    osgi.identity;filter:='(&(osgi.identity=javax.validation.api)(version>=1.1.0))',\
    osgi.identity;filter:='(&(osgi.identity=org.apache.felix.gogo.command)(version>=1.0.2))',\
    osgi.identity;filter:='(&(osgi.identity=org.apache.felix.gogo.runtime)(version>=1.0.10))',\
    osgi.identity;filter:='(&(osgi.identity=org.slf4j.api)(version>=1.7.2))',\
    bnd.identity;version='latest';id='org.example.impl',\
    bnd.identity;id='org.apache.felix.gogo.command',\
    bnd.identity;id='org.apache.felix.gogo.runtime',\
    bnd.identity;id='org.apache.felix.gogo.shell',\
    bnd.identity;id='org.eclipse.ecf.osgi.services.remoteserviceadmin.console',\
    bnd.identity;id='org.apache.felix.scr',\
    bnd.identity;id='org.eclipse.ecf.osgi.services.distribution',\
    bnd.identity;id='org.eclipse.ecf.provider.jersey.client'
-runfw: org.apache.felix.framework;version='[5.6.10,5.6.10]'
-runee: JavaSE-1.8
-runbundles: \
    com.fasterxml.jackson.core.jackson-annotations;version='[2.9.2,2.9.3)',\
    com.fasterxml.jackson.core.jackson-core;version='[2.9.2,2.9.3)',\
    com.fasterxml.jackson.core.jackson-databind;version='[2.9.2,2.9.3)',\
    com.fasterxml.jackson.jaxrs.jackson-jaxrs-base;version='[2.9.2,2.9.3)',\
    com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider;version='[2.9.2,2.9.3)',\
    javax.annotation;version='[1.2.0,1.2.1)',\
    javax.inject;version='[1.0.0,1.0.1)',\
    javax.persistence;version='[2.2.0,2.2.1)',\
    javax.validation.api;version='[1.1.0,1.1.1)',\
    javax.ws.rs;version='[2.0.1,2.0.2)',\
    org.aopalliance;version='[1.0.0,1.0.1)',\
    org.apache.felix.configadmin;version='[1.8.16,1.8.17)',\
    org.apache.felix.eventadmin;version='[1.4.10,1.4.11)',\
    org.apache.felix.gogo.command;version='[1.0.2,1.0.3)',\
    org.apache.felix.gogo.runtime;version='[1.0.10,1.0.11)',\
    org.apache.felix.http.jetty;version='[3.4.8,3.4.9)',\
    org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
    org.apache.felix.scr;version='[2.0.14,2.0.15)',\
    org.eclipse.core.jobs;version='[3.9.3,3.9.4)',\
    org.eclipse.ecf;version='[3.9.0,3.9.1)',\
    org.eclipse.ecf.discovery;version='[5.0.300,5.0.301)',\
    org.eclipse.ecf.identity;version='[3.9.0,3.9.1)',\
    org.eclipse.ecf.osgi.services.remoteserviceadmin;version='[4.6.800,4.6.801)',\
    org.eclipse.ecf.osgi.services.remoteserviceadmin.proxy;version='[1.0.100,1.0.101)',\
    org.eclipse.ecf.provider.jaxrs;version='[1.3.0,1.3.1)',\
    org.eclipse.ecf.provider.jaxrs.server;version='[1.4.0,1.4.1)',\
    org.eclipse.ecf.provider.jersey.server;version='[1.3.0,1.3.1)',\
    org.eclipse.ecf.remoteservice;version='[8.13.0,8.13.1)',\
    org.eclipse.ecf.remoteservice.asyncproxy;version='[2.1.0,2.1.1)',\
    org.eclipse.equinox.common;version='[3.9.0,3.9.1)',\
    org.eclipse.equinox.concurrent;version='[1.1.0,1.1.1)',\
    org.eclipse.equinox.supplement;version='[1.7.0,1.7.1)',\
    org.eclipse.osgi.services.remoteserviceadmin;version='[1.6.200,1.6.201)',\
    org.glassfish.hk2.api;version='[2.5.0,2.5.1)',\
    org.glassfish.hk2.osgi-resource-locator;version='[2.5.0,2.5.1)',\
    org.glassfish.hk2.utils;version='[2.5.0,2.5.1)',\
    org.glassfish.jersey.bundles.repackaged.jersey-guava;version='[2.22.1,2.22.2)',\
    org.glassfish.jersey.containers.servlet.core;version='[2.22.1,2.22.2)',\
    org.glassfish.jersey.core.jersey-common;version='[2.22.1,2.22.2)',\
    org.glassfish.jersey.core.jersey-server;version='[2.22.1,2.22.2)',\
    org.glassfish.jersey.ext.entityfiltering;version='[2.22.1,2.22.2)',\
    org.glassfish.jersey.media.jersey-media-json-jackson;version='[2.22.1,2.22.2)',\
    org.slf4j.api;version='[1.7.2,1.7.3)',\
    org.example.api;version=snapshot,\
    org.example.impl;version=snapshot,\
    org.apache.felix.gogo.shell;version='[1.0.0,1.0.1)',\
    org.eclipse.ecf.console;version='[1.1.0,1.1.1)',\
    org.eclipse.ecf.osgi.services.remoteserviceadmin.console;version='[1.0.0,1.0.1)',\
    org.eclipse.ecf.osgi.services.distribution;version='[2.1.200,2.1.201)',\
    javassist;version='[3.13.0,3.13.1)',\
    org.eclipse.ecf.provider.jaxrs.client;version='[1.3.0,1.3.1)',\
    org.eclipse.ecf.provider.jersey.client;version='[1.3.0,1.3.1)',\
    org.glassfish.hk2.locator;version='[2.5.0,2.5.1)',\
    org.glassfish.jersey.core.jersey-client;version='[2.22.1,2.22.2)'

With your permission, I would like to add bndtools project templates for both jaxrs hello api and impl projects to the ECF bndtools.workspace repo, along with a jersey and cxf bndrun server and client templates (once I complete them). I'll create the bndruns and test over the next few days.

  • Thank you so much for all the details that you've shared, it works now correctly using http://localhost:8080/1/helloworld/hello, many thanks again – Yazid Jul 12 '18 at 09:51
1

The exported interfaces property should not be "HTTP". Instead it must be an interface fqname or Star. So try this:

"service.exported.interfaces=*"
Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
1

If you are not using already, please update to ECF 3.14.0. Further, after 3.14.0/Photon (last few weeks) there have been significant changes to the JaxRS providers to support OSGi R7 Async Remote Services so please make sure you have the latest from JaxRSProviders as well. The required remote service properties have changed based upon the R7 changes. Please see the service properties of the hello examples and this short tutorial for running the hello example on Karaf:

https://wiki.eclipse.org/Tutorial:_JaxRS_Remote_Services_on_Karaf

In short, it's no longer necessary to specify ecf.jaxrs.jersey.server.alias but there are other (newly standardize) properties to set.

I would like to create a bndtools4 JaxRS run descriptor template, and I think this would make it significantly easier for you. I suspect your problem might be that do not have all necessary jersey bundles, as jersey has quite a number of dependencies...all of which have to be present to successfully export a remote service. For ref, here's the setup info for using the project and bndrun templates that are currently there:

https://wiki.eclipse.org/Bndtools_Support_for_Remote_Services_Development

I will create a bndtools4 bndrun template for the CXF and Jersey distribution providers, but have not had enough time since the JaxRSProvider changes. If you would like to express your desire for bndrun template and/or help with contributions, please open an issue at https://github.com/ECF/JaxRSProviders/issues and that will help track.

In the mean time, the examples list of bundles is in the product files here:

https://github.com/ECF/JaxRSProviders/tree/master/examples/com.mycorp.examples.student.remoteservice.host/launch

  • Also...there is a list of JaxRS example bundles in the karaf-features: – Scott Lewis Jul 11 '18 at 19:18
  • located here http://download.eclipse.org/rt/ecf/RELEASE/site.p2/karaf-features.xml – Scott Lewis Jul 11 '18 at 19:19
  • Thank you so much for taking the time to answer to my question, I will raise an issue in GitHub to get this functionality. – Yazid Jul 11 '18 at 23:53
  • About dependencies i think bndtools resolve dependencies by looking at the linked bundles in the configured repositories. About properties can you please tell me what would be the default URL that i need to use when nothing is set. – Yazid Jul 12 '18 at 00:05
0

For info:

I've added project templates for JaxRS API, Impl, Consumer projects (based upon the HelloWorldService) and I've added bndrun templates for Jersey server and client, as well as CXF server and client.

See https://github.com/ECF/JaxRSProviders/issues/6