The preferred model for OSGi is to just register a Servlet service in the service registry. This servlet should be picked up by the Http server installed on that framework. This model will be the standard model in the near future but is already supported by Apache Felix. This is how you would make this in bnd(tools):
bnd.bnd
-runfw: org.apache.felix.framework;version='[4,5)'
-runbundles: \
org.apache.felix.configadmin; version=1.6.0, \
org.apache.felix.log; version=1.0.1, \
org.apache.felix.scr; version=1.6.0, \
org.apache.felix.http.jetty; version=2.2.0, \
org.apache.felix.http.whiteboard; version=2.2.0
If this is running you could write a servlet using Declarative Services like this:
@Component(provide=Servlet.class,properties="alias=/hello") // makes it available on /hello
public class MyAndroidServer extends HttpServlet {
public void doGet(HttpServletRequest rq, HttpSerletResponse rsp) throws IOException {
rsp.getWriter().println("Hello World");
}
}
If you start with bndtools it should be quite easy to get this to work. As far as I know this is the most simple way to use servlets on an OSGi environment.