JAVA-17818 Split or move spring-cloud-openfeign module (conti-2) (#13485)

Co-authored-by: timis1 <[email protected]>
This commit is contained in:
timis1
2023-02-20 21:48:26 +05:30
committed by GitHub
co-authored by timis1
parent 639de9687e
commit 09382f545e
42 changed files with 269 additions and 140 deletions
+5
View File
@@ -7,3 +7,8 @@ This module contains articles about Feign
- [Intro to Feign](https://www.baeldung.com/intro-to-feign)
- [Retrying Feign Calls](https://www.baeldung.com/feign-retry)
- [Setting Request Headers Using Feign](https://www.baeldung.com/java-feign-request-headers)
- [File Upload With Open Feign](https://www.baeldung.com/java-feign-file-upload)
- [Feign Logging Configuration](https://www.baeldung.com/java-feign-logging)
- [Retrieve Original Message From Feign ErrorDecoder](https://www.baeldung.com/feign-retrieve-original-message)
- [RequestLine with Feign Client](https://www.baeldung.com/feign-requestline)
- [Propagating Exceptions With OpenFeign and Spring](https://www.baeldung.com/spring-openfeign-propagate-exception)
+19
View File
@@ -64,6 +64,22 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form-spring</artifactId>
<version>${feign.form.spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>${spring.cloud.openfeign.version}</version>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<version>${wire.mock.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@@ -118,6 +134,9 @@
<properties>
<feign.version>11.8</feign.version>
<wsdl4j.version>1.6.3</wsdl4j.version>
<feign.form.spring.version>3.8.0</feign.form.spring.version>
<spring.cloud.openfeign.version>3.1.2</spring.cloud.openfeign.version>
<wire.mock.version>2.33.2</wire.mock.version>
</properties>
</project>
@@ -0,0 +1,16 @@
package com.baeldung.core;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableFeignClients
public class ExampleApplication {
public static void main(String[] args) {
SpringApplication.run(ExampleApplication.class, args);
}
}
@@ -1,6 +1,7 @@
package com.baeldung.cloud.openfeign.client;
package com.baeldung.core.client;
import com.baeldung.core.model.Employee;
import com.baeldung.cloud.openfeign.model.Employee;
import feign.Headers;
import feign.Param;
import feign.RequestLine;
@@ -0,0 +1,13 @@
package com.baeldung.core.client;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import com.baeldung.core.config.FeignConfig;
@FeignClient(name = "user-client", url="https://jsonplaceholder.typicode.com", configuration = FeignConfig.class)
public interface UserClient {
@GetMapping(value = "/users")
String getUsers();
}
@@ -1,7 +1,8 @@
package com.baeldung.cloud.openfeign.config;
package com.baeldung.core.config;
import org.springframework.context.annotation.Bean;
import feign.Logger;
import org.springframework.context.annotation.Bean;
public class FeignConfig {
@@ -1,13 +1,15 @@
package com.baeldung.cloud.openfeign.controller;
package com.baeldung.core.controller;
import com.baeldung.cloud.openfeign.client.EmployeeClient;
import com.baeldung.cloud.openfeign.model.Employee;
import feign.Feign;
import feign.form.spring.SpringFormEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baeldung.core.client.EmployeeClient;
import com.baeldung.core.model.Employee;
import feign.Feign;
import feign.form.spring.SpringFormEncoder;
@RestController
public class EmployeeController {
@@ -1,13 +1,13 @@
package com.baeldung.cloud.openfeign.customizederrorhandling.client;
import com.baeldung.cloud.openfeign.customizederrorhandling.config.FeignConfig;
import com.baeldung.cloud.openfeign.defaulterrorhandling.model.Product;
package com.baeldung.core.customizederrorhandling.client;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.baeldung.core.customizederrorhandling.config.FeignConfig;
import com.baeldung.core.defaulterrorhandling.model.Product;
@FeignClient(name = "product-client-2", url = "http://localhost:8081/product/", configuration = FeignConfig.class)
public interface ProductClient {
@@ -1,8 +1,9 @@
package com.baeldung.cloud.openfeign.customizederrorhandling.config;
package com.baeldung.core.customizederrorhandling.config;
import com.baeldung.core.customizederrorhandling.exception.ProductNotFoundException;
import com.baeldung.core.customizederrorhandling.exception.ProductServiceNotAvailableException;
import com.baeldung.core.exception.BadRequestException;
import com.baeldung.cloud.openfeign.exception.BadRequestException;
import com.baeldung.cloud.openfeign.customizederrorhandling.exception.ProductNotFoundException;
import com.baeldung.cloud.openfeign.customizederrorhandling.exception.ProductServiceNotAvailableException;
import feign.Response;
import feign.codec.ErrorDecoder;
@@ -1,8 +1,9 @@
package com.baeldung.cloud.openfeign.customizederrorhandling.config;
package com.baeldung.core.customizederrorhandling.config;
import org.springframework.context.annotation.Bean;
import feign.Logger;
import feign.codec.ErrorDecoder;
import org.springframework.context.annotation.Bean;
public class FeignConfig {
@@ -1,12 +1,13 @@
package com.baeldung.cloud.openfeign.customizederrorhandling.controller;
package com.baeldung.core.customizederrorhandling.controller;
import com.baeldung.cloud.openfeign.customizederrorhandling.client.ProductClient;
import com.baeldung.cloud.openfeign.defaulterrorhandling.model.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baeldung.core.customizederrorhandling.client.ProductClient;
import com.baeldung.core.defaulterrorhandling.model.Product;
@RestController("product_controller2")
@RequestMapping(value = "myapp2")
@@ -1,10 +1,11 @@
package com.baeldung.cloud.openfeign.customizederrorhandling.exception;
package com.baeldung.core.customizederrorhandling.exception;
import java.util.Date;
import org.springframework.http.HttpStatus;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.http.HttpStatus;
import java.util.Date;
public class ErrorResponse {
@@ -1,6 +1,5 @@
package com.baeldung.cloud.openfeign.customizederrorhandling.exception;
package com.baeldung.core.customizederrorhandling.exception;
import com.baeldung.cloud.openfeign.exception.BadRequestException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -1,4 +1,4 @@
package com.baeldung.cloud.openfeign.customizederrorhandling.exception;
package com.baeldung.core.customizederrorhandling.exception;
public class ProductNotFoundException extends RuntimeException {
@@ -1,4 +1,4 @@
package com.baeldung.cloud.openfeign.customizederrorhandling.exception;
package com.baeldung.core.customizederrorhandling.exception;
public class ProductServiceNotAvailableException extends RuntimeException {
@@ -1,13 +1,13 @@
package com.baeldung.cloud.openfeign.defaulterrorhandling.client;
import com.baeldung.cloud.openfeign.defaulterrorhandling.config.FeignConfig;
import com.baeldung.cloud.openfeign.defaulterrorhandling.model.Product;
package com.baeldung.core.defaulterrorhandling.client;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.baeldung.core.defaulterrorhandling.config.FeignConfig;
import com.baeldung.core.defaulterrorhandling.model.Product;
@FeignClient(name = "product-client", url = "http://localhost:8084/product/", configuration = FeignConfig.class)
public interface ProductClient {
@@ -1,7 +1,8 @@
package com.baeldung.cloud.openfeign.defaulterrorhandling.config;
package com.baeldung.core.defaulterrorhandling.config;
import org.springframework.context.annotation.Bean;
import feign.Logger;
import org.springframework.context.annotation.Bean;
public class FeignConfig {
@@ -1,10 +1,13 @@
package com.baeldung.cloud.openfeign.defaulterrorhandling.controller;
package com.baeldung.core.defaulterrorhandling.controller;
import com.baeldung.cloud.openfeign.defaulterrorhandling.client.ProductClient;
import com.baeldung.cloud.openfeign.defaulterrorhandling.model.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baeldung.core.defaulterrorhandling.client.ProductClient;
import com.baeldung.core.defaulterrorhandling.model.Product;
@RestController("product_controller1")
@RequestMapping(value ="myapp1")
@@ -1,4 +1,4 @@
package com.baeldung.cloud.openfeign.defaulterrorhandling.model;
package com.baeldung.core.defaulterrorhandling.model;
public class Product {
@@ -0,0 +1,21 @@
package com.baeldung.core.exception;
public class BadRequestException extends Exception {
public BadRequestException() {
}
public BadRequestException(String message) {
super(message);
}
public BadRequestException(Throwable cause) {
super(cause);
}
@Override
public String toString() {
return "BadRequestException: "+getMessage();
}
}
@@ -0,0 +1,18 @@
package com.baeldung.core.exception;
public class NotFoundException extends Exception {
public NotFoundException(String message) {
super(message);
}
public NotFoundException(Throwable cause) {
super(cause);
}
@Override
public String toString() {
return "NotFoundException: " + getMessage();
}
}
@@ -1,4 +1,4 @@
package com.baeldung.cloud.openfeign.fileupload.config;
package com.baeldung.core.fileupload.config;
public class ExceptionMessage {
private String timestamp;
@@ -1,6 +1,5 @@
package com.baeldung.cloud.openfeign.fileupload.config;
package com.baeldung.core.fileupload.config;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
@@ -13,12 +12,7 @@ import feign.form.spring.SpringFormEncoder;
public class FeignSupportConfig {
@Bean
public Encoder multipartFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(new ObjectFactory<HttpMessageConverters>() {
@Override
public HttpMessageConverters getObject() {
return new HttpMessageConverters(new RestTemplate().getMessageConverters());
}
}));
return new SpringFormEncoder(new SpringEncoder(() -> new HttpMessageConverters(new RestTemplate().getMessageConverters())));
}
@Bean
@@ -1,10 +1,10 @@
package com.baeldung.cloud.openfeign.fileupload.config;
package com.baeldung.core.fileupload.config;
import java.io.IOException;
import java.io.InputStream;
import com.baeldung.cloud.openfeign.exception.BadRequestException;
import com.baeldung.cloud.openfeign.exception.NotFoundException;
import com.baeldung.core.exception.BadRequestException;
import com.baeldung.core.exception.NotFoundException;
import com.fasterxml.jackson.databind.ObjectMapper;
import feign.Response;
@@ -15,7 +15,7 @@ public class RetreiveMessageErrorDecoder implements ErrorDecoder {
@Override
public Exception decode(String methodKey, Response response) {
ExceptionMessage message = null;
ExceptionMessage message;
try (InputStream bodyIs = response.body()
.asInputStream()) {
ObjectMapper mapper = new ObjectMapper();
@@ -1,4 +1,4 @@
package com.baeldung.cloud.openfeign.fileupload.controller;
package com.baeldung.core.fileupload.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
@@ -6,7 +6,7 @@ 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.fileupload.service.UploadService;
import com.baeldung.core.fileupload.service.UploadService;
@RestController
public class FileController {
@@ -1,4 +1,4 @@
package com.baeldung.cloud.openfeign.fileupload.service;
package com.baeldung.core.fileupload.service;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
@@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import com.baeldung.cloud.openfeign.fileupload.config.FeignSupportConfig;
import com.baeldung.core.fileupload.config.FeignSupportConfig;
@FeignClient(name = "file", url = "http://localhost:8081", configuration = FeignSupportConfig.class)
public interface UploadClient {
@@ -1,4 +1,4 @@
package com.baeldung.cloud.openfeign.fileupload.service;
package com.baeldung.core.fileupload.service;
import org.springframework.web.multipart.MultipartFile;
@@ -1,4 +1,4 @@
package com.baeldung.cloud.openfeign.fileupload.service;
package com.baeldung.core.fileupload.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -1,4 +1,4 @@
package com.baeldung.cloud.openfeign.model;
package com.baeldung.core.model;
public class Employee {
@@ -5,3 +5,5 @@ ws.port.type.name=UsersPort
ws.target.namespace=http://www.baeldung.com/springbootsoap/feignclient
ws.location.uri=http://localhost:${server.port}/ws/users/
debug=false
logging.level.com.baeldung.core=DEBUG

Some files were not shown because too many files have changed in this diff Show More