-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
1,799 additions
and
1,706 deletions.
There are no files selected for viewing
20 changes: 11 additions & 9 deletions
20
src/main/java/bitwheeze/golos/goloslib/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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package bitwheeze.golos.goloslib; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "golos") | ||
public class ApplicationProperties { | ||
String api; | ||
|
||
} | ||
package bitwheeze.golos.goloslib; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@ConfigurationProperties(prefix = "golos") | ||
public class ApplicationProperties { | ||
String api; | ||
|
||
} |
136 changes: 68 additions & 68 deletions
136
src/main/java/bitwheeze/golos/goloslib/GolosApiConfiguration.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 |
---|---|---|
@@ -1,68 +1,68 @@ | ||
package bitwheeze.golos.goloslib; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.client.reactive.ReactorClientHttpConnector; | ||
import org.springframework.http.codec.LoggingCodecSupport; | ||
import org.springframework.http.codec.json.Jackson2JsonDecoder; | ||
import org.springframework.http.codec.json.Jackson2JsonEncoder; | ||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; | ||
import org.springframework.web.reactive.function.client.ExchangeStrategies; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.netty.http.client.HttpClient; | ||
|
||
import java.util.Collections; | ||
|
||
@Slf4j | ||
@Configuration | ||
public class GolosApiConfiguration { | ||
|
||
@Value("${golos.api:https://api-golos.blckchnd.com}") | ||
private String url; | ||
|
||
@Value("${golos.media-type:application/json}") | ||
private String mediaType; | ||
|
||
@Bean(name = "golos_api") | ||
public WebClient buildWebClient(ObjectMapper mapper) { | ||
ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder() | ||
.codecs(clientDefaultCodecsConfigurer -> { | ||
clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(mapper, MediaType.APPLICATION_JSON)); | ||
clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonDecoder(new Jackson2JsonDecoder(mapper, MediaType.valueOf(mediaType))); | ||
}) | ||
.build(); | ||
|
||
exchangeStrategies | ||
.messageWriters().stream() | ||
.filter(LoggingCodecSupport.class::isInstance) | ||
.forEach(writer -> ((LoggingCodecSupport)writer).setEnableLoggingRequestDetails(true)); | ||
|
||
log.info("using api url {}", url); | ||
return WebClient.builder() | ||
.baseUrl(url) | ||
//.defaultCookie("cookieKey", "cookieValue") | ||
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) | ||
.defaultUriVariables(Collections.singletonMap("url", url)) | ||
.exchangeStrategies(exchangeStrategies) | ||
.clientConnector(new ReactorClientHttpConnector( | ||
HttpClient.create().wiretap(true) | ||
)) | ||
.build(); | ||
} | ||
|
||
@Primary | ||
@Bean | ||
public ObjectMapper buildObjectMapper(Jackson2ObjectMapperBuilder builder) { | ||
var mapper = builder.build(); | ||
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); | ||
return mapper; | ||
} | ||
|
||
} | ||
package bitwheeze.golos.goloslib; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.client.reactive.ReactorClientHttpConnector; | ||
import org.springframework.http.codec.LoggingCodecSupport; | ||
import org.springframework.http.codec.json.Jackson2JsonDecoder; | ||
import org.springframework.http.codec.json.Jackson2JsonEncoder; | ||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; | ||
import org.springframework.web.reactive.function.client.ExchangeStrategies; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.netty.http.client.HttpClient; | ||
|
||
import java.util.Collections; | ||
|
||
@Slf4j | ||
@Configuration | ||
public class GolosApiConfiguration { | ||
|
||
@Value("${golos.api:https://api-golos.blckchnd.com}") | ||
private String url; | ||
|
||
@Value("${golos.media-type:application/json}") | ||
private String mediaType; | ||
|
||
@Bean(name = "golos_api") | ||
public WebClient buildWebClient(ObjectMapper mapper) { | ||
ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder() | ||
.codecs(clientDefaultCodecsConfigurer -> { | ||
clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(mapper, MediaType.APPLICATION_JSON)); | ||
clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonDecoder(new Jackson2JsonDecoder(mapper, MediaType.valueOf(mediaType))); | ||
}) | ||
.build(); | ||
|
||
exchangeStrategies | ||
.messageWriters().stream() | ||
.filter(LoggingCodecSupport.class::isInstance) | ||
.forEach(writer -> ((LoggingCodecSupport)writer).setEnableLoggingRequestDetails(true)); | ||
|
||
log.info("using api url {}", url); | ||
return WebClient.builder() | ||
.baseUrl(url) | ||
//.defaultCookie("cookieKey", "cookieValue") | ||
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) | ||
.defaultUriVariables(Collections.singletonMap("url", url)) | ||
.exchangeStrategies(exchangeStrategies) | ||
.clientConnector(new ReactorClientHttpConnector( | ||
HttpClient.create().wiretap(true) | ||
)) | ||
.build(); | ||
} | ||
|
||
@Primary | ||
@Bean | ||
public ObjectMapper buildObjectMapper(Jackson2ObjectMapperBuilder builder) { | ||
var mapper = builder.build(); | ||
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); | ||
return mapper; | ||
} | ||
|
||
} |
8 changes: 4 additions & 4 deletions
8
src/main/java/bitwheeze/golos/goloslib/GolosApiProperties.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package bitwheeze.golos.goloslib; | ||
|
||
public class GolosApiProperties { | ||
} | ||
package bitwheeze.golos.goloslib; | ||
|
||
public class GolosApiProperties { | ||
} |
Oops, something went wrong.