diff --git a/prd/src/main/java/site/ocr/prd/WebClientConfig.java b/prd/src/main/java/site/ocr/prd/WebClientConfig.java index 0e1063d..488511a 100644 --- a/prd/src/main/java/site/ocr/prd/WebClientConfig.java +++ b/prd/src/main/java/site/ocr/prd/WebClientConfig.java @@ -2,6 +2,7 @@ package site.ocr.prd; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; import org.springframework.web.reactive.function.client.WebClient; @Configuration @@ -13,4 +14,8 @@ public class WebClientConfig { .build(); } + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } } \ No newline at end of file diff --git a/prd/src/main/java/site/ocr/prd/contorllers/ImgController.java b/prd/src/main/java/site/ocr/prd/contorllers/ImgController.java index be82047..03b12ab 100644 --- a/prd/src/main/java/site/ocr/prd/contorllers/ImgController.java +++ b/prd/src/main/java/site/ocr/prd/contorllers/ImgController.java @@ -1,20 +1,50 @@ package site.ocr.prd.contorllers; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.multipart.MultipartFile; @RestController public class ImgController { + + private final RestTemplate restTemplate; + + @Autowired + public ImgController(RestTemplate restTemplate) { + this.restTemplate = restTemplate; + } @PostMapping("img/get-img") - public void postGetImg(@RequestPart("image") MultipartFile image) { - image.getResource(); + public ResponseEntity postGetImg(@RequestPart("image") MultipartFile image) { System.out.println("image :: " + image.getResource().getFilename()); + + //헤더 설정(이미지) + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.MULTIPART_FORM_DATA); + + //바디에 이미지 파일 추가 + MultiValueMap body = new LinkedMultiValueMap<>(); + body.add("image", image.getResource()); + + //요청 엔티티 생성 + HttpEntity> requestEntity = new HttpEntity<>(body, headers); + + //요청 전송 + ResponseEntity response = + restTemplate.postForEntity("http://localhost:9002/ocr", + requestEntity, String.class); + + return ResponseEntity.ok(response.getBody()); } }