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


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.

  • How can I start the HTTP service a second time on a different port?
  • When registering servlets, how can I know which service is bound to which port?

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

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

OSGi HTTP Bundle - Bind to two ports - http - iOS, 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  The Http Service allows other bundles in the OSGi environment to dynamically register resources and servlets into the URI namespace of Http Service. A bundle may later unregister its resources or servlets.

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.

102 Http Service Specification - OSGi Enterprise 7, The Http Service supports two standard techniques for this purpose: HttpContext - Allows bundles to provide information for a servlet or resource registration. org.osgi.service.http.port - This property specifies the port used for servlets and Component Context · 112.5.9 Activation Objects · 112.5.10 Binding Services  OSGi is a Java framework for developing and deploying modular software programs and libraries. Each bundle is a tightly coupled, dynamically loadable collection of classes, jars, and configuration files that explicitly declare their external dependencies (if any).

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


If I understand, the magic is in here:


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.

OSGI, You must also install the Apache Aries SPI Fly bundles as many parts of Jetty - for example jetty.http.port: If not specified, this defaults to the usual jetty port of 8080. jetty.home This header can be used in conjunction with either of the two preceding work.stereotype;version="[2.5.6,4.0.0)",org.springframework.web.​bind. Plug-in or bundle is a software component. The OSGi specification defines a bundle as the smallest unit of modularization, i.e., in OSGi a software component is a bundle. The Eclipse programming model typically calls them plug-in but these terms are interchangeable. In this tutorial the usage of plug-in is preferred.

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

Software Architecture: 10th European Conference, ECSA 2016, , We have chosen two well known component models, OSGi and SOFA, to explain A component (bundle) can register and use services through the service registry. Hence we suggest that a component binds through its port associated with a When both components are activated at runtime, the binding is established  OSGi has a layered model that is depicted in the following figure. Bundles – Bundles are the OSGi components made by the developers. Services – The services layer connects bundles in a dynamic way by offering a publish-find-bind model for plain old Java objects. Life-Cycle – The API to install, start, stop, update, and uninstall bundles.

[#FELIX-5349] Add ManagedServiceFactory to HTTP service, in this stack overflow conversation: http://stackoverflow.com/questions/​20074211/osgi-http-bundle-bind-to-two-ports I have experimented with  A negative port number has the same effect as setting org.apache.felix.http.enable to false. org.osgi.service.http.port.secure: The port used for servlets and resources available via HTTPS. The default is 8443. See port settings below for additional information. A negative port number has the same effect as setting org.apache.felix.https.enable to false.

User - Jetty and multiple jaxrs servers, Your proposed way sounds pretty good, it's also possible to bind your deploying multiple bundles with multiple jetty/jaxrs resources in Karaf? I is use osgi http service provided by pax-web), one port configuration is easier  The OSGi Alliance is proud to celebrate its 20th anniversary, marking two decades of growth and rising influence as a global consortium creating open specifications that enable Java modularity and microservices.

Bundle User Documentation - http, v5.2.1, Note: If the server fails to bind to a port, an HttpService will still be registered, but the org.osgi.service.http.port, Port number that the HTTP server will listen for Each entry in the vector is an array with two elements where the first is the file  It can be used as the underlying servlet transport provider within an OSGI framework. This post focus on what are major points to consider when integration Jetty within an OSGi environment. Integration. The main advantage of Jetty is that it is OSGi framework friendly. It has a set of bundles that can be used for this purpose.