SIDEBAR
»
S
I
D
E
B
A
R
«
Using Jetty as an OSGi HTTP Service
May 19th, 2010 by Eugene Ostroukhov

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$</p>

<p>// suppress Jetty INFO/DEBUG messages to stderr
Logger.getLogger("org.mortbay").setLevel(Level.WARNING); //$NON-NLS-1$</p>

<p>JettyConfigurator.startServer(webappName, d);
checkBundle();

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.

What is really important is that the server will run in Eclipse process and deployed servlets can have access to Eclipse APIs so you can interact with the workbench as you need – i.e. you can have all the settings stored in the preference store and configurable from the preference page, access the workspace and interact with your IDE (i.e. in our case it is possible to do AJAX call to disconnect JavaScript debugger).

There are two ways to register servlets:

  1. Programmatic (using OSGi APIs)
  2. 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.


4 Responses  
  • Aurelien Pupier writes:
    May 19th, 20108:38 amat

    “unable to find any documentation on how to use Jetty” Yes!! I’m not alone :) I already blogged for the same reason on another feature of Jetty (programmatic hot deploy) http://www.bonitasoft.org/blog/tutorial/programmatic-hot-deploy-with-jetty/

    I also opened a bug to improve help with Jetty : http://bugs.eclipse.org/bugs/show_bug.cgi?id=309553

  • Hugues Malphettes writes:
    May 19th, 20108:56 amat

    Hi Eugene,

    Indeed the JettyConfigurator API is the only API available with the eclipse platform to start a jetty6 server that provides the HttpService. It does serve its purpose but it is not advertised heavily as we are preparing for the support for web-applications in OSGi with the web-bundles.

    You could add to the eclipse-platform a full jetty-7 application server in the workbench and configure it using the standard jetty configuration files. It supports web-bundles, the HttpService and it is run from OSGi so the webapp-bundles are like any other OSGi bundles: http://wiki.eclipse.org/Jetty/Feature/Jetty_OSGi

    I hope this helps, Hugues

  • Blog bookmarks 05/21/2010 « My Diigo bookmarks writes:
    May 20th, 20109:32 pmat

    [...] Thoughts On Eclipse UI » Blog Archive » Using Jetty as an OSGi HTTP Service [...]

  • Lars Vogel writes:
    May 21st, 201010:58 pmat

    I believed I once heard there as plans to use Jetty in the OSGi reference implementation to help support the servlet 3.0 standard in OSGi.


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

»  Substance:WordPress   »  Style:Ahren Ahimsa