1
|
package eu.dnetlib.repo.manager.config;
|
2
|
|
3
|
import org.apache.log4j.Logger;
|
4
|
import org.springframework.beans.factory.annotation.Value;
|
5
|
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
|
6
|
import org.springframework.context.annotation.*;
|
7
|
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
8
|
import org.springframework.http.HttpHeaders;
|
9
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
10
|
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
|
11
|
import org.springframework.session.web.http.CookieSerializer;
|
12
|
import org.springframework.session.web.http.DefaultCookieSerializer;
|
13
|
import org.springframework.web.client.RestTemplate;
|
14
|
|
15
|
import javax.annotation.PostConstruct;
|
16
|
|
17
|
@Configuration
|
18
|
@EnableRedisHttpSession
|
19
|
@EnableAspectJAutoProxy
|
20
|
@EnableCircuitBreaker
|
21
|
@PropertySource(value = {"classpath:application.properties"} )
|
22
|
@ComponentScan(basePackages = {
|
23
|
"org.eurocris.openaire.cris.validator.service",
|
24
|
"eu.dnetlib.repo.manager.*"})
|
25
|
public class RedisConfiguration {
|
26
|
|
27
|
private static Logger LOGGER = Logger.getLogger(RedisConfiguration.class);
|
28
|
|
29
|
@Value("${redis.host}")
|
30
|
private String host;
|
31
|
|
32
|
@Value("${redis.port:6379}")
|
33
|
private String port;
|
34
|
|
35
|
@Value("${redis.password}")
|
36
|
private String password;
|
37
|
|
38
|
@Value("${aai.mode}")
|
39
|
private String aai_mode;
|
40
|
|
41
|
@PostConstruct
|
42
|
private void init(){
|
43
|
LOGGER.info(String.format("Redis : %s Port : %s Password : %s",host,port,password));
|
44
|
}
|
45
|
|
46
|
@Bean
|
47
|
public JedisConnectionFactory connectionFactory() {
|
48
|
LOGGER.info(String.format("Redis : %s Port : %s Password : %s",host,port,password));
|
49
|
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
|
50
|
jedisConnectionFactory.setHostName(host);
|
51
|
jedisConnectionFactory.setPort(Integer.parseInt(port));
|
52
|
jedisConnectionFactory.setUsePool(true);
|
53
|
if(password != null) jedisConnectionFactory.setPassword(password);
|
54
|
return jedisConnectionFactory;
|
55
|
}
|
56
|
|
57
|
@Bean
|
58
|
public CookieSerializer cookieSerializer() {
|
59
|
DefaultCookieSerializer serializer = new DefaultCookieSerializer();
|
60
|
serializer.setCookieName("openAIRESession");
|
61
|
serializer.setCookiePath("/");
|
62
|
if(aai_mode.equalsIgnoreCase("production") || aai_mode.equalsIgnoreCase("beta"))
|
63
|
serializer.setDomainName(".openaire.eu");
|
64
|
// serializer.setDomainName(".athenarc.gr");
|
65
|
LOGGER.info("Serializer : " + serializer);
|
66
|
return serializer;
|
67
|
}
|
68
|
|
69
|
@Bean
|
70
|
public RestTemplate restTemplate() {
|
71
|
RestTemplate restTemplate = new RestTemplate();
|
72
|
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
73
|
HttpHeaders httpHeaders = new HttpHeaders();
|
74
|
httpHeaders.set("Content-Type", "application/json");
|
75
|
return restTemplate;
|
76
|
}
|
77
|
|
78
|
|
79
|
}
|