031e9eee2af987b2641f010c1310f8e0f2930713
[so.git] / mso-api-handlers / mso-api-handler-infra / src / main / java / org / onap / so / apihandlerinfra / JerseyConfiguration.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.apihandlerinfra;
22
23 import java.util.stream.Collectors;
24 import java.util.stream.Stream;
25 import javax.annotation.PostConstruct;
26 import javax.ws.rs.ApplicationPath;
27 import org.glassfish.jersey.server.ResourceConfig;
28 import org.glassfish.jersey.servlet.ServletProperties;
29 import org.onap.logging.filter.base.Constants;
30 import org.onap.so.apihandler.filters.RequestIdFilter;
31 import org.onap.so.apihandlerinfra.exceptions.ApiExceptionMapper;
32 import org.onap.so.apihandlerinfra.infra.rest.Network;
33 import org.onap.so.apihandlerinfra.infra.rest.ServiceInstance;
34 import org.onap.so.apihandlerinfra.infra.rest.VfModules;
35 import org.onap.so.apihandlerinfra.infra.rest.Vnf;
36 import org.onap.so.apihandlerinfra.infra.rest.Volumes;
37 import org.onap.so.apihandlerinfra.infra.rest.exception.mapper.AAIEntityNotFoundMapper;
38 import org.onap.so.apihandlerinfra.infra.rest.exception.mapper.CloudConfigurationNotFoundMapper;
39 import org.onap.so.apihandlerinfra.infra.rest.exception.mapper.NoRecipeExceptionMapper;
40 import org.onap.so.apihandlerinfra.infra.rest.exception.mapper.RequestConflictMapper;
41 import org.onap.so.apihandlerinfra.infra.rest.exception.mapper.WorkflowEngineConnectionMapper;
42 import org.onap.so.apihandlerinfra.tenantisolation.CloudOrchestration;
43 import org.onap.so.apihandlerinfra.tenantisolation.CloudResourcesOrchestration;
44 import org.onap.so.apihandlerinfra.tenantisolation.ModelDistributionRequest;
45 import org.onap.so.logging.jaxrs.filter.SOAuditLogContainerFilter;
46 import org.onap.so.utils.Components;
47 import org.onap.so.web.exceptions.RuntimeExceptionMapper;
48 import org.springframework.context.annotation.Configuration;
49 import io.swagger.v3.jaxrs2.integration.JaxrsOpenApiContextBuilder;
50 import io.swagger.v3.jaxrs2.integration.resources.AcceptHeaderOpenApiResource;
51 import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource;
52 import io.swagger.v3.oas.integration.OpenApiConfigurationException;
53 import io.swagger.v3.oas.integration.SwaggerConfiguration;
54 import io.swagger.v3.oas.models.OpenAPI;
55 import io.swagger.v3.oas.models.info.Info;
56
57 @Configuration
58 @ApplicationPath("/")
59 public class JerseyConfiguration extends ResourceConfig {
60
61     @PostConstruct
62     public void setUp() {
63         System.setProperty(Constants.Property.PARTNER_NAME, Components.APIH.toString());
64         register(GlobalHealthcheckHandler.class);
65         register(NodeHealthcheckHandler.class);
66         register(ServiceInstances.class);
67         register(Onap3gppServiceInstances.class);
68         register(ServiceIntentApiHandler.class);
69         register(TasksHandler.class);
70         register(CloudOrchestration.class);
71         register(CloudResourcesOrchestration.class);
72         register(OrchestrationRequests.class);
73         register(VfModules.class);
74         register(Vnf.class);
75         register(Network.class);
76         register(Volumes.class);
77         register(ServiceInstance.class);
78         register(SOAuditLogContainerFilter.class);
79         register(ManualTasks.class);
80         register(TasksHandler.class);
81         register(OpenApiResource.class);
82         register(AcceptHeaderOpenApiResource.class);
83         register(ApiExceptionMapper.class);
84         register(RuntimeExceptionMapper.class);
85         register(RequestIdFilter.class);
86         register(E2EServiceInstances.class);
87         register(WorkflowSpecificationsHandler.class);
88         register(InstanceManagement.class);
89         register(ResumeOrchestrationRequest.class);
90         register(AAIEntityNotFoundMapper.class);
91         register(CloudConfigurationNotFoundMapper.class);
92         register(NoRecipeExceptionMapper.class);
93         register(RequestConflictMapper.class);
94         register(WorkflowEngineConnectionMapper.class);
95         register(OrchestrationTasks.class);
96         // this registration seems to be needed to get predictable
97         // execution behavior for the above JSON Exception Mappers
98         register(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider.class);
99
100         register(ModelDistributionRequest.class);
101         property(ServletProperties.FILTER_FORWARD_ON_404, true);
102
103         OpenAPI oas = new OpenAPI();
104         Info info = new Info();
105         info.title("Swagger apihandlerinfra bootstrap code");
106         info.setVersion("1.0.2");
107
108         SwaggerConfiguration oasConfig = new SwaggerConfiguration().openAPI(oas).prettyPrint(true)
109                 .resourcePackages(Stream.of("org.onap.so.apihandlerinfra").collect(Collectors.toSet()));
110
111         try {
112             new JaxrsOpenApiContextBuilder().application(this).openApiConfiguration(oasConfig).buildContext(true);
113         } catch (OpenApiConfigurationException e) {
114             throw new RuntimeException(e.getMessage(), e);
115         }
116
117     }
118
119 }