Merge "Added null checks for bp to prevent exceptions at bp.getId() calls; fixed...
[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.web.exceptions.RuntimeExceptionMapper;
49 import org.springframework.context.annotation.Configuration;
50 import io.swagger.v3.jaxrs2.integration.JaxrsOpenApiContextBuilder;
51 import io.swagger.v3.jaxrs2.integration.resources.AcceptHeaderOpenApiResource;
52 import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource;
53 import io.swagger.v3.oas.integration.OpenApiConfigurationException;
54 import io.swagger.v3.oas.integration.SwaggerConfiguration;
55 import io.swagger.v3.oas.models.OpenAPI;
56 import io.swagger.v3.oas.models.info.Info;
57
58 @Configuration
59 @ApplicationPath("/")
60 public class JerseyConfiguration extends ResourceConfig {
61
62     @PostConstruct
63     public void setUp() {
64         System.setProperty(Constants.Property.PARTNER_NAME, "SO.APIH");
65         register(GlobalHealthcheckHandler.class);
66         register(NodeHealthcheckHandler.class);
67         register(ServiceInstances.class);
68         register(TasksHandler.class);
69         register(CloudOrchestration.class);
70         register(CloudResourcesOrchestration.class);
71         register(OrchestrationRequests.class);
72         register(VfModules.class);
73         register(Vnf.class);
74         register(Network.class);
75         register(Volumes.class);
76         register(ServiceInstance.class);
77         register(SOAuditLogContainerFilter.class);
78         register(ManualTasks.class);
79         register(TasksHandler.class);
80         register(OpenApiResource.class);
81         register(AcceptHeaderOpenApiResource.class);
82         register(ApiExceptionMapper.class);
83         register(RuntimeExceptionMapper.class);
84         register(RequestIdFilter.class);
85         register(E2EServiceInstances.class);
86         register(WorkflowSpecificationsHandler.class);
87         register(InstanceManagement.class);
88         register(ResumeOrchestrationRequest.class);
89         register(AAIEntityNotFoundMapper.class);
90         register(CloudConfigurationNotFoundMapper.class);
91         register(NoRecipeExceptionMapper.class);
92         register(RequestConflictMapper.class);
93         register(WorkflowEngineConnectionMapper.class);
94         // this registration seems to be needed to get predictable
95         // execution behavior for the above JSON Exception Mappers
96         register(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider.class);
97         register(ModelDistributionRequest.class);
98         property(ServletProperties.FILTER_FORWARD_ON_404, true);
99
100         OpenAPI oas = new OpenAPI();
101         Info info = new Info();
102         info.title("Swagger apihandlerinfra bootstrap code");
103         info.setVersion("1.0.2");
104
105         SwaggerConfiguration oasConfig = new SwaggerConfiguration().openAPI(oas).prettyPrint(true)
106                 .resourcePackages(Stream.of("org.onap.so.apihandlerinfra").collect(Collectors.toSet()));
107
108         try {
109             new JaxrsOpenApiContextBuilder().application(this).openApiConfiguration(oasConfig).buildContext(true);
110         } catch (OpenApiConfigurationException e) {
111             throw new RuntimeException(e.getMessage(), e);
112         }
113
114     }
115
116 }