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