I was unable to find any documentation on how to use Jetty as an OSGi HTTP service. We needed it as a part of our WRT tools effort to host a code that would serve as a runtime environment (sort of “emulator”) for the user code. I guess there are many other scenarios that could make use of the embedded server.
Basically, everything you need to know can be found in org.eclipse.wst.ws.internal.explorer.WebappManager class that is part of the WebTools project. The code is very simple:
Dictionary d = new Hashtable();
d.put("http.port", new Integer(getPortParameter())); //$NON-NLS-1$
// set the base URL
d.put("context.path", "/wse"); //$NON-NLS-1$ //$NON-NLS-2$
d.put("other.info", "org.eclipse.wst.ws.explorer"); //$NON-NLS-1$ //$NON-NLS-2$
// suppress Jetty INFO/DEBUG messages to stderr
In our code we do not specify the context path (so we have root as a context path) and specify a different ID so both our code and Web Services tools could coexist.
There are two ways to register servlets:
- Programmatic (using OSGi APIs)
- Declarative (using org.eclipse.equinox.http.registry.servlets extension point)
In our application we use programmatic way so we don’t have to rely on singletons to integrate them with our IDE.