-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : optimizing REST client configurations using RestClientCustomiz…
…er (#1178) * feat : set RestClient using RestClientCustomizer * create restclient bean * feat : externalize configuration URL * enchance WebMVC Config * fix : issue with configuring WebMVC * fix : issue with reading configurationProperties * adds proxy beans * ReOrder Beans
- Loading branch information
1 parent
7d94c44
commit eb3b605
Showing
10 changed files
with
129 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...client/src/main/java/com/example/restclient/bootrestclient/BootRestClientApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...ent/src/main/java/com/example/restclient/bootrestclient/config/ApplicationProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.example.restclient.bootrestclient.config; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.NestedConfigurationProperty; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
@Getter | ||
@Setter | ||
@Validated | ||
@ConfigurationProperties("application") | ||
public class ApplicationProperties { | ||
|
||
@NotBlank(message = "External Call URL cant be Blank") | ||
private String externalCallUrl; | ||
|
||
@NestedConfigurationProperty private Cors cors = new Cors(); | ||
|
||
@Getter | ||
@Setter | ||
public static class Cors { | ||
private String pathPattern = "/api/**"; | ||
private String allowedMethods = "*"; | ||
private String allowedHeaders = "*"; | ||
private String allowedOriginPatterns = "*"; | ||
private boolean allowCredentials = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...-restclient/src/main/java/com/example/restclient/bootrestclient/config/SwaggerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.example.restclient.bootrestclient.config; | ||
|
||
import io.swagger.v3.oas.annotations.OpenAPIDefinition; | ||
import io.swagger.v3.oas.annotations.info.Info; | ||
import io.swagger.v3.oas.annotations.servers.Server; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@OpenAPIDefinition( | ||
info = @Info(title = "rest-client", version = "v1"), | ||
servers = @Server(url = "/")) | ||
public class SwaggerConfig {} |
24 changes: 24 additions & 0 deletions
24
...t-restclient/src/main/java/com/example/restclient/bootrestclient/config/WebMvcConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.example.restclient.bootrestclient.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.lang.NonNull; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@RequiredArgsConstructor | ||
public class WebMvcConfig implements WebMvcConfigurer { | ||
|
||
private final ApplicationProperties properties; | ||
|
||
@Override | ||
public void addCorsMappings(@NonNull CorsRegistry registry) { | ||
ApplicationProperties.Cors propertiesCors = properties.getCors(); | ||
registry.addMapping(propertiesCors.getPathPattern()) | ||
.allowedMethods(propertiesCors.getAllowedMethods()) | ||
.allowedHeaders(propertiesCors.getAllowedHeaders()) | ||
.allowedOriginPatterns(propertiesCors.getAllowedOriginPatterns()) | ||
.allowCredentials(propertiesCors.isAllowCredentials()); | ||
} | ||
} |
6 changes: 4 additions & 2 deletions
6
httpClients/boot-restclient/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
spring.application.name=boot-restclient | ||
|
||
spring.mvc.problemdetails.enabled=true | ||
spring.threads.virtual.enabled=true | ||
spring.mvc.problemdetails.enabled=true | ||
spring.threads.virtual.enabled=true | ||
|
||
application.external-call-url=https://jsonplaceholder.typicode.com |