Merge "Modify JerseyConfig"
[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.servlet.ServletConfig;
27 import javax.ws.rs.ApplicationPath;
28 import javax.ws.rs.core.Context;
29 import org.glassfish.jersey.server.ResourceConfig;
30 import org.glassfish.jersey.servlet.ServletProperties;
31 import org.onap.logging.filter.base.Constants;
32 import org.onap.so.apihandler.filters.RequestIdFilter;
33 import org.onap.so.apihandlerinfra.exceptions.ApiExceptionMapper;
34 import org.onap.so.apihandlerinfra.infra.rest.Network;
35 import org.onap.so.apihandlerinfra.infra.rest.ServiceInstance;
36 import org.onap.so.apihandlerinfra.infra.rest.VfModules;
37 import org.onap.so.apihandlerinfra.infra.rest.Vnf;
38 import org.onap.so.apihandlerinfra.infra.rest.Volumes;
39 import org.onap.so.apihandlerinfra.infra.rest.exception.mapper.AAIEntityNotFoundMapper;
40 import org.onap.so.apihandlerinfra.infra.rest.exception.mapper.CloudConfigurationNotFoundMapper;
41 import org.onap.so.apihandlerinfra.infra.rest.exception.mapper.NoRecipeExceptionMapper;
42 import org.onap.so.apihandlerinfra.infra.rest.exception.mapper.RequestConflictMapper;
43 import org.onap.so.apihandlerinfra.infra.rest.exception.mapper.WorkflowEngineConnectionMapper;
44 import org.onap.so.apihandlerinfra.tenantisolation.CloudOrchestration;
45 import org.onap.so.apihandlerinfra.tenantisolation.CloudResourcesOrchestration;
46 import org.onap.so.apihandlerinfra.tenantisolation.ModelDistributionRequest;
47 import org.onap.so.logging.jaxrs.filter.SOAuditLogContainerFilter;
48 import org.onap.so.utils.Components;
49 import org.onap.so.web.exceptions.RuntimeExceptionMapper;
50 import org.springframework.context.annotation.Configuration;
51 import io.swagger.v3.jaxrs2.integration.JaxrsOpenApiContextBuilder;
52 import io.swagger.v3.jaxrs2.integration.resources.AcceptHeaderOpenApiResource;
53 import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource;
54 import io.swagger.v3.oas.integration.OpenApiConfigurationException;
55 import io.swagger.v3.oas.integration.SwaggerConfiguration;
56 import io.swagger.v3.oas.models.OpenAPI;
57 import io.swagger.v3.oas.models.info.Info;
58
59 @Configuration
60 @ApplicationPath("/")
61 public class JerseyConfiguration extends ResourceConfig {
62
63     @PostConstruct
64     public void setUp() {
65         System.setProperty(Constants.Property.PARTNER_NAME, Components.APIH.toString());
66         register(GlobalHealthcheckHandler.class);
67         register(NodeHealthcheckHandler.class);
68         register(ServiceInstances.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         register(ModelDistributionRequest.class);
100         property(ServletProperties.FILTER_FORWARD_ON_404, true);
101
102         OpenAPI oas = new OpenAPI();
103         Info info = new Info();
104         info.title("Swagger apihandlerinfra bootstrap code");
105         info.setVersion("1.0.2");
106
107         SwaggerConfiguration oasConfig = new SwaggerConfiguration().openAPI(oas).prettyPrint(true)
108                 .resourcePackages(Stream.of("org.onap.so.apihandlerinfra").collect(Collectors.toSet()));
109
110         try {
111             new JaxrsOpenApiContextBuilder().application(this).openApiConfiguration(oasConfig).buildContext(true);
112         } catch (OpenApiConfigurationException e) {
113             throw new RuntimeException(e.getMessage(), e);
114         }
115
116     }
117
118 }