2c84ed4fd0c4b63f364278701ae0213bbdaeab91
[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.logging.cxf.interceptor.SOAPLoggingInInterceptor;
36 import org.onap.so.logging.cxf.interceptor.SOAPLoggingOutInterceptor;
37 import org.onap.so.logging.jaxrs.filter.JaxRsFilterLogging;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.boot.web.servlet.ServletRegistrationBean;
40 import org.springframework.context.annotation.Bean;
41 import org.springframework.context.annotation.Configuration;
42
43 import com.fasterxml.jackson.databind.DeserializationFeature;
44 import com.fasterxml.jackson.databind.ObjectMapper;
45 import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
46
47
48 @Configuration("CXFConfiguration")
49 public class CXFConfiguration {
50         
51         JAXRSServerFactoryBean endpoint;
52         
53     @Autowired
54     private Bus bus;
55     
56         @Autowired
57         private JaxRsFilterLogging jaxRsFilterLogging;
58         
59         @Autowired
60         private SDNCAdapterPortType sdncAdapterPortImpl;
61         
62         @Autowired 
63         private SNIROResponse sniroResponse;
64     
65         @Autowired
66         private ObjectMapper mapper;
67         
68     @Bean
69     public Server rsServer() {
70         endpoint = new JAXRSServerFactoryBean();
71         mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
72         endpoint.setBus(bus);
73         endpoint.setServiceBeans(Arrays.<Object>asList(sniroResponse));
74         endpoint.setAddress("/rest");
75         endpoint.setFeatures(Arrays.asList(createSwaggerFeature(), new LoggingFeature()));
76         endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(mapper),jaxRsFilterLogging));
77         return endpoint.create();
78     }
79
80     @Bean
81     public ServletRegistrationBean cxfServlet() {
82         return new ServletRegistrationBean(new CXFServlet(), "/adapters/*");
83     }
84
85     @Bean
86     public Endpoint sndcAdapter() {
87         EndpointImpl wsdlEndpoint = new EndpointImpl(bus, sdncAdapterPortImpl);
88         wsdlEndpoint.getInInterceptors().add(new SOAPLoggingInInterceptor());
89         wsdlEndpoint.getOutInterceptors().add(new SOAPLoggingOutInterceptor());
90         wsdlEndpoint.getOutFaultInterceptors().add(new SOAPLoggingOutInterceptor());
91         wsdlEndpoint.publish("/SDNCAdapter");
92         return wsdlEndpoint;
93     }
94
95
96     @Bean
97     public Swagger2Feature createSwaggerFeature() {
98         Swagger2Feature swagger2Feature= new Swagger2Feature();
99         swagger2Feature.setBasePath("/services/rest");
100         swagger2Feature.setPrettyPrint(true);
101         swagger2Feature.setTitle("SO Orchestration Application");
102         swagger2Feature.setContact("The ONAP SO team");
103         swagger2Feature.setDescription("This project is the SO Orchestration Engine");
104         swagger2Feature.setVersion("1.0.0");
105         swagger2Feature.setResourcePackage("org.onap.so.adapters.sdnc");
106         swagger2Feature.setScan(true);
107         return swagger2Feature;
108     }
109 }