Jeongpil An,
For what it is worth, below is a simplified and sanitized version of my REST 
environment under Karaf 4.4.3. Note the REST endpoint and the API 
implementation are in different bundles, as I used the same REST application 
for many bundles.

Although thus is not a Jararta implementation, I hope it helps.

***
* REST Application
***
package com.foo.restapp;

import javax.ws.rs.core.Application;

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

@Component(service=Application.class)
@JaxrsName("fooApi")
@JaxrsApplicationBase("/foo/api")
public class RestApplication extends Application{

}

***
* Example REST API
***
package com.foo.messenger.rest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;

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


@Path("/archiveMessage")
@Component(service = ArchiveMessage.class)
@JaxrsResource
@JaxrsApplicationSelect("(osgi.jaxrs.name=fooApi)")
public class ArchiveMessage {
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    @Path("/{messageId}")
    public Response archiveMessage(@PathParam("messageId") final Integer 
messageId,
            @QueryParam("account") ) {
...
        ResponseBuilder builder;
...
        if (success) {
           builder = Response.ok(String.format("Success - Archiving Message 
ID:%d", messageId));
        } else {
            builder = Response.noContent();
        }
        return builder.build();
    }

}


***
* Feature
***
   <feature name="foo-restapp"
        description="Foo REST Whiteboard" version="${project.version}">
        <feature>cxf-jaxrs</feature>
        <feature>jackson-jaxrs</feature>
        <feature>pax-web-http-whiteboard</feature>
        <feature>pax-web-karaf</feature>
        <feature>aries-jax-rs-whiteboard</feature>
        <feature>aries-jax-rs-whiteboard-jackson</feature>
        <bundle start="true">mvn:com.foo.rest/foo-restapp/${restapp.version}
        </bundle>
    </feature>
    <feature name="foo-msg-rest"
        description="Foo Messenger REST endpoint" version="${project.version}">
        <feature prerequisite="true">foo-restapp</feature>
        <bundle start="true" 
start-level="90">mvn:com.foo.rest/foo-msg-rest/${bugdata.msg.rest.version}
        </bundle>
    </feature>


Paul Spencer



> On Apr 12, 2023, at 2:58 AM, 안정필 <jeongpil...@gmail.com> wrote:
> 
> Thanks for your good comments, Grzegorz Grzybek.
> 
> Using your comments, I'll try again and post the result.
> 
> Regards
> Jeongpil An (call ajp)
> 
> 2023년 4월 12일 (수) 오후 3:01, Grzegorz Grzybek <gr.grzy...@gmail.com>님이 작성:
> Hello
> 
> Karaf 4.4.3 uses Pax Web 8 and Pax Web, while not containing any Karaf 
> features related to JaxRS, provides integration tests using aries-jaxrs (OSGi 
> CMPN specification implementation).
> 
> The Jetty-based test: 
> https://github.com/ops4j/org.ops4j.pax.web/blob/web-8.0.19/pax-web-itest/pax-web-itest-container/pax-web-itest-jetty/src/test/java/org/ops4j/pax/web/itest/jetty/whiteboard/WhiteboardR7JaxRsIntegrationTest.java
> 
> Abstract definition of the test: 
> https://github.com/ops4j/org.ops4j.pax.web/blob/web-8.0.19/pax-web-itest/pax-web-itest-container/pax-web-itest-container-common/src/main/java/org/ops4j/pax/web/itest/container/whiteboard/AbstractWhiteboardR7JaxRsIntegrationTest.java
> 
> And what's most important - the list of bundles you need (so you can create 
> your own feature): 
> https://github.com/ops4j/org.ops4j.pax.web/blob/web-8.0.19/pax-web-itest/pax-web-itest-common/src/main/java/org/ops4j/pax/web/itest/AbstractControlledTestBase.java#L667-L725
> 
> I know this is rtfs approach to answer your question, but that's how it is ;)
> 
> kind regards
> Grzegorz Grzybek
> 
> śr., 12 kwi 2023 o 07:46 안정필 <jeongpil...@gmail.com> napisał(a):
> Hi, Karaf Users and Developers.
> I'm a user who likes karaf and osgi.
> 
> Can I use Jakarta Restful WebService(OSGi 8.1) on Karaf ?
> I'm using Karaf 4.4.3.
> 
> It seems like that karaf default cxf-jaxrs feature 3.5.5 supports 
> javax.ws.rs, not jakarta.ws.rs.
> cxf 4.0 changed to jakarta but  temporarily removed osgi module 
> till osgi supports jakarta, as they say.
> I tried several things but the result was not good. (eclipse Jersey 3.1, 
> resteasy 6.2.3.Final, etc.)
> 
> Any Idea?
> 
> Thanks in advance for any comments.
> 
> Regards
> Jeongpil An (call, ajp)

Reply via email to