Reputation: 2296
I can't connect to my SOAP-Service listening on Port 9000 running a Spring-Boot application. The application is run in a docker container. The problem is that the soap-endpoint is listening on localhost instead of 0.0.0.0.
I want to bind the soap services on 0.0.0.0:9000 not 127.0.0.1:9000. How can I accomplish this?
Here my Setup:
Application.properties
soap.url = http://localhost:9000/
rest.url = http://localhost:9090/
server.port = 9090
Spring-boot starts up correctly
Springboot-Startup-log
2017-05-04 06:36:53.095 INFO 1 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 9090 (http)
2017-05-04 06:36:53.110 INFO 1 --- [ main] ch.gemdat.Application : Started Application in 28.285 seconds (JVM running for 29.465)
2017-05-04 06:36:55.387 INFO 1 --- [ main] myapp : - services/soap/form/call/v1
2017-05-04 06:36:55.388 INFO 1 --- [ main] myapp : >> myapp successfully started in 0:31 <<
The tomcat (rest-services) started and listens to port 9090 default on interface 0.0.0.0. The soap-services are bound to localhost:9000.
netstat -tulpn
tcp 0 0 0.0.0.0:9090 0.0.0.0:* LISTEN 1/java
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1/java
I perfectly can connect to all services running on port 9090. Because they are listening correctly on 0.0.0.0.
This is how I publish the soap-services:
private static void publishSoapServices() {
MyAppLogger.info("Register soap endpoints...");
BeanDefinitionRegistry beanDefRegistry = new SimpleBeanDefinitionRegistry();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(beanDefRegistry);
scanner.addIncludeFilter(new AssignableTypeFilter(MyAppService.class));
scanner.scan(Constants.SOAP_PACKAGE);
for (String bean : beanDefRegistry.getBeanDefinitionNames()) {
if (!bean.contains("springframework")) {
try {
Class<?> soapClass = Class.forName(beanDefRegistry.getBeanDefinition(bean).getBeanClassName());
if (MyAppSoapService.class.isAssignableFrom(soapClass)) {
MyAppService soapService = (MyAppService) soapClass.newInstance();
Endpoint.publish(PropertyReader.getValue("soap.url") + soapService.getEndpoint(), soapService);
ctx.getAutowireCapableBeanFactory().autowireBean(soapService);
MyAppLogger.info("- " + soapService.getEndpoint());
}
} catch (Exception e) {
MyAppLogger.error("Soap service ''{0}'' could not be published.", e, bean);
}
}
}
}
All services are available on localhost. Means http://localhost:9000/services/soap/form/call/v1
works. But when I run it in a docker container (run-arguments: -p 9000:9000 -p 9090:9090) only the rest-services are available (because they only listen to localhost... and rest-services listens to all ips(0.0.0.0))
Docker inspect shows that the port is mapped correctly:
"Ports": {
"9000/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "9000"
}
]
Upvotes: 2
Views: 1181
Reputation: 2296
After some trial and error I found the solution.
Application.properties
soap.url = http://0.0.0.0:9000/
rest.url = http://localhost:9090/
server.port = 9090
The solution is to set the soap.url
used in the application.properties
method to http://0.0.0.0:9000/
. It doesn't work for 0.0.0.0:9000/
what I initially tried.
Why does it work for the rest ports then?
Well it doesn't. The rest-services work because the ports are not published under rest.url
from the application.properties
. They are bound to the initial spring-boot-app-port set by reading server.port
from application.properties. The port got overridden by the tomcats default listening on the interface for 0.0.0.0
As P.J.Meisch stated - it is simply the soap.url
binding to localhost
being the problem.
Upvotes: 1