I have two Spring web services which should communicate via http. Both of them are running on my machine in dcoker containers over openjdk:8-jre-alpine. Here is the POST query which fails with "Connection refused" :
public String createPost(int playerCount) {
String uri = URI + "/create";
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(uri)
.queryParam("playerCount", playerCount);
HttpEntity<?> entity = new HttpEntity<>(headers);
ResponseEntity<String> response = rest.exchange(
builder.build().encode().toUri(),
HttpMethod.POST,
entity,
String.class);
logger.info("Create request");
return response.getBody();
}
URI is http://localhost:8090/game
Here is corresponding controller of other service:
@RequestMapping(
path = "create",
method = RequestMethod.POST,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<Long> create(@RequestParam("playerCount") int playerCount) {
long gameId = gameService.create(playerCount);
HttpHeaders headers = new HttpHeaders();
headers.add("Access-Control-Allow-Origin", "*");
return new ResponseEntity<>(gameId, headers, HttpStatus.OK);
}
I'm simply running both containers with run -p 8080:8080
and '8090:8090' . And as I said previously getting "Connection refused" How to set up communication properly?
NOTE: it works fine if I run it with Intellij.