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