John Streets
John Streets

Reputation: 155

How to Embed Web Server in OSGi Framework?

I'd like to know how do I run a HTTP server into an OSGi platform. I am currently using Equinox and found some official info about embedding Jetty bundle, but links to dependencies seem broken and overall it isn't well documented. (http://www.eclipse.org/equinox/server/http_in_equinox.php)

Thank you.

Upvotes: 0

Views: 2048

Answers (4)

Victor Bashurov
Victor Bashurov

Reputation: 380

All you need is to have corresponding bundles installed to your embedded OSGI framework. There is a code sample: https://bitbucket.org/vbashur/diff/ Take a look on osgimain and osgiservice projects

Upvotes: 0

matteo rulli
matteo rulli

Reputation: 1493

You could use Virgo: it's based on equinox and integrates tomcat.

As for Jetty server, it is for sure embeddable into OSGi: the Apache CXF project uses jetty to serve SOAP requests and CXF runs in OSGi without any problem.

Upvotes: 0

Achim Nierbeck
Achim Nierbeck

Reputation: 5285

There is also Pax-Web, which gives you a ton of features. Take a look at http://team.ops4j.org/wiki/display/paxweb/Pax+Web. It suports std. Http- service, whiteboard exrender for Servlets, filters, jsps. And also war (either std or with osgi manifest).

Upvotes: 0

Peter Kriens
Peter Kriens

Reputation: 15372

Just take a look at Apache Felix Http service http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html Since these are well designed OSGi bundles, they run also in Equinox.

I am using their whiteboard model, with this bundle you just register a Servlet with a service property. If you want to check this all out, suggest you download bndtools and create a runtime with webconsole and DS. This is ALL you have to write for a Hello World servlet:

package com.example;

@Component(alias="/hello", provide=Servlet.class)
public MyServlet extends HttpServlet {
  public void doGet(HttpServletRequest req, HttpServletResponse rsp) {
     rsp.setContentType("text/plain;charset=UTF-8");
     rsp.getOutputStream().write("Hello World".getBytes("UTF-8"));
  }
}

Upvotes: 1

Related Questions