Newer
Older
task-bldg / src / main / java / osm / surveyor / task / index / IndexController.java
  1. package osm.surveyor.task.index;
  2.  
  3. import org.springframework.beans.factory.annotation.Value;
  4. import org.springframework.http.HttpMethod;
  5. import org.springframework.http.HttpStatus;
  6. import org.springframework.http.ResponseEntity;
  7. import org.springframework.web.bind.annotation.GetMapping;
  8. import org.springframework.web.bind.annotation.RestController;
  9. import org.springframework.web.client.RestTemplate;
  10.  
  11. @RestController
  12. public class IndexController {
  13. @Value("${task-bldg.osm-data.url}")
  14. private String url;
  15.  
  16. @GetMapping("/index")
  17. public String index() {
  18. try {
  19. RestTemplate restTemplate = new RestTemplate();
  20. System.out.println(String.format("INFO: httpGet(%s)", url));
  21. ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, null, String.class);
  22. HttpStatus httpStatus = response.getStatusCode();
  23. if (httpStatus.isError()) {
  24. System.out.println("ERROE: Can not access '"+ url +"'");
  25. throw new Exception("ERROE: Can not access '"+ url +"'");
  26. }
  27. String body = response.getBody();
  28. return body;
  29. }
  30. catch (Exception e) {
  31. return e.toString();
  32. }
  33. }
  34. }