WebConfig.java

1
package org.cardanofoundation.explorer.api.config;
2
3
import java.time.Duration;
4
import java.util.List;
5
import java.util.concurrent.TimeUnit;
6
import java.util.stream.Collectors;
7
8
import lombok.RequiredArgsConstructor;
9
import lombok.extern.log4j.Log4j2;
10
11
import org.springframework.context.annotation.Bean;
12
import org.springframework.context.annotation.Configuration;
13
import org.springframework.http.HttpHeaders;
14
import org.springframework.http.MediaType;
15
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
16
import org.springframework.web.client.RestTemplate;
17
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
18
import org.springframework.web.reactive.function.client.WebClient;
19
import org.springframework.web.servlet.config.annotation.CorsRegistry;
20
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
21
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
22
23
import io.netty.channel.ChannelOption;
24
import io.netty.handler.timeout.ReadTimeoutHandler;
25
import io.netty.handler.timeout.WriteTimeoutHandler;
26
import reactor.netty.http.client.HttpClient;
27
28
import org.cardanofoundation.explorer.api.interceptor.AuthInterceptor;
29
import org.cardanofoundation.explorer.api.interceptor.auth.Request;
30
import org.cardanofoundation.explorer.api.interceptor.auth.RoleFilterMapper;
31
import org.cardanofoundation.explorer.common.validation.date.param.DateValidArgumentResolver;
32
33
@Configuration
34
@Log4j2
35
@RequiredArgsConstructor
36
public class WebConfig implements WebMvcConfigurer {
37
38
  private final AuthInterceptor authInterceptor;
39
  private final RoleFilterMapper roleConf;
40
  private static final int TIMEOUT = 10000;
41
  private static final int READ_TIMEOUT = 10000;
42
  private static final int WRITE_TIMEOUT = 10000;
43
44
  @Override
45
  public void addCorsMappings(CorsRegistry registry) {
46
    registry
47
        .addMapping("/**")
48
        .allowedOrigins("*")
49
        .allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "HEAD");
50
  }
51
52
  @Bean
53
  public RestTemplate getRestTemplate() {
54 1 1. getRestTemplate : replaced return value with null for org/cardanofoundation/explorer/api/config/WebConfig::getRestTemplate → SURVIVED
    return new RestTemplate();
55
  }
56
57
  @Override
58
  public void addInterceptors(InterceptorRegistry registry) {
59
    log.info("Authentication interceptor is adding to the service");
60
    registry
61
        .addInterceptor(authInterceptor)
62
        .addPathPatterns(
63
            roleConf.getAuth().stream().map(Request::getUri).collect(Collectors.toList()));
64
  }
65
66
  @Bean
67
  public DateValidArgumentResolver getDateValidArgumentResolver() {
68 1 1. getDateValidArgumentResolver : replaced return value with null for org/cardanofoundation/explorer/api/config/WebConfig::getDateValidArgumentResolver → SURVIVED
    return new DateValidArgumentResolver();
69
  }
70
71
  @Override
72
  public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
73
    resolvers.add(this.getDateValidArgumentResolver());
74
  }
75
76
  @Bean
77
  public WebClient getWebClient() {
78
    HttpClient httpClient =
79
        HttpClient.create()
80
            .wiretap(Boolean.FALSE)
81
            .followRedirect(Boolean.TRUE)
82
            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, TIMEOUT)
83
            .responseTimeout(Duration.ofMillis(TIMEOUT))
84
            .doOnConnected(
85
                connection -> {
86
                  connection.addHandlerFirst(
87
                      new ReadTimeoutHandler(READ_TIMEOUT, TimeUnit.MILLISECONDS));
88
                  connection.addHandlerFirst(
89
                      new WriteTimeoutHandler(WRITE_TIMEOUT, TimeUnit.MILLISECONDS));
90
                });
91
92 1 1. getWebClient : replaced return value with null for org/cardanofoundation/explorer/api/config/WebConfig::getWebClient → SURVIVED
    return WebClient.builder()
93
        .clientConnector(new ReactorClientHttpConnector(httpClient))
94
        .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
95
        .build();
96
  }
97
}

Mutations

54

1.1
Location : getRestTemplate
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/config/WebConfig::getRestTemplate → SURVIVED

68

1.1
Location : getDateValidArgumentResolver
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/config/WebConfig::getDateValidArgumentResolver → SURVIVED

92

1.1
Location : getWebClient
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/config/WebConfig::getWebClient → SURVIVED

Active mutators

Tests examined


Report generated by PIT 1.14.2