Search code examples
javaosgijax-rsblueprint-osgi

OSGI Blueprint jaxrs server endpoint configuration - how to configure address?


I have a REST service I've set up using OSGI (running in Karaf).

<jaxrs:server address="http://localhost:9001/rest" id="myFileService" >
        <jaxrs:serviceBeans>
            <ref component-id="FileServicesImpl" />
        </jaxrs:serviceBeans>
</jaxrs:server>

When I browse to http://localhost:8181/cxf, if lists my services, and I can successfully connect to my service at http://localhost:9001/rest . If I go to http://MyMachineName:8181/cxf, I get the service list, but if I go to http://MyMachineName:9001/rest the address is not found.

For what it's worth, when I browse to the /cxf link using MyMachineName, it still lists the endpoint as localhost.

Is there a way to configure the endpoint address in the blueprint config so that it responds the both localhost and the machine name? Or to just specific the port? Or do I have to hardcode the machine name or incorporate it into a config file and force it to the machine name?


Solution

  • You have two options here. The first is using http://0.0.0.0:9001/rest as url. This will tell cxf to bind to all ip adresses the server has.

    The other option which I prefer is to just user /rest as url. In this case cxf will bind to the OSGi http service which is implemented by pax web in karaf. So you can setup the port and eventually https settings on the pax web level.