[PPN-211113] Implement spring config client
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.processor.configuration.factory;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.reactive.function.client.ClientRequest;
|
||||
import org.springframework.web.reactive.function.client.ClientResponse;
|
||||
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* WebClientFilterFactory
|
||||
*
|
||||
* @author Shin Woo-jin (woozu.shin@kakaoent.com)
|
||||
* @since 2021-09-07
|
||||
*/
|
||||
@Slf4j
|
||||
public final class WebClientFilterFactory {
|
||||
|
||||
private WebClientFilterFactory() {}
|
||||
|
||||
public static ExchangeFilterFunction logRequest() {
|
||||
return ExchangeFilterFunction.ofRequestProcessor(WebClientFilterFactory::writeRequest);
|
||||
}
|
||||
|
||||
public static ExchangeFilterFunction logResponse() {
|
||||
return ExchangeFilterFunction.ofResponseProcessor(WebClientFilterFactory::writeResponse);
|
||||
}
|
||||
|
||||
private static Mono<ClientRequest> writeRequest(ClientRequest clientRequest) {
|
||||
try {
|
||||
log.info("[WEBCLIENT REQUEST] uri : {} method : {} headers : {}",
|
||||
clientRequest.url(), clientRequest.method(), clientRequest.headers());
|
||||
} catch (Exception e) {
|
||||
log.error("[WEBCLIENT REQUEST] write request failed", e);
|
||||
}
|
||||
return Mono.just(clientRequest);
|
||||
}
|
||||
|
||||
private static Mono<ClientResponse> writeResponse(ClientResponse clientResponse) {
|
||||
try {
|
||||
log.info("[WEBCLIENT REQUEST] statusCode : {} headers : {}",
|
||||
clientResponse.rawStatusCode(), clientResponse.headers().asHttpHeaders());
|
||||
} catch (Exception e) {
|
||||
log.error("[WEBCLIENT RESPONSE] write response failed", e);
|
||||
}
|
||||
return Mono.just(clientResponse);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.processor.configuration.factory;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.util.ObjectMapperFactory;
|
||||
import org.springframework.http.codec.json.Jackson2JsonDecoder;
|
||||
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
import org.springframework.web.reactive.function.client.ExchangeStrategies;
|
||||
|
||||
/**
|
||||
* WebFluxExchangeStragiesFactory
|
||||
*
|
||||
* @author Shin Woo-jin (woozu.shin@kakaoent.com)
|
||||
* @since 2021-09-08
|
||||
*/
|
||||
public final class WebFluxExchangeStragiesFactory {
|
||||
|
||||
private WebFluxExchangeStragiesFactory() {}
|
||||
|
||||
public static ExchangeStrategies ofDefault() {
|
||||
final ObjectMapper mapper = ObjectMapperFactory.defaultMapper();
|
||||
return ExchangeStrategies.builder()
|
||||
.codecs(configurer -> {
|
||||
configurer.defaultCodecs().maxInMemorySize(-1);
|
||||
configurer.defaultCodecs()
|
||||
.jackson2JsonEncoder(new Jackson2JsonEncoder(mapper,
|
||||
MimeTypeUtils.APPLICATION_JSON));
|
||||
configurer.defaultCodecs()
|
||||
.jackson2JsonDecoder(new Jackson2JsonDecoder(mapper,
|
||||
MimeTypeUtils.APPLICATION_JSON));
|
||||
})
|
||||
.build();
|
||||
}
|
||||
public static ExchangeStrategies ofTextHtml() {
|
||||
final ObjectMapper mapper = ObjectMapperFactory.defaultMapper();
|
||||
return ExchangeStrategies.builder()
|
||||
.codecs(configurer -> {
|
||||
configurer.defaultCodecs().maxInMemorySize(-1);
|
||||
configurer.defaultCodecs()
|
||||
.jackson2JsonEncoder(new Jackson2JsonEncoder(mapper,
|
||||
MimeTypeUtils.TEXT_HTML));
|
||||
configurer.defaultCodecs()
|
||||
.jackson2JsonDecoder(new Jackson2JsonDecoder(mapper,
|
||||
MimeTypeUtils.TEXT_HTML));
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.processor.infrastructure.client;
|
||||
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.configuration.factory.WebClientFilterFactory;
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.configuration.factory.WebFluxExchangeStragiesFactory;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.webclient.factory.WebClientFilterFactory;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.webclient.factory.WebFluxExchangeStragiesFactory;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.code.PpomppuBoardName;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import org.springframework.web.reactive.function.client.WebClientRequestException;
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.processor.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser.Feature;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import java.io.IOException;
|
||||
import org.springframework.cache.support.NullValue;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* ObjectMapperFactory
|
||||
*
|
||||
* @author Shin Woo-jin (woozu.shin@kakaoent.com)
|
||||
* @since 2021-08-31
|
||||
*/
|
||||
public final class ObjectMapperFactory {
|
||||
|
||||
private ObjectMapperFactory() {
|
||||
}
|
||||
|
||||
private static final ObjectMapper defaultMapper;
|
||||
private static final ObjectMapper httpMapper;
|
||||
|
||||
static {
|
||||
defaultMapper = initDefaultMapper();
|
||||
httpMapper = initHttpMapper();
|
||||
}
|
||||
|
||||
public static ObjectMapper defaultMapper() {
|
||||
return defaultMapper;
|
||||
}
|
||||
|
||||
public static ObjectMapper httpMapper() {
|
||||
return httpMapper;
|
||||
}
|
||||
|
||||
private static ObjectMapper initDefaultMapper() {
|
||||
final ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
|
||||
objectMapper.disable(SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS);
|
||||
objectMapper.enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL);
|
||||
objectMapper.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
|
||||
objectMapper.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
|
||||
objectMapper.registerModule(new JavaTimeModule());
|
||||
return objectMapper;
|
||||
}
|
||||
|
||||
private static ObjectMapper initHttpMapper() {
|
||||
final ObjectMapper objectMapper = initDefaultMapper();
|
||||
objectMapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE, true);
|
||||
return objectMapper;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy from {@link GenericJackson2JsonRedisSerializer.NullValueSerializer}.
|
||||
*/
|
||||
public static class NullValueSerializer extends StdSerializer<NullValue> {
|
||||
|
||||
private static final long serialVersionUID = 6776419544239897328L;
|
||||
private final String classIdentifier;
|
||||
|
||||
/**
|
||||
* @param classIdentifier can be {@literal null} and will be defaulted to {@code @class}.
|
||||
*/
|
||||
NullValueSerializer(String classIdentifier) {
|
||||
super(NullValue.class);
|
||||
this.classIdentifier = StringUtils.hasText(classIdentifier) ? classIdentifier : "@class";
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.fasterxml.jackson.databind.ser.std.StdSerializer#serialize(java.lang.Object, com
|
||||
* .fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.databind.SerializerProvider)
|
||||
*/
|
||||
@Override
|
||||
public void serialize(NullValue value, JsonGenerator jgen, SerializerProvider provider)
|
||||
throws IOException {
|
||||
|
||||
jgen.writeStartObject();
|
||||
jgen.writeStringField(classIdentifier, NullValue.class.getName());
|
||||
jgen.writeEndObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,12 @@ spring:
|
||||
activate:
|
||||
on-profile: development
|
||||
import:
|
||||
- "configserver:http://192.168.0.100:11080"
|
||||
- classpath:/development/webclient.yml
|
||||
- classpath:/development/temppassword.yml
|
||||
- classpath:/development/database.yml
|
||||
- classpath:/development/database.yml
|
||||
profiles:
|
||||
group:
|
||||
development: development, datasource-development
|
||||
|
||||
# import: optional:configserver:http://localhost:11080 # can be start up even config server was not found.
|
||||
@@ -1,4 +1,6 @@
|
||||
spring:
|
||||
application:
|
||||
name: ppn-processor
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
profiles:
|
||||
@@ -12,3 +14,9 @@ server:
|
||||
error:
|
||||
whitelabel:
|
||||
enabled: false
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: refresh
|
||||
|
||||
Reference in New Issue
Block a user