/
IntegrationControllerConfiguration.java
110 lines (102 loc) · 5.15 KB
/
IntegrationControllerConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.integration.controller.spring;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.gravitee.apim.core.integration.crud_service.IntegrationCrudService;
import io.gravitee.apim.core.user.crud_service.UserCrudService;
import io.gravitee.exchange.api.configuration.IdentifyConfiguration;
import io.gravitee.exchange.api.controller.ControllerCommandHandlersFactory;
import io.gravitee.exchange.api.controller.ExchangeController;
import io.gravitee.exchange.api.websocket.command.ExchangeSerDe;
import io.gravitee.exchange.controller.websocket.WebSocketExchangeController;
import io.gravitee.exchange.controller.websocket.auth.WebSocketControllerAuthentication;
import io.gravitee.integration.api.websocket.command.IntegrationExchangeSerDe;
import io.gravitee.integration.controller.command.IntegrationControllerCommandHandlerFactory;
import io.gravitee.integration.controller.websocket.auth.IntegrationWebsocketControllerAuthentication;
import io.gravitee.node.api.cache.CacheManager;
import io.gravitee.node.api.certificate.KeyStoreLoaderFactoryRegistry;
import io.gravitee.node.api.certificate.KeyStoreLoaderOptions;
import io.gravitee.node.api.certificate.TrustStoreLoaderOptions;
import io.gravitee.node.api.cluster.ClusterManager;
import io.gravitee.rest.api.service.TokenService;
import io.vertx.rxjava3.core.Vertx;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.Environment;
@Configuration
public class IntegrationControllerConfiguration {
@Bean("integrationWebsocketControllerAuthentication")
public IntegrationWebsocketControllerAuthentication integrationWebsocketControllerAuthentication(
final TokenService tokenService,
final UserCrudService userCrudService
) {
return new IntegrationWebsocketControllerAuthentication(tokenService, userCrudService);
}
@Bean("integrationExchangeSerDe")
public IntegrationExchangeSerDe integrationExchangeSerDe() {
return new IntegrationExchangeSerDe(objectMapper());
}
@Bean("integrationIdentifyConfiguration")
public IdentifyConfiguration integrationPrefixConfiguration(final Environment environment) {
return new IdentifyConfiguration(environment, "integration");
}
@Bean("integrationControllerCommandHandlerFactory")
public IntegrationControllerCommandHandlerFactory integrationControllerCommandHandlerFactory(
final IntegrationCrudService integrationCrudService
) {
return new IntegrationControllerCommandHandlerFactory(integrationCrudService);
}
@Bean("integrationExchangeController")
public ExchangeController integrationExchangeController(
final @Lazy ClusterManager clusterManager,
final @Lazy CacheManager cacheManager,
final Vertx vertx,
final KeyStoreLoaderFactoryRegistry<KeyStoreLoaderOptions> keyStoreLoaderFactoryRegistry,
final KeyStoreLoaderFactoryRegistry<TrustStoreLoaderOptions> trustStoreLoaderFactoryRegistry,
final @Qualifier("integrationIdentifyConfiguration") IdentifyConfiguration identifyConfiguration,
final @Qualifier(
"integrationWebsocketControllerAuthentication"
) WebSocketControllerAuthentication<?> integrationWebsocketControllerAuthentication,
final @Qualifier(
"integrationControllerCommandHandlerFactory"
) ControllerCommandHandlersFactory integrationControllerCommandHandlerFactory,
final @Qualifier("integrationExchangeSerDe") ExchangeSerDe integrationExchangeSerDe
) {
return new WebSocketExchangeController(
identifyConfiguration,
clusterManager,
cacheManager,
vertx,
keyStoreLoaderFactoryRegistry,
trustStoreLoaderFactoryRegistry,
integrationWebsocketControllerAuthentication,
integrationControllerCommandHandlerFactory,
integrationExchangeSerDe
);
}
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
mapper.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return mapper;
}
}