JAVA-23235 Split or move spring-cloud-openfeign module (conti-4) (moved-8) (#14450)
Co-authored-by: timis1 <noreplay@yahoo.com>
This commit is contained in:
parent
d0348f344e
commit
817170a1bf
|
@ -6,4 +6,5 @@ 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)
|
||||
- [Setting Request Headers Using Feign](https://www.baeldung.com/java-feign-request-headers)
|
||||
- [RequestLine with Feign Client](https://www.baeldung.com/feign-requestline)
|
|
@ -1,2 +1,5 @@
|
|||
## Relevant Articles
|
||||
- [Setup Http Patch Request With OpenFeign](https://www.baeldung.com/openfeign-http-patch-request)
|
||||
- [Introduction to Spring Cloud OpenFeign](https://www.baeldung.com/spring-cloud-openfeign)
|
||||
- [Feign Logging Configuration](https://www.baeldung.com/java-feign-logging)
|
||||
- [Configuring Spring Cloud FeignClient URL](https://www.baeldung.com/spring-cloud-feignclient-url)
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package com.baeldung.cloud.openfeign.client;
|
||||
|
||||
import com.baeldung.cloud.openfeign.model.Album;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import com.baeldung.cloud.openfeign.model.Album;
|
||||
|
||||
@FeignClient(name = "albumClient", url = "https://jsonplaceholder.typicode.com/albums/")
|
||||
public interface AlbumClient {
|
||||
@GetMapping(value = "/{id}")
|
|
@ -1,14 +1,15 @@
|
|||
package com.baeldung.cloud.openfeign.client;
|
||||
|
||||
import com.baeldung.cloud.openfeign.config.ClientConfiguration;
|
||||
import com.baeldung.cloud.openfeign.hystrix.JSONPlaceHolderFallback;
|
||||
import com.baeldung.cloud.openfeign.model.Post;
|
||||
import java.util.List;
|
||||
|
||||
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 java.util.List;
|
||||
import com.baeldung.cloud.openfeign.config.ClientConfiguration;
|
||||
import com.baeldung.cloud.openfeign.hystrix.JSONPlaceHolderFallback;
|
||||
import com.baeldung.cloud.openfeign.model.Post;
|
||||
|
||||
@FeignClient(value = "jplaceholder",
|
||||
url = "https://jsonplaceholder.typicode.com/",
|
|
@ -1,10 +1,11 @@
|
|||
package com.baeldung.cloud.openfeign.client;
|
||||
|
||||
import com.baeldung.cloud.openfeign.model.Post;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import com.baeldung.cloud.openfeign.model.Post;
|
||||
|
||||
@FeignClient(name = "postClient", url = "${spring.cloud.openfeign.client.config.postClient.url}")
|
||||
public interface PostClient {
|
||||
@GetMapping(value = "/{id}")
|
|
@ -1,10 +1,12 @@
|
|||
package com.baeldung.cloud.openfeign.client;
|
||||
|
||||
import com.baeldung.cloud.openfeign.model.Todo;
|
||||
import feign.RequestLine;
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
|
||||
import java.net.URI;
|
||||
import com.baeldung.cloud.openfeign.model.Todo;
|
||||
|
||||
import feign.RequestLine;
|
||||
|
||||
@FeignClient(name = "todoClient")
|
||||
public interface TodoClient {
|
|
@ -2,6 +2,7 @@ package com.baeldung.cloud.openfeign.config;
|
|||
|
||||
import com.baeldung.cloud.openfeign.exception.BadRequestException;
|
||||
import com.baeldung.cloud.openfeign.exception.NotFoundException;
|
||||
|
||||
import feign.Response;
|
||||
import feign.codec.ErrorDecoder;
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
package com.baeldung.cloud.openfeign.config;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import feign.RequestInterceptor;
|
||||
import feign.RequestTemplate;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class DynamicUrlInterceptor implements RequestInterceptor {
|
||||
|
||||
private final Supplier<String> urlSupplier;
|
|
@ -1,16 +1,7 @@
|
|||
package com.baeldung.cloud.openfeign.controller;
|
||||
|
||||
import com.baeldung.cloud.openfeign.config.DynamicUrlInterceptor;
|
||||
import com.baeldung.cloud.openfeign.client.AlbumClient;
|
||||
import com.baeldung.cloud.openfeign.client.PostClient;
|
||||
import com.baeldung.cloud.openfeign.client.TodoClient;
|
||||
import com.baeldung.cloud.openfeign.model.Album;
|
||||
import com.baeldung.cloud.openfeign.model.Post;
|
||||
import com.baeldung.cloud.openfeign.model.Todo;
|
||||
import feign.Feign;
|
||||
import feign.Target;
|
||||
import feign.codec.Decoder;
|
||||
import feign.codec.Encoder;
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||
|
@ -24,7 +15,18 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.net.URI;
|
||||
import com.baeldung.cloud.openfeign.client.AlbumClient;
|
||||
import com.baeldung.cloud.openfeign.client.PostClient;
|
||||
import com.baeldung.cloud.openfeign.client.TodoClient;
|
||||
import com.baeldung.cloud.openfeign.config.DynamicUrlInterceptor;
|
||||
import com.baeldung.cloud.openfeign.model.Album;
|
||||
import com.baeldung.cloud.openfeign.model.Post;
|
||||
import com.baeldung.cloud.openfeign.model.Todo;
|
||||
|
||||
import feign.Feign;
|
||||
import feign.Target;
|
||||
import feign.codec.Decoder;
|
||||
import feign.codec.Encoder;
|
||||
|
||||
@RestController
|
||||
@Import(FeignClientsConfiguration.class)
|
|
@ -0,0 +1,21 @@
|
|||
package com.baeldung.cloud.openfeign.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.cloud.openfeign.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,12 +1,13 @@
|
|||
package com.baeldung.cloud.openfeign.hystrix;
|
||||
|
||||
import com.baeldung.cloud.openfeign.client.JSONPlaceHolderClient;
|
||||
import com.baeldung.cloud.openfeign.model.Post;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.baeldung.cloud.openfeign.client.JSONPlaceHolderClient;
|
||||
import com.baeldung.cloud.openfeign.model.Post;
|
||||
|
||||
@Component
|
||||
public class JSONPlaceHolderFallback implements JSONPlaceHolderClient {
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package com.baeldung.cloud.openfeign.service;
|
||||
|
||||
import com.baeldung.cloud.openfeign.model.Post;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baeldung.cloud.openfeign.model.Post;
|
||||
|
||||
public interface JSONPlaceHolderService {
|
||||
|
||||
List<Post> getPosts();
|
|
@ -1,12 +1,13 @@
|
|||
package com.baeldung.cloud.openfeign.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baeldung.cloud.openfeign.client.JSONPlaceHolderClient;
|
||||
import com.baeldung.cloud.openfeign.model.Post;
|
||||
import com.baeldung.cloud.openfeign.service.JSONPlaceHolderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class JSONPlaceHolderServiceImpl implements JSONPlaceHolderService {
|
|
@ -1,3 +1,10 @@
|
|||
spring.application.name=openfeign
|
||||
user.api.url=http://localhost:8082/api/user
|
||||
feign.okhttp.enabled=true
|
||||
feign.okhttp.enabled=true
|
||||
|
||||
server.port=8085
|
||||
spring.main.allow-bean-definition-overriding=true
|
||||
logging.level.com.baeldung.cloud.openfeign.client=DEBUG
|
||||
feign.hystrix.enabled=true
|
||||
|
||||
spring.cloud.openfeign.client.config.postClient.url=https://jsonplaceholder.typicode.com/posts/
|
|
@ -1,17 +1,18 @@
|
|||
package com.baeldung.cloud.openfeign;
|
||||
|
||||
import com.baeldung.cloud.openfeign.model.Post;
|
||||
import com.baeldung.cloud.openfeign.service.JSONPlaceHolderService;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import com.baeldung.cloud.openfeign.model.Post;
|
||||
import com.baeldung.cloud.openfeign.service.JSONPlaceHolderService;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
|
@ -1,14 +1,9 @@
|
|||
### Relevant Articles:
|
||||
|
||||
- [Introduction to Spring Cloud OpenFeign](https://www.baeldung.com/spring-cloud-openfeign)
|
||||
- [Differences Between Netflix Feign and OpenFeign](https://www.baeldung.com/netflix-feign-vs-openfeign)
|
||||
- [Differences Between Netflix Feign and Open.Feign](https://www.baeldung.com/netflix-feign-vs-openfeign)
|
||||
- [Provide an OAuth2 Token to a Feign Client](https://www.baeldung.com/spring-cloud-feign-oauth-token)
|
||||
- [Propagating Exceptions With OpenFeign and Spring](https://www.baeldung.com/spring-openfeign-propagate-exception)
|
||||
- [Feign Client Exception Handling](https://www.baeldung.com/java-feign-client-exception-handling)
|
||||
- [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)
|
||||
- [Post form-url-encoded Data with Spring Cloud Feign](https://www.baeldung.com/spring-cloud-post-form-url-encoded-data)
|
||||
- [Configuring Spring Cloud FeignClient URL](https://www.baeldung.com/spring-cloud-feignclient-url)
|
||||
|
|
|
@ -7,6 +7,4 @@ feign.hystrix.enabled=true
|
|||
spring.security.oauth2.client.registration.keycloak.authorization-grant-type=client_credentials
|
||||
spring.security.oauth2.client.registration.keycloak.client-id=payment-app
|
||||
spring.security.oauth2.client.registration.keycloak.client-secret=863e9de4-33d4-4471-b35e-f8d2434385bb
|
||||
spring.security.oauth2.client.provider.keycloak.token-uri=http://localhost:8083/auth/realms/master/protocol/openid-connect/token
|
||||
|
||||
spring.cloud.openfeign.client.config.postClient.url=https://jsonplaceholder.typicode.com/posts/
|
||||
spring.security.oauth2.client.provider.keycloak.token-uri=http://localhost:8083/auth/realms/master/protocol/openid-connect/token
|
Loading…
Reference in New Issue