Hi @all,

Wow! Very active community here in the forum. I appreciate this, thanks.

@jbonofre In a current project at work, we already have rest services
running in karaf by using cxf and blueprint.
I also tried out @cschneider's propositon wiht cxf-dosgi and I got that
running too.

I just wanted to try out publishing rest services via whiteboard, and since
aries jax rs whiteboard is the reference implementation I took that.

About your example. My code looks like this:

/import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants;

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


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

    @Activate
    public void onActivate(){
        System.out.println("ExampleRest activating!");
    }

    @GET
    @Path("/{name}")
    public String sayHello(@PathParam("name") String name) {
        return "Hello " + name;
    }

}/

The generated service.component.xml under OSGI-INF looks like this:

/<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0";
name="de.rest.test.ExampleRest" immediate="true" activate="onActivate">
  <implementation class="de.rest.test.ExampleRest"/>
  <service>
    <provide interface="de.rest.test.ExampleRest"/>
  </service>
  <property name="osgi.jaxrs.application.select" type="String"
value="(osgi.jaxrs.name=.default)"/>
  <property name="osgi.jaxrs.resource" type="String" value="true"/>
</scr:component>/


And the generated Manifest like this:

/Manifest-Version: 1.0
Bnd-LastModified: 1536171585428
Build-Jdk: 1.8.0_171
Built-By: adnan
Bundle-Description: de.rest.test.whiteboard.ds OSGi bundle project.
Bundle-ManifestVersion: 2
Bundle-Name: de.rest.test.whiteboard.ds Bundle
Bundle-SymbolicName: de.rest.test.whiteboard.ds
Bundle-Version: 1.0.0.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Export-Package: de.rest.test;version="1.0.0.SNAPSHOT";uses:="javax.ws.
 rs"
Import-Package: javax.ws.rs;version="[2.1,3)"
Provide-Capability: osgi.service;objectClass:List<String>="de.rest.tes
 t.ExampleRest"
Require-Capability: osgi.extender;filter:="(&(osgi.extender=osgi.compo
 nent)(version>=1.3.0)(!(version>=2.0.0)))",osgi.ee;filter:="(&(osgi.e
 e=JavaSE)(version=1.8))"
Service-Component: OSGI-INF/de.rest.test.ExampleRest.xml
Tool: Bnd-3.5.0.201709291849/

I also already had a look at the osgienroute example @Tim-Ward-2 mentioned.
I created the rest bundle based on the osgi enroute maven archetype. The
code looks very similar (The following is the code generated by the enroute
archetype):

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

import org.osgi.service.component.annotations.Component;
import org.osgi.service.jaxrs.whiteboard.propertytypes.JaxrsResource;

@Component(service=RestComponentImpl.class)
@JaxrsResource
public class RestComponentImpl {
    
    //TODO add an implementation
    
    @Path("rest")
    @GET
    public String toUpper() {
        return "Hello World!";
    }
}
/

I couldnt get a well generetaed manifest by the bnd-tool, so I used the
maven-bundle.-plugin and the generetd service.component.xml and the genrated
Manifest look similar too.


After installing the feature as mentioned in my previous post and deploying
the bundle with you corde examples @jbonofre 
 (bundle symbolic name is de.rest.test.whiteboard.ds Bundle)  and also the
enroute exmaple bunlde (bundly symbolic name is rest-enroute), I have the
following in karaf:

/
karaf@root()> list                                                              
                                                                         
START LEVEL 100 , List Threshold: 50
 ID │ State  │ Lvl │ Version            │ Name
────┼────────┼─────┼────────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
 23 │ Active │  80 │ 4.2.1              │ Apache Karaf :: OSGi Services ::
Event
 45 │ Active │  80 │ 0.0.0              │ aries-jaxrs-whiteboard.xml
 49 │ Active │  80 │ 1.0.0              │ Apache Aries JAX-RS Specification
API
 50 │ Active │  80 │ 1.0.0              │ Apache Aries JAX-RS Whiteboard
 52 │ Active │  80 │ 1.1.2              │ Apache Felix Servlet API
 59 │ Active │  80 │ 1.3.0.1            │ Apache ServiceMix :: Specs ::
Annotation API 1.3
 60 │ Active │  80 │ 4.6.0              │ Apache XBean OSGI Bundle Utilities
 61 │ Active │  80 │ 4.6.0              │ Apache XBean :: Classpath Resource
Finder
 89 │ Active │  80 │ 6.2.0              │ org.objectweb.asm
 90 │ Active │  80 │ 6.2.0              │ org.objectweb.asm.commons
 91 │ Active │  80 │ 6.2.0              │ org.objectweb.asm.tree
 98 │ Active │  80 │ 1.1.0.201802012106 │
org.osgi:org.osgi.service.http.whiteboard
 99 │ Active │  80 │ 1.0.0.201802012106 │ org.osgi:org.osgi.service.jaxrs
100 │ Active │  80 │ 1.1.0.201802012106 │ org.osgi:org.osgi.util.function
101 │ Active │  80 │ 1.1.0.201802012106 │ org.osgi:org.osgi.util.promise
102 │ Active │  80 │ 1.0.0.SNAPSHOT     │ de.rest.test.whiteboard.ds Bundle
103 │ Active │  80 │ 1.0.0.SNAPSHOT     │ rest-enroute
karaf@root()> /


With the command karaf@root()> service:list , I get (excerpt) :

/karaf@root()> service:list                                                     
                                         
[de.rest.test.ExampleRest]
--------------------------
 component.id = 2
 component.name = de.rest.test.ExampleRest
 osgi.jaxrs.application.select = (osgi.jaxrs.name=.default)
 osgi.jaxrs.resource = true
 service.bundleid = 102
 service.id = 123
 service.scope = bundle
Provided by : 
 de.rest.test.whiteboard.ds Bundle (102)

[val.rest.enroute.RestComponentImpl]
------------------------------------
 component.id = 3
 component.name = val.rest.enroute.RestComponentImpl
 service.bundleid = 103
 service.id = 124
 service.scope = bundle
Provided by : 
 rest-enroute (103)/

With the command karaf@root()> http:list , I get :

/karaf@root()> http:list
ID │ Servlet │ Servlet-Name │ State │ Alias │ Url
───┼─────────┼──────────────┼───────┼───────┼────
karaf@root()>  /

Yes, nothing. So no servlet or something in that regard is registered. It
can not work, right? 

When I install the feature cxf-jaxrs I get this:

/karaf@root(feature)> http:list
ID  │ Servlet             │ Servlet-Name               │ State       │ Alias
│ Url
────┼─────────────────────┼────────────────────────────┼─────────────┼───────┼─────────
114 │ CXFNonSpringServlet │ cxf-osgi-transport-servlet │ Deployed    │ /cxf 
│ [/cxf/*]
karaf@root(feature)/


I assume I am missing something obvious and substantial. Can someone point
me to what I am missing?

Thanks in advance!


Greetings,

Adnan






--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html

Reply via email to