Search code examples
javaapache-camelcxfapache-karafapache-servicemix

REST service deployed in Apache ServiceMix not accessible remotely


I am deploying an angular2 webapp in servicemix as a war file. This makes the app run on localhost:8181/angular2webapp url. I have a bundle installed for REST requests, which is basically a camel component.

<cxf:rsServer id="rsServer" address="http://localhost:9090"
serviceClass="com.mypackage.class.MyClass" />

Now this is a different origin request which I have configured to be allowed. All this setup is working fine on a single machine(Machine1). When I am trying to access x.x.x.x:8181/angular2webappfrom a different machine(Machine2) in the same network, it is opening the basic page but when I call click a button which calls a REST endpoint of com.mypackage.class.MyClass in order to fill a table, I can see in browser console of Machine2 GET http://localhost:9090/deviceservice/devices net::ERR_CONNECTION_REFUSED. I hosted the cxf server on x.x.x.x as

<cxf:rsServer id="rsServer" address="http://x.x.x.x:9090"
serviceClass="com.mypackage.class.MyClass" />

and changed angular2 code to call 'x.x.x.x:9090 but it didnt work too. Moreover, I can call the REST service from postman as GET on http://localhost:9090... but not as x.x.x.x:9090....

OR IS THE RIGHT QUESTION:

Is there a way to expose the REST server from ServiceMix outside? If not, should I use something like NGINIX as a proxy server so that it everything happens with localhost? What is the right thing to do?


Solution

  • Use 0.0.0.0 instead of localhost in the address

    address="http://0.0.0.0:9090"
    

    You can likely find questions on SO about the difference between localhost/127.0.0.1 and 0.0.0.0 etc such as: What is the difference between 0.0.0.0, 127.0.0.1 and localhost?