View Javadoc
1   /*
2   * Copyright 2020-2026 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.bremersee.xml.test.app;
18  
19  import java.util.ServiceLoader;
20  import org.bremersee.xml.JaxbContextBuilder;
21  import org.bremersee.xml.JaxbContextDataProvider;
22  import org.bremersee.xml.http.codec.ReactiveJaxbDecoder;
23  import org.bremersee.xml.http.codec.ReactiveJaxbEncoder;
24  import org.springframework.boot.SpringBootConfiguration;
25  import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
26  //import org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration;
27  import org.springframework.context.annotation.ComponentScan;
28  import org.springframework.http.codec.ServerCodecConfigurer;
29  import org.springframework.web.reactive.config.EnableWebFlux;
30  import org.springframework.web.reactive.config.WebFluxConfigurer;
31  
32  /**
33   * The web configuration.
34   *
35   * @author Christian Bremer
36   */
37  @SpringBootConfiguration
38  @EnableAutoConfiguration // (exclude = {ReactiveSecurityAutoConfiguration.class})
39  @EnableWebFlux
40  @ComponentScan(basePackageClasses = {WebConfiguration.class})
41  public class WebConfiguration implements WebFluxConfigurer {
42  
43    private final JaxbContextBuilder jaxbContextBuilder;
44  
45    /**
46     * Instantiates a new web configuration.
47     */
48    public WebConfiguration() {
49      jaxbContextBuilder = JaxbContextBuilder
50          .newInstance()
51          .processAll(ServiceLoader.load(JaxbContextDataProvider.class));
52    }
53  
54    @Override
55    public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
56      configurer
57          .customCodecs()
58          .registerWithDefaultConfig(new ReactiveJaxbDecoder(jaxbContextBuilder));
59      configurer
60          .customCodecs()
61          .registerWithDefaultConfig(new ReactiveJaxbEncoder(jaxbContextBuilder));
62    }
63  
64  }