Open Kilda Java Documentation
WebConfig.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.northbound.config;
17 
21 import org.springframework.boot.web.client.RestTemplateBuilder;
22 import org.springframework.context.annotation.Bean;
23 import org.springframework.context.annotation.Configuration;
24 import org.springframework.context.annotation.PropertySource;
25 import org.springframework.http.MediaType;
26 import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
27 import org.springframework.web.client.RestTemplate;
28 import org.springframework.web.filter.OncePerRequestFilter;
29 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
30 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
31 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
32 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
33 
34 import java.util.Collections;
35 
39 @Configuration
40 @EnableWebMvc
41 @PropertySource({"classpath:northbound.properties"})
42 public class WebConfig extends WebMvcConfigurerAdapter {
46  @Override
47  public void addInterceptors(InterceptorRegistry registry) {
48  registry.addInterceptor(timeExecutionInterceptor());
49  registry.addInterceptor(extraAuthInterceptor());
50  }
51 
57  @Bean
59  return new ExecutionTimeInterceptor();
60  }
61 
62  @Bean
64  return new ExtraAuthInterceptor();
65  }
66 
70  @Bean
71  public RestTemplate restTemplate(RestTemplateBuilder builder) {
72  RestTemplate restTemplate = builder.build();
73  MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
74  converter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
75  restTemplate.getMessageConverters().add(converter);
76 
77  return restTemplate;
78  }
79 
85  @Override
86  public void addResourceHandlers(ResourceHandlerRegistry registry) {
87  registry.addResourceHandler("swagger-ui.html")
88  .addResourceLocations("classpath:/META-INF/resources/");
89  registry.addResourceHandler("/webjars/**")
90  .addResourceLocations("classpath:/META-INF/resources/webjars/");
91  }
92 
93  @Bean
94  public OncePerRequestFilter requestCorrelationIdFilter() {
95  return new RequestCorrelationFilter();
96  }
97 }
ExecutionTimeInterceptor timeExecutionInterceptor()
Definition: WebConfig.java:58
void addInterceptors(InterceptorRegistry registry)
Definition: WebConfig.java:47
ExtraAuthInterceptor extraAuthInterceptor()
Definition: WebConfig.java:63
OncePerRequestFilter requestCorrelationIdFilter()
Definition: WebConfig.java:94
RestTemplate restTemplate(RestTemplateBuilder builder)
Definition: WebConfig.java:71
void addResourceHandlers(ResourceHandlerRegistry registry)
Definition: WebConfig.java:86