fix logging request
This commit is contained in:
parent
e99d83fb4f
commit
c7a752120d
10 changed files with 119 additions and 19 deletions
|
|
@ -22,6 +22,7 @@ public class LoggingInterceptor implements ClientHttpRequestInterceptor {
|
||||||
|
|
||||||
log.info("Request URI: " + request.getURI());
|
log.info("Request URI: " + request.getURI());
|
||||||
log.info("Request method: " + request.getMethod());
|
log.info("Request method: " + request.getMethod());
|
||||||
|
log.info("Request headers: " + request.getHeaders());
|
||||||
log.info("Request body: " + new String(body, "UTF-8"));
|
log.info("Request body: " + new String(body, "UTF-8"));
|
||||||
|
|
||||||
ClientHttpResponse response = execution.execute(request, body);
|
ClientHttpResponse response = execution.execute(request, body);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
package ru.spcex.clearing.gatewayapi.config;
|
package ru.spcex.clearing.gatewayapi.config;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.filter.CommonsRequestLoggingFilter;
|
|
||||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||||
|
|
@ -12,16 +10,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
@EnableWebMvc
|
@EnableWebMvc
|
||||||
public class WebConfig implements WebMvcConfigurer {
|
public class WebConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
@Bean
|
|
||||||
public CommonsRequestLoggingFilter loggingFilter() {
|
|
||||||
CommonsRequestLoggingFilter filter = new CommonsRequestLoggingFilter();
|
|
||||||
filter.setIncludePayload(true);
|
|
||||||
filter.setIncludeQueryString(true);
|
|
||||||
filter.setMaxPayloadLength(1000000000);
|
|
||||||
filter.setAfterMessagePrefix("Income request data: ");
|
|
||||||
return filter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
registry.addResourceHandler("swagger-ui.html")
|
registry.addResourceHandler("swagger-ui.html")
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import java.time.Instant;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
public class InstantDeserializer extends JsonDeserializer<Instant> {
|
public class InstantDeserializer extends JsonDeserializer<Instant> {
|
||||||
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss:SSS");
|
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Instant deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
public Instant deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package ru.spcex.clearing.gatewayapi.config.filters;
|
||||||
|
|
||||||
|
import org.springframework.util.StreamUtils;
|
||||||
|
|
||||||
|
import javax.servlet.ServletInputStream;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletRequestWrapper;
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
public class CachedHttpServletRequest extends HttpServletRequestWrapper {
|
||||||
|
|
||||||
|
private byte[] cachedPayload;
|
||||||
|
|
||||||
|
public CachedHttpServletRequest(HttpServletRequest request) throws IOException {
|
||||||
|
super(request);
|
||||||
|
InputStream requestInputStream = request.getInputStream();
|
||||||
|
this.cachedPayload = StreamUtils.copyToByteArray(requestInputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServletInputStream getInputStream() {
|
||||||
|
return new CachedServletInputStream(this.cachedPayload);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BufferedReader getReader() {
|
||||||
|
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(this.cachedPayload);
|
||||||
|
return new BufferedReader(new InputStreamReader(byteArrayInputStream));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package ru.spcex.clearing.gatewayapi.config.filters;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import javax.servlet.ReadListener;
|
||||||
|
import javax.servlet.ServletInputStream;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public class CachedServletInputStream extends ServletInputStream {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
private InputStream cachedInputStream;
|
||||||
|
|
||||||
|
public CachedServletInputStream(byte[] cachedBody) {
|
||||||
|
this.cachedInputStream = new ByteArrayInputStream(cachedBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFinished() {
|
||||||
|
try {
|
||||||
|
return cachedInputStream.available() == 0;
|
||||||
|
} catch (IOException exp) {
|
||||||
|
log.error(exp.getMessage());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isReady() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setReadListener(ReadListener readListener) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read() throws IOException {
|
||||||
|
return cachedInputStream.read();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package ru.spcex.clearing.gatewayapi.config.filters;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.core.Ordered;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.StreamUtils;
|
||||||
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
|
||||||
|
import javax.servlet.FilterChain;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebFilter;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
@Order(value = Ordered.HIGHEST_PRECEDENCE)
|
||||||
|
@Component
|
||||||
|
@WebFilter(filterName = "RequestCachingFilter", urlPatterns = "/*")
|
||||||
|
public class RequestCachingFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
|
||||||
|
FilterChain filterChain) throws ServletException, IOException {
|
||||||
|
CachedHttpServletRequest cachedHttpServletRequest = new CachedHttpServletRequest(request);
|
||||||
|
log.info("REQUEST QUERY: " + request.getQueryString());
|
||||||
|
log.info("REQUEST DATA: " + StreamUtils.copyToString(cachedHttpServletRequest.getInputStream(), StandardCharsets.UTF_8));
|
||||||
|
filterChain.doFilter(cachedHttpServletRequest, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,7 +10,7 @@ import java.time.Instant;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
public class InstantSerializer extends JsonSerializer<Instant> {
|
public class InstantSerializer extends JsonSerializer<Instant> {
|
||||||
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss:SSS");
|
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(Instant value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
public void serialize(Instant value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ public class SendMessageToSecurityServiceWithFondSecurities extends Stage<FondLi
|
||||||
fixedIncomeSecurityNewRequest.setNominalValue(security.getNominalValue());
|
fixedIncomeSecurityNewRequest.setNominalValue(security.getNominalValue());
|
||||||
fixedIncomeSecurityNewRequest.setNominalCurrency(security.getNominalCurrency());
|
fixedIncomeSecurityNewRequest.setNominalCurrency(security.getNominalCurrency());
|
||||||
fixedIncomeSecurityNewRequest.setMaturityDate(security.getMaturityDate());
|
fixedIncomeSecurityNewRequest.setMaturityDate(security.getMaturityDate());
|
||||||
fixedIncomeSecurityNewRequest.setCouponFrequency(security.getCouponFrequency());
|
fixedIncomeSecurityNewRequest.setCouponFrequency(security.getCouponFrequency().longValue());
|
||||||
fixedIncomeSecurityNewRequest.setIssuerId(companyId);
|
fixedIncomeSecurityNewRequest.setIssuerId(companyId);
|
||||||
fixedIncomeSecurityNewRequest.setShortNameEng(security.getShortNameEng());
|
fixedIncomeSecurityNewRequest.setShortNameEng(security.getShortNameEng());
|
||||||
fixedIncomeSecurityNewRequest.setFullNameEng(security.getFullNameEng());
|
fixedIncomeSecurityNewRequest.setFullNameEng(security.getFullNameEng());
|
||||||
|
|
@ -112,7 +112,7 @@ public class SendMessageToSecurityServiceWithFondSecurities extends Stage<FondLi
|
||||||
fixedIncomeSecurityUpdateRequest.setNominalValue(security.getNominalValue());
|
fixedIncomeSecurityUpdateRequest.setNominalValue(security.getNominalValue());
|
||||||
fixedIncomeSecurityUpdateRequest.setNominalCurrency(security.getNominalCurrency());
|
fixedIncomeSecurityUpdateRequest.setNominalCurrency(security.getNominalCurrency());
|
||||||
fixedIncomeSecurityUpdateRequest.setMaturityDate(security.getMaturityDate());
|
fixedIncomeSecurityUpdateRequest.setMaturityDate(security.getMaturityDate());
|
||||||
fixedIncomeSecurityUpdateRequest.setCouponFrequency(security.getCouponFrequency());
|
fixedIncomeSecurityUpdateRequest.setCouponFrequency(security.getCouponFrequency().longValue());
|
||||||
fixedIncomeSecurityUpdateRequest.setIssuerId(companyId);
|
fixedIncomeSecurityUpdateRequest.setIssuerId(companyId);
|
||||||
fixedIncomeSecurityUpdateRequest.setShortNameEng(security.getShortNameEng());
|
fixedIncomeSecurityUpdateRequest.setShortNameEng(security.getShortNameEng());
|
||||||
fixedIncomeSecurityUpdateRequest.setFullNameEng(security.getFullNameEng());
|
fixedIncomeSecurityUpdateRequest.setFullNameEng(security.getFullNameEng());
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@ package ru.spcex.clearing.gatewayapi.request;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import ru.spcex.clearing.gatewayapi.config.deserializers.InstantDeserializer;
|
import ru.spcex.clearing.gatewayapi.config.deserializers.InstantDeserializer;
|
||||||
|
import ru.spcex.clearing.gatewayapi.config.serializers.InstantSerializer;
|
||||||
import ru.spcex.clearing.gatewayapi.errors.GatewayError;
|
import ru.spcex.clearing.gatewayapi.errors.GatewayError;
|
||||||
import ru.spcex.clearing.gatewayapi.exception.GatewayException;
|
import ru.spcex.clearing.gatewayapi.exception.GatewayException;
|
||||||
import ru.spcex.platform.enumeration.Section;
|
import ru.spcex.platform.enumeration.Section;
|
||||||
|
|
@ -38,6 +40,7 @@ public class CommonRequest {
|
||||||
|
|
||||||
@JsonProperty("datetime")
|
@JsonProperty("datetime")
|
||||||
@JsonDeserialize(using = InstantDeserializer.class)
|
@JsonDeserialize(using = InstantDeserializer.class)
|
||||||
|
@JsonSerialize(using = InstantSerializer.class)
|
||||||
@ApiModelProperty(
|
@ApiModelProperty(
|
||||||
value = "Передавать дату и время формирования JSON объекта в формате «ДД.ММ.ГГГГ ЧЧ:ММ:СС:ссс».",
|
value = "Передавать дату и время формирования JSON объекта в формате «ДД.ММ.ГГГГ ЧЧ:ММ:СС:ссс».",
|
||||||
example = "01.01.2023 12:34:56:789"
|
example = "01.01.2023 12:34:56:789"
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ public class FondSecurity extends WithMapId {
|
||||||
value = "Дополнительная информация\\Количество купонов в год",
|
value = "Дополнительная информация\\Количество купонов в год",
|
||||||
example = "1000"
|
example = "1000"
|
||||||
)
|
)
|
||||||
private Long couponFrequency;
|
private BigDecimal couponFrequency;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -327,11 +327,11 @@ public class FondSecurity extends WithMapId {
|
||||||
this.couponType = couponType;
|
this.couponType = couponType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getCouponFrequency() {
|
public BigDecimal getCouponFrequency() {
|
||||||
return couponFrequency;
|
return couponFrequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCouponFrequency(Long couponFrequency) {
|
public void setCouponFrequency(BigDecimal couponFrequency) {
|
||||||
this.couponFrequency = couponFrequency;
|
this.couponFrequency = couponFrequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue