javaeclipserestosgi-bundleamdatu

OSGi REST service is not working (bnd tool)


I am writing a REST service its according to the Amdatu guide its quite simple but It is throwing me an error I have added all the dependencies but still getting missing requirement error

Here is an error Message

! could not resolve the bundles
! Failed to start bundle org.apache.felix.http.whiteboard-2.3.0, exception Unresolved constraint in bundle org.apache.felix.http.whiteboard [13]: Unable to resolve 13.0: missing requirement [13.0] osgi.wiring.package; (&(osgi.wiring.package=javax.servlet)(version>=3.0.0)(!(version>=4.0.0)))
! Failed to start bundle org.amdatu.web.rest.wink-1.0.8, exception Unresolved constraint in bundle org.amdatu.web.rest.wink [14]: Unable to resolve 14.0: missing requirement [14.0] osgi.wiring.package; (&(osgi.wiring.package=org.codehaus.jackson.jaxrs)(version>=1.9.0)(!(version>=2.0.0)))
! Failed to start bundle org.apache.felix.http.jetty-2.3.0, exception Unresolved constraint in bundle org.apache.felix.http.jetty [15]: Unable to resolve 15.0: missing requirement [15.0] osgi.wiring.package; (&(osgi.wiring.package=javax.servlet)(version>=3.0.0)(!(version>=4.0.0)))
____________________________
Welcome to Apache Felix Gogo

g! 

Here is implementation

package web.rest;

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

@Path("hellorest")
public class HelloWorldResource {
    @GET
    @Produces(MediaType.TEXT_HTML)
    public String say_hello() {
        return "hello";
    }

}

Here is an Activator class

package web.rest;

import org.apache.felix.dm.DependencyActivatorBase;
import org.apache.felix.dm.DependencyManager;
import org.osgi.framework.BundleContext;

public class Activator extends DependencyActivatorBase{

    @Override
    public void destroy(BundleContext arg0, DependencyManager arg1)
            throws Exception {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void init(BundleContext arg0, DependencyManager manager)
            throws Exception {
        manager.add(createComponent()
                .setInterface(Object.class.getName(),null)
                .setImplementation(HelloWorldResource.class));
    }

}

I have added these to build dependencies enter image description here

These are Run dependencies enter image description here

If you ask me to change the Servlet package to 3.0 I will answer some other service require Servlet version must be less than 3.0 now I can't fulfill them at the same time.


Solution

  • The problem is in your 'run bundles' configuration:

    1. replace the javax.servlet bundle with org.apache.felix.http.servlet-api. It contains the javax.servlet package in the appropriate versions.
    2. Add the jackson-jaxrs bundle as well

    Both bundles are also available in the 'Amdatu Dependencies' repository.