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