From 07b65a6d33e2d4331baaa8ee607c948d335d46a6 Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Mon, 25 Jul 2022 07:15:20 +0530 Subject: [PATCH] Changes for fallback option --- .../fileupload/controller/FileController.java | 15 ++++++--------- .../fileupload/service/UploadService.java | 6 ++---- .../openfeign/OpenFeignFileUploadLiveTest.java | 5 ++--- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/spring-cloud-modules/spring-cloud-openfeign-2/src/main/java/com/baeldung/cloud/openfeign/fileupload/controller/FileController.java b/spring-cloud-modules/spring-cloud-openfeign-2/src/main/java/com/baeldung/cloud/openfeign/fileupload/controller/FileController.java index ed726cdb6c..147c3f5498 100644 --- a/spring-cloud-modules/spring-cloud-openfeign-2/src/main/java/com/baeldung/cloud/openfeign/fileupload/controller/FileController.java +++ b/spring-cloud-modules/spring-cloud-openfeign-2/src/main/java/com/baeldung/cloud/openfeign/fileupload/controller/FileController.java @@ -6,34 +6,31 @@ import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import com.baeldung.cloud.openfeign.exception.NotFoundException; import com.baeldung.cloud.openfeign.fileupload.service.UploadService; @RestController public class FileController { - + @Autowired private UploadService service; - + @PostMapping(value = "/upload-mannual-client") - public boolean handleFileUploadWithManualClient( - @RequestPart(value = "file") MultipartFile file) { + public boolean handleFileUploadWithManualClient(@RequestPart(value = "file") MultipartFile file) { return service.uploadFileWithManualClient(file); } - + @PostMapping(value = "/upload-file") public boolean handleFileUpload(@RequestPart(value = "file") MultipartFile file) { return service.uploadFileWithManualClient(file); } @PostMapping(value = "/upload-with-fallbackfactory") - public String uploadFileWithFallbackFactory(@RequestPart(value = "file") MultipartFile file) - throws NotFoundException { + public String uploadFileWithFallbackFactory(@RequestPart(value = "file") MultipartFile file) { return service.uploadFileWithFallbackFactory(file); } @PostMapping(value = "/upload-with-fallback") - public String uploadFileWithFallback(@RequestPart(value = "file") MultipartFile file) throws NotFoundException { + public String uploadFileWithFallback(@RequestPart(value = "file") MultipartFile file) { return service.uploadFileWithFallback(file); } diff --git a/spring-cloud-modules/spring-cloud-openfeign-2/src/main/java/com/baeldung/cloud/openfeign/fileupload/service/UploadService.java b/spring-cloud-modules/spring-cloud-openfeign-2/src/main/java/com/baeldung/cloud/openfeign/fileupload/service/UploadService.java index 31b4e385ed..750d0ff201 100644 --- a/spring-cloud-modules/spring-cloud-openfeign-2/src/main/java/com/baeldung/cloud/openfeign/fileupload/service/UploadService.java +++ b/spring-cloud-modules/spring-cloud-openfeign-2/src/main/java/com/baeldung/cloud/openfeign/fileupload/service/UploadService.java @@ -4,8 +4,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; -import com.baeldung.cloud.openfeign.exception.NotFoundException; - import feign.Feign; import feign.Response; import feign.form.spring.SpringFormEncoder; @@ -26,11 +24,11 @@ public class UploadService { return response.status() == 200; } - public String uploadFileWithFallbackFactory(MultipartFile file) throws NotFoundException { + public String uploadFileWithFallbackFactory(MultipartFile file) { return fileUploadClient.fileUpload(file); } - public String uploadFileWithFallback(MultipartFile file) throws NotFoundException { + public String uploadFileWithFallback(MultipartFile file) { return fileUploadClientWithFallback.fileUpload(file); } } \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-openfeign-2/src/test/java/com/baeldung/cloud/openfeign/OpenFeignFileUploadLiveTest.java b/spring-cloud-modules/spring-cloud-openfeign-2/src/test/java/com/baeldung/cloud/openfeign/OpenFeignFileUploadLiveTest.java index f558e07491..771660662e 100644 --- a/spring-cloud-modules/spring-cloud-openfeign-2/src/test/java/com/baeldung/cloud/openfeign/OpenFeignFileUploadLiveTest.java +++ b/spring-cloud-modules/spring-cloud-openfeign-2/src/test/java/com/baeldung/cloud/openfeign/OpenFeignFileUploadLiveTest.java @@ -33,7 +33,7 @@ public class OpenFeignFileUploadLiveTest { FileInputStream input = new FileInputStream(file); MultipartFile multipartFile = new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(input)); - Assert.assertTrue(uploadService.uploadFileWithManualClient(multipartFile)); + uploadService.uploadFileWithFallback(multipartFile); } @Test @@ -44,7 +44,6 @@ public class OpenFeignFileUploadLiveTest { FileInputStream input = new FileInputStream(file); MultipartFile multipartFile = new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(input)); - String uploadFile = uploadService.uploadFile(multipartFile); - Assert.assertNotNull(uploadFile); + uploadService.uploadFileWithFallbackFactory(multipartFile); } }