From e2c22a8ebd01e9ba623104ef1d624e1f7d7acdb9 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 25 Apr 2018 19:18:39 +0300 Subject: www: move api post url to config --- .../src/main/java/com/juick/www/controllers/NewMessage.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java index 3d6bc8cf..3186b796 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java +++ b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java @@ -44,6 +44,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.util.UriComponentsBuilder; import javax.inject.Inject; import java.io.IOException; @@ -82,6 +83,8 @@ public class NewMessage { private String imgDir; @Value("${upload_tmp_dir:#{systemEnvironment['TEMP'] ?: '/tmp'}}") private String tmpDir; + @Value("${api_url:http://localhost:8081}") + private String apiUrl; private RestTemplate rest = new RestTemplate(); private static final Logger logger = LoggerFactory.getLogger(NewMessage.class); @@ -165,8 +168,9 @@ public class NewMessage { if (StringUtils.isNotEmpty(attachmentFName.toString())) { params.add("img", attachmentFName.toASCIIString()); } + URI postUri = UriComponentsBuilder.fromUriString(apiUrl).path("/post").build().toUri(); ResponseEntity result = rest.postForEntity( - "http://localhost:8081/post", + postUri, request, CommandResult.class); logger.info("/comment: {}", jsonMapper.writeValueAsString(result.getBody())); return "redirect:/" + msg.getUser().getName() + "/" + mid + "#" + result.getBody().getNewMessage().get().getRid(); @@ -203,8 +207,9 @@ public class NewMessage { params.add("body", String.format("@%s %s", userTo.getName(), body)); params.add("hash", userService.getHashByUID(visitor.getUid())); + URI postUri = UriComponentsBuilder.fromUriString(apiUrl).path("/post").build().toUri(); ResponseEntity result = rest.postForEntity( - "http://localhost:8081/post", + postUri, request, CommandResult.class); logger.info("/pm: {}", jsonMapper.writeValueAsString(result.getBody())); return "redirect:/pm/sent"; @@ -243,9 +248,9 @@ public class NewMessage { if (StringUtils.isNotEmpty(attachmentFName.toString())) { params.add("img", attachmentFName.toASCIIString()); } + URI postUri = UriComponentsBuilder.fromUriString(apiUrl).path("/post").build().toUri(); try { - ResponseEntity result = rest.postForEntity( - "http://localhost:8081/post", + ResponseEntity result = rest.postForEntity(postUri, request, CommandResult.class); if (result.getBody().getNewMessage().isPresent()) { logger.info("/post: {}", jsonMapper.writeValueAsString(result.getBody())); -- cgit v1.2.3