aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-25 19:18:39 +0300
committerGravatar Vitaly Takmazov2018-04-25 19:18:39 +0300
commite2c22a8ebd01e9ba623104ef1d624e1f7d7acdb9 (patch)
tree8c437dbd47777c534f930538d34db8ef446f8ffd
parent2bf63fc8d2a4b84e051d28e670c7c74b039e2545 (diff)
www: move api post url to config
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/NewMessage.java13
1 files 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<CommandResult> 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<CommandResult> 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<CommandResult> result = rest.postForEntity(
- "http://localhost:8081/post",
+ ResponseEntity<CommandResult> result = rest.postForEntity(postUri,
request, CommandResult.class);
if (result.getBody().getNewMessage().isPresent()) {
logger.info("/post: {}", jsonMapper.writeValueAsString(result.getBody()));