1

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?

рüффп
  • 5,172
  • 34
  • 67
  • 113
Farid Jafri
  • 346
  • 1
  • 9

1 Answers1

2

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?

Community
  • 1
  • 1
Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65
  • Thanks it worked :) Could you also tell me the difference between a server created with cxf:rsServer and cxf:cxfEndpoint? Like it is done in this page: https://github.com/apache/servicemix/blob/master/examples/camel/camel-cxf-soap/camel-cxf-soap-route/src/main/resources/OSGI-INF/blueprint/blueprint.xml – Farid Jafri Apr 21 '17 at 06:37
  • Also, I am putting in the IP in angular2 code. Is this a wrong way of doing different origin request? Should I have a proxy server or accept requests? Can you recommend a better way? – Farid Jafri Apr 21 '17 at 06:48
  • This seems not work with https , the netstat command tell me it listen on 127.0.0.1 – 4535992 Oct 08 '19 at 07:19