Philipp
Philipp

Reputation: 4799

OSGi HTTP Bundle - Bind to two ports

I'm using the Apache Felix HTTP Jetty bundle. I can start the servlet container / HttpService and assign it to a port using the system property

org.osgi.service.http.port=8080

But I would like to have two such services, bound to two different ports, eg my application API should be served on 8080, but some static web pages should be served on port 80.

Edit: for that last question, the service comes with the port value set in a property org.osgi.service.http.port: 8080

Upvotes: 1

Views: 2874

Answers (4)

Derek Baum
Derek Baum

Reputation: 665

Felix http.jetty 3.2.6 provides a ManagedServiceFactory, which makes it easy to create multiple http instances with different configurations.

Upvotes: 1

Sheena Artrip
Sheena Artrip

Reputation: 2010

I believe you can if the Apache Felix HTTP Jetty bundle exposes a ManagedServiceFactory. (EDIT: It does not)

How to support virtual hosts with OSGI HttpService

http://www.codeaffine.com/2011/10/05/raprwt-osgi-integration-ii/

If I understand, the magic is in here:

http://www.osgi.org/javadoc/r2/org/osgi/service/cm/ConfigurationAdmin.html#createFactoryConfiguration(java.lang.String)

If you create and register a Configuration using the pid of the managed service factory, it will create a new instance of HttpService using a new Pid.

Upvotes: 0

Achim Nierbeck
Achim Nierbeck

Reputation: 5285

If you switch over to Pax-Web you'll be able to do something like it. Pax-Web supports Virtual Hosts, and let's you bind a certain application to a single connection. Some more details on how to use it you'll find at my two blog posts:
Bind web applications to specific http connectors - part 1
Bind web applications to specific http connectors - part 2

Upvotes: 2

Peter Kriens
Peter Kriens

Reputation: 15372

As far as I know this is not possible with the Http servers in OSGi I've worked with. Creating a little forwarder between the ports is of course quite easy to do in Java.

Upvotes: 0

Related Questions