Containerization feature of SO
[so.git] / adapters / mso-sdnc-adapter / src / main / java / org / onap / so / adapters / sdnc / CXFConfiguration.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapters.sdnc;
22
23 import java.util.Arrays;
24
25 import javax.xml.ws.Endpoint;
26
27 import org.apache.cxf.Bus;
28 import org.apache.cxf.endpoint.Server;
29 import org.apache.cxf.feature.LoggingFeature;
30 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
31 import org.apache.cxf.jaxrs.swagger.Swagger2Feature;
32 import org.apache.cxf.jaxws.EndpointImpl;
33 import org.apache.cxf.transport.servlet.CXFServlet;
34 import org.onap.so.adapters.sdnc.sdncrest.SNIROResponse;
35 import org.onap.so.logger.MsoLogger;
36 import org.onap.so.logging.jaxrs.filter.jersey.JaxRsFilterLogging;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.boot.web.servlet.ServletRegistrationBean;
39 import org.springframework.context.annotation.Bean;
40 import org.springframework.context.annotation.Configuration;
41
42 import com.fasterxml.jackson.databind.DeserializationFeature;
43 import com.fasterxml.jackson.databind.ObjectMapper;
44 import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
45
46
47 @Configuration("CXFConfiguration")
48 public class CXFConfiguration {
49     
50         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL,CXFConfiguration.class);
51         
52         JAXRSServerFactoryBean endpoint;
53         
54     @Autowired
55     private Bus bus;
56     
57         @Autowired
58         private JaxRsFilterLogging jaxRsFilterLogging;
59         
60         @Autowired
61         private SDNCAdapterPortType sdncAdapterPortImpl;
62         
63         @Autowired 
64         private SNIROResponse sniroResponse;
65
66     
67         @Autowired
68         private ObjectMapper mapper;
69     @Bean
70     public Server rsServer() {
71         endpoint = new JAXRSServerFactoryBean();
72         mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
73         endpoint.setBus(bus);
74         endpoint.setServiceBeans(Arrays.<Object>asList(sniroResponse));
75         endpoint.setAddress("/rest");
76         endpoint.setFeatures(Arrays.asList(createSwaggerFeature(), new LoggingFeature()));
77         endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(mapper),jaxRsFilterLogging));
78         return endpoint.create();
79     }
80
81     @Bean
82     public ServletRegistrationBean cxfServlet() {
83         return new ServletRegistrationBean(new CXFServlet(), "/adapters/*");
84     }
85
86     @Bean
87     public Endpoint sndcAdapter() {
88         EndpointImpl endpoint = new EndpointImpl(bus, sdncAdapterPortImpl);
89         endpoint.publish("/SDNCAdapter");
90         return endpoint;
91     }
92
93
94     @Bean
95     public Swagger2Feature createSwaggerFeature() {
96         Swagger2Feature swagger2Feature= new Swagger2Feature();
97         swagger2Feature.setBasePath("/services/rest");
98         swagger2Feature.setPrettyPrint(true);
99         swagger2Feature.setTitle("SO Orchestration Application");
100         swagger2Feature.setContact("The ONAP SO team");
101         swagger2Feature.setDescription("This project is the SO Orchestration Engine");
102         swagger2Feature.setVersion("1.0.0");
103         swagger2Feature.setResourcePackage("org.onap.so.adapters.sdnc");
104         swagger2Feature.setScan(true);
105         return swagger2Feature;
106     }
107 }