cb20ded8de3db4bd9cd491fa6727fbf43f6ed141
[so.git] / bpmn / mso-infrastructure-bpmn / src / main / java / org / onap / so / bpmn / infrastructure / CXFConfiguration.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure;
24
25 import java.util.Arrays;
26
27 import javax.xml.ws.Endpoint;
28
29 import org.apache.cxf.Bus;
30 import org.apache.cxf.endpoint.Server;
31 import org.apache.cxf.feature.LoggingFeature;
32 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
33 import org.apache.cxf.jaxrs.swagger.Swagger2Feature;
34 import org.apache.cxf.jaxws.EndpointImpl;
35 import org.apache.cxf.transport.servlet.CXFServlet;
36 import org.onap.so.bpmn.common.adapter.sdnc.SDNCCallbackAdapterPortType;
37 import org.onap.so.bpmn.common.adapter.vnf.VnfAdapterNotify;
38 import org.onap.so.bpmn.common.workflow.service.WorkflowAsyncResource;
39 import org.onap.so.bpmn.common.workflow.service.WorkflowMessageResource;
40 import org.onap.so.bpmn.common.workflow.service.WorkflowResource;
41 import org.onap.so.logging.cxf.interceptor.SOAPLoggingInInterceptor;
42 import org.onap.so.logging.cxf.interceptor.SOAPLoggingOutInterceptor;
43 import org.onap.so.logging.jaxrs.filter.JaxRsFilterLogging;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46 import org.springframework.beans.factory.annotation.Autowired;
47 import org.springframework.boot.web.servlet.ServletRegistrationBean;
48 import org.springframework.context.annotation.Bean;
49 import org.springframework.context.annotation.Configuration;
50
51 import com.fasterxml.jackson.databind.ObjectMapper;
52 import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
53
54
55 @Configuration
56 public class CXFConfiguration {
57     
58         private static final Logger logger = LoggerFactory.getLogger(CXFConfiguration.class);
59         
60     @Autowired
61     private Bus bus;    
62
63         @Autowired
64         private WorkflowMessageResource wmr;
65         
66         @Autowired
67         private WorkflowResource workflowResource;
68
69         @Autowired
70         private WorkflowAsyncResource workflowAsyncResource;
71         
72         @Autowired
73         private JaxRsFilterLogging jaxRsFilterLogging;
74         
75         @Autowired
76         private ObjectMapper mapper; 
77         
78         @Autowired
79         private SDNCCallbackAdapterPortType sdncAdapterCallbackServiceImpl;
80         
81         @Autowired
82         private VnfAdapterNotify vnfAdapterNotifyServiceImpl;
83         
84         @Bean
85     public ServletRegistrationBean cxfServlet() {
86         return new ServletRegistrationBean(new CXFServlet(), "/mso/*");
87     }
88     
89     @Bean
90     public Endpoint vnfAdapterCallback() {
91         EndpointImpl endpoint = new EndpointImpl(bus, vnfAdapterNotifyServiceImpl);
92         endpoint.publish("/VNFAdaptercallback");
93         endpoint.getInInterceptors().add(new SOAPLoggingInInterceptor());
94         endpoint.getOutInterceptors().add(new SOAPLoggingOutInterceptor());
95         endpoint.getOutFaultInterceptors().add(new SOAPLoggingOutInterceptor());
96         return endpoint;
97     }
98         
99     @Bean
100     public Endpoint sndcAdapterCallback() {
101         EndpointImpl endpoint = new EndpointImpl(bus, sdncAdapterCallbackServiceImpl);
102         endpoint.publish("/SDNCAdapterCallbackService");
103         endpoint.getInInterceptors().add(new SOAPLoggingInInterceptor());
104         endpoint.getOutInterceptors().add(new SOAPLoggingOutInterceptor());
105         endpoint.getOutFaultInterceptors().add(new SOAPLoggingOutInterceptor());
106         return endpoint;
107     }
108                 
109     @Bean
110     public Server rsServer() {
111         JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
112         endpoint.setBus(bus);
113         endpoint.setServiceBeans(Arrays.<Object>asList(wmr, workflowResource, workflowAsyncResource));
114         endpoint.setAddress("/");       
115         endpoint.setFeatures(Arrays.asList(createSwaggerFeature(), new LoggingFeature()));
116         endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(mapper),jaxRsFilterLogging));
117        
118         return endpoint.create();
119     }
120
121     @Bean
122     public Swagger2Feature createSwaggerFeature() {
123         Swagger2Feature swagger2Feature= new Swagger2Feature();
124         swagger2Feature.setPrettyPrint(true);
125         swagger2Feature.setTitle("SO Orchestration Application");
126         swagger2Feature.setContact("The ONAP SO team");
127         swagger2Feature.setDescription("This project is the SO Orchestration Engine");
128         swagger2Feature.setVersion("1.0.0");
129         swagger2Feature.setResourcePackage("org.onap.so.bpmn.common.workflow.service");
130         swagger2Feature.setScan(true);
131         return swagger2Feature;
132     }
133 }