You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Gary Hodgson <ga...@gmail.com> on 2015/08/26 08:39:29 UTC

[DOSGI] Dynamic Port Allocation?

Hello,

I would like to be able to deploy multiple services in multiple Karaf
instances without having to configure any port numbers for them.  I have
done some experimenting but I am not sure if I have missed something which
allows me to do what I want out of the box.  I'll run through my
understanding so far to see if it's in-line with reality.

Assuming each Karaf instance has it's own http service already (and the
discovery of this port is already taken care of), I know that setting
"org.apache.cxf.ws.httpservice.context" on each service will make it
discoverable via that address.  However the service itself is made
available from a new jetty instance started by default on port 9000. The
problem appears that if I deploy the same service on another instance there
is a port conflict on 9000.  I could set the port via
"org.apache.cxf.ws.address" but would much prefer to not have to manage
port allocation etc.

One attempt so far has me setting "org.apache.cxf.ws.address" via an
Activator, (allocating an available port via ServerSocket), but this has
two disadvantages: it means I can't take advantage of DI in my service;
and, there is the slim chance that the port is taken in the time between
the activator finding it and jetty creating a server with it.

I also see that if I set "org.apache.cxf.ws.address" to "
http://localhost:0/service" then jetty will correctly allocate a free port,
but then the Endpoint Address in DOSGi is not updated with the correct
local port and therefore not discoverable.

Ultimately I would like to know if there is a way to configure CXF-DOSGI to
allocate a free port for each service and still have it discoverable?  Or
is this not yet currently supported?  I'd happily take a crack at
implementing such a feature but I suspect it's not trivial to do it
correctly as it requires jetty to tell DOSGI what port has been allocated
after the server has been created.

Would love to hear whether I am missing something or whether my
understanding so far is correct.  For reference, I'm currently trying this
with Karaf 3.0.4 and cxf-dosgi 1.7.0

Thanks,
Gary