031bc2edc5814ac460b527d3a2d74e8916446e9c
[so.git] / adapters / mso-vfc-adapter / src / main / java / org / onap / so / adapters / vfc / 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.vfc;
22
23 import java.util.Arrays;
24 import javax.xml.ws.Endpoint;
25
26 import org.apache.cxf.Bus;
27 import org.apache.cxf.endpoint.Server;
28 import org.apache.cxf.feature.LoggingFeature;
29 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
30 import org.apache.cxf.jaxrs.swagger.Swagger2Feature;
31 import org.apache.cxf.jaxws.EndpointImpl;
32 import org.apache.cxf.transport.servlet.CXFServlet;
33 import org.onap.so.adapters.vfc.rest.HealthCheckHandler;
34 import org.onap.so.adapters.vfc.rest.VfcAdapterRest;
35 import org.onap.so.logging.jaxrs.filter.JaxRsFilterLogging;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.boot.web.servlet.ServletRegistrationBean;
38 import org.springframework.context.annotation.Bean;
39 import org.springframework.context.annotation.Configuration;
40 import com.fasterxml.jackson.databind.ObjectMapper;
41 import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
42
43
44 @Configuration
45 public class CXFConfiguration {
46
47         @Autowired
48         private Bus bus;
49
50         @Autowired
51     private VfcAdapterRest vfcAdapterRest;
52
53     @Autowired
54     private HealthCheckHandler healthCheckHandler;
55     
56     @Autowired
57     private JaxRsFilterLogging jaxRsFilterLogging;
58     
59     @Autowired
60     private ObjectMapper mapper; 
61         
62         @Bean
63         public ServletRegistrationBean cxfServlet() {   
64                 return new ServletRegistrationBean(new CXFServlet(), "/services/*");
65         }
66         
67     @Bean
68     public Server rsServer() {
69         JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
70         endpoint.setBus(bus);
71         endpoint.setServiceBeans(Arrays.<Object>asList(vfcAdapterRest, healthCheckHandler));
72         endpoint.setAddress("/");       
73         endpoint.setFeatures(Arrays.asList(createSwaggerFeature(), new LoggingFeature()));
74         endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(mapper),jaxRsFilterLogging));
75         return endpoint.create();
76     }
77         
78         @Bean
79         public Swagger2Feature createSwaggerFeature() {
80                 Swagger2Feature swagger2Feature = new Swagger2Feature();
81                 swagger2Feature.setPrettyPrint(true);
82                 swagger2Feature.setTitle("SO Request Adapter");
83                 swagger2Feature.setContact("The ONAP SO team");
84                 swagger2Feature.setDescription("This project is the SO Orchestration Engine");
85                 swagger2Feature.setVersion("1.0.0");
86                 swagger2Feature.setResourcePackage("org.onap.so.adapters.requestdb");
87                 swagger2Feature.setScan(true);
88                 return swagger2Feature;
89         }
90
91 }