|
46 | 46 | */
|
47 | 47 | @Configuration
|
48 | 48 | public class MongoHttpSessionConfiguration extends SpringHttpSessionConfiguration
|
49 |
| - implements BeanClassLoaderAware, EmbeddedValueResolverAware, ImportAware { |
50 |
| - |
51 |
| - private AbstractMongoSessionConverter mongoSessionConverter; |
52 |
| - private Integer maxInactiveIntervalInSeconds; |
53 |
| - private String collectionName; |
54 |
| - private StringValueResolver embeddedValueResolver; |
55 |
| - private ClassLoader classLoader; |
56 |
| - private MongoOperations mongoOperations; |
57 |
| - |
58 |
| - @Autowired |
59 |
| - public void setMongoOperations( |
60 |
| - @SpringSessionMongoOperations ObjectProvider<MongoOperations> springSessionMongoOperations, |
61 |
| - ObjectProvider<MongoOperations> mongoOperations) { |
62 |
| - MongoOperations mongoOperationsToUse = springSessionMongoOperations.getIfAvailable(); |
63 |
| - if (mongoOperationsToUse == null) { |
64 |
| - mongoOperationsToUse = mongoOperations.getObject(); |
65 |
| - } |
66 |
| - this.mongoOperations = mongoOperationsToUse; |
67 |
| - } |
68 |
| - |
69 |
| - @Bean |
70 |
| - public MongoOperationsSessionRepository mongoSessionRepository() { |
71 |
| - |
72 |
| - MongoOperationsSessionRepository repository = new MongoOperationsSessionRepository(mongoOperations); |
73 |
| - repository.setMaxInactiveIntervalInSeconds(this.maxInactiveIntervalInSeconds); |
74 |
| - |
75 |
| - if (this.mongoSessionConverter != null) { |
76 |
| - repository.setMongoSessionConverter(this.mongoSessionConverter); |
77 |
| - } else { |
78 |
| - JdkMongoSessionConverter mongoSessionConverter = new JdkMongoSessionConverter(new SerializingConverter(), |
79 |
| - new DeserializingConverter(this.classLoader), |
80 |
| - Duration.ofSeconds(MongoOperationsSessionRepository.DEFAULT_INACTIVE_INTERVAL)); |
81 |
| - repository.setMongoSessionConverter(mongoSessionConverter); |
82 |
| - } |
83 |
| - |
84 |
| - if (StringUtils.hasText(this.collectionName)) { |
85 |
| - repository.setCollectionName(this.collectionName); |
86 |
| - } |
87 |
| - |
88 |
| - return repository; |
89 |
| - } |
90 |
| - |
91 |
| - public void setCollectionName(String collectionName) { |
92 |
| - this.collectionName = collectionName; |
93 |
| - } |
94 |
| - |
95 |
| - public void setMaxInactiveIntervalInSeconds(Integer maxInactiveIntervalInSeconds) { |
96 |
| - this.maxInactiveIntervalInSeconds = maxInactiveIntervalInSeconds; |
97 |
| - } |
98 |
| - |
99 |
| - public void setImportMetadata(AnnotationMetadata importMetadata) { |
100 |
| - |
101 |
| - AnnotationAttributes attributes = AnnotationAttributes |
102 |
| - .fromMap(importMetadata.getAnnotationAttributes(EnableMongoHttpSession.class.getName())); |
103 |
| - |
104 |
| - if (attributes != null) { |
105 |
| - this.maxInactiveIntervalInSeconds = attributes.getNumber("maxInactiveIntervalInSeconds"); |
106 |
| - } else { |
107 |
| - this.maxInactiveIntervalInSeconds = MongoOperationsSessionRepository.DEFAULT_INACTIVE_INTERVAL; |
108 |
| - } |
109 |
| - |
110 |
| - String collectionNameValue = attributes != null ? attributes.getString("collectionName") : ""; |
111 |
| - if (StringUtils.hasText(collectionNameValue)) { |
112 |
| - this.collectionName = this.embeddedValueResolver.resolveStringValue(collectionNameValue); |
113 |
| - } |
114 |
| - } |
115 |
| - |
116 |
| - @Autowired(required = false) |
117 |
| - public void setMongoSessionConverter(AbstractMongoSessionConverter mongoSessionConverter) { |
118 |
| - this.mongoSessionConverter = mongoSessionConverter; |
119 |
| - } |
120 |
| - |
121 |
| - @Override |
122 |
| - public void setBeanClassLoader(ClassLoader classLoader) { |
123 |
| - this.classLoader = classLoader; |
124 |
| - } |
125 |
| - |
126 |
| - @Override |
127 |
| - public void setEmbeddedValueResolver(StringValueResolver resolver) { |
128 |
| - this.embeddedValueResolver = resolver; |
129 |
| - } |
| 49 | + implements BeanClassLoaderAware, EmbeddedValueResolverAware, ImportAware { |
| 50 | + |
| 51 | + private AbstractMongoSessionConverter mongoSessionConverter; |
| 52 | + private Integer maxInactiveIntervalInSeconds; |
| 53 | + private String collectionName; |
| 54 | + private StringValueResolver embeddedValueResolver; |
| 55 | + private ClassLoader classLoader; |
| 56 | + private MongoOperations mongoOperations; |
| 57 | + |
| 58 | + @Autowired |
| 59 | + public void setMongoOperations( |
| 60 | + @SpringSessionMongoOperations ObjectProvider<MongoOperations> springSessionMongoOperations, |
| 61 | + ObjectProvider<MongoOperations> mongoOperations) { |
| 62 | + MongoOperations mongoOperationsToUse = springSessionMongoOperations.getIfAvailable(); |
| 63 | + if (mongoOperationsToUse == null) { |
| 64 | + mongoOperationsToUse = mongoOperations.getObject(); |
| 65 | + } |
| 66 | + this.mongoOperations = mongoOperationsToUse; |
| 67 | + } |
| 68 | + |
| 69 | + @Bean |
| 70 | + public MongoOperationsSessionRepository mongoSessionRepository() { |
| 71 | + |
| 72 | + MongoOperationsSessionRepository repository = new MongoOperationsSessionRepository(mongoOperations); |
| 73 | + repository.setMaxInactiveIntervalInSeconds(this.maxInactiveIntervalInSeconds); |
| 74 | + |
| 75 | + if (this.mongoSessionConverter != null) { |
| 76 | + repository.setMongoSessionConverter(this.mongoSessionConverter); |
| 77 | + } else { |
| 78 | + JdkMongoSessionConverter mongoSessionConverter = new JdkMongoSessionConverter(new SerializingConverter(), |
| 79 | + new DeserializingConverter(this.classLoader), |
| 80 | + Duration.ofSeconds(MongoOperationsSessionRepository.DEFAULT_INACTIVE_INTERVAL)); |
| 81 | + repository.setMongoSessionConverter(mongoSessionConverter); |
| 82 | + } |
| 83 | + |
| 84 | + if (StringUtils.hasText(this.collectionName)) { |
| 85 | + repository.setCollectionName(this.collectionName); |
| 86 | + } |
| 87 | + |
| 88 | + return repository; |
| 89 | + } |
| 90 | + |
| 91 | + public void setCollectionName(String collectionName) { |
| 92 | + this.collectionName = collectionName; |
| 93 | + } |
| 94 | + |
| 95 | + public void setMaxInactiveIntervalInSeconds(Integer maxInactiveIntervalInSeconds) { |
| 96 | + this.maxInactiveIntervalInSeconds = maxInactiveIntervalInSeconds; |
| 97 | + } |
| 98 | + |
| 99 | + public void setImportMetadata(AnnotationMetadata importMetadata) { |
| 100 | + |
| 101 | + AnnotationAttributes attributes = AnnotationAttributes.fromMap( |
| 102 | + importMetadata.getAnnotationAttributes(EnableMongoHttpSession.class.getName())); |
| 103 | + |
| 104 | + if (attributes != null) { |
| 105 | + this.maxInactiveIntervalInSeconds = attributes.getNumber("maxInactiveIntervalInSeconds"); |
| 106 | + } else { |
| 107 | + this.maxInactiveIntervalInSeconds = MongoOperationsSessionRepository.DEFAULT_INACTIVE_INTERVAL; |
| 108 | + } |
| 109 | + |
| 110 | + String collectionNameValue = attributes != null ? attributes.getString("collectionName") : ""; |
| 111 | + if (StringUtils.hasText(collectionNameValue)) { |
| 112 | + this.collectionName = this.embeddedValueResolver.resolveStringValue(collectionNameValue); |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + @Autowired(required = false) |
| 117 | + public void setMongoSessionConverter(AbstractMongoSessionConverter mongoSessionConverter) { |
| 118 | + this.mongoSessionConverter = mongoSessionConverter; |
| 119 | + } |
| 120 | + |
| 121 | + @Override |
| 122 | + public void setBeanClassLoader(ClassLoader classLoader) { |
| 123 | + this.classLoader = classLoader; |
| 124 | + } |
| 125 | + |
| 126 | + @Override |
| 127 | + public void setEmbeddedValueResolver(StringValueResolver resolver) { |
| 128 | + this.embeddedValueResolver = resolver; |
| 129 | + } |
130 | 130 |
|
131 | 131 | }
|
0 commit comments