Using with OSGi
A Juneau REST servlet is an ordinary HttpServlet, so in OSGi you publish it as a servlet service and let the HTTP whiteboard mount it.
When to use it
Use this when you deploy your REST resources as a bundle in an OSGi container.
Juneau servlets extend the jakarta.servlet API, so the container needs a Jakarta Servlet whiteboard implementation (OSGi R8 or later).
Example
The following activator registers a REST servlet as a service with the whiteboard path pattern /sample.
import java.util.*;
import org.apache.juneau.rest.server.*;
import org.apache.juneau.rest.server.servlet.*;
import org.osgi.framework.*;
import jakarta.servlet.Servlet;
@Rest
class MyRestServlet extends BasicRestServlet {}
public class Activator implements BundleActivator {
private ServiceRegistration<Servlet> registration;
@Override /* BundleActivator */
public void start(BundleContext context) throws Exception {
var props = new Hashtable<String,Object>();
props.put("osgi.http.whiteboard.servlet.pattern", "/sample");
registration = context.registerService(Servlet.class, new MyRestServlet(), props);
}
@Override /* BundleActivator */
public void stop(BundleContext context) throws Exception {
registration.unregister();
}
}