Remove legacy certificate handling
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / distribution / servlet / DistributionServlet.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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 package org.openecomp.sdc.be.distribution.servlet;
21
22 import com.jcabi.aspects.Loggable;
23 import fj.data.Either;
24 import io.swagger.v3.oas.annotations.Operation;
25 import io.swagger.v3.oas.annotations.Parameter;
26 import io.swagger.v3.oas.annotations.Parameters;
27 import io.swagger.v3.oas.annotations.media.ArraySchema;
28 import io.swagger.v3.oas.annotations.media.Content;
29 import io.swagger.v3.oas.annotations.media.Schema;
30 import io.swagger.v3.oas.annotations.responses.ApiResponse;
31 import io.swagger.v3.oas.annotations.servers.Server;
32 import io.swagger.v3.oas.annotations.servers.Servers;
33 import io.swagger.v3.oas.annotations.tags.Tag;
34 import io.swagger.v3.oas.annotations.tags.Tags;
35 import javax.inject.Inject;
36 import javax.servlet.http.HttpServletRequest;
37 import javax.ws.rs.Consumes;
38 import javax.ws.rs.GET;
39 import javax.ws.rs.HeaderParam;
40 import javax.ws.rs.POST;
41 import javax.ws.rs.Path;
42 import javax.ws.rs.Produces;
43 import javax.ws.rs.core.Context;
44 import javax.ws.rs.core.MediaType;
45 import javax.ws.rs.core.Response;
46 import org.openecomp.sdc.be.config.BeEcompErrorManager;
47 import org.openecomp.sdc.be.dao.api.ActionStatus;
48 import org.openecomp.sdc.be.distribution.AuditHandler;
49 import org.openecomp.sdc.be.distribution.DistributionBusinessLogic;
50 import org.openecomp.sdc.be.distribution.api.client.KafkaDataResponse;
51 import org.openecomp.sdc.be.distribution.api.client.RegistrationRequest;
52 import org.openecomp.sdc.be.distribution.api.client.ServerListResponse;
53 import org.openecomp.sdc.be.distribution.api.client.TopicRegistrationResponse;
54 import org.openecomp.sdc.be.distribution.api.client.TopicUnregistrationResponse;
55 import org.openecomp.sdc.be.impl.ComponentsUtils;
56 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
57 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
58 import org.openecomp.sdc.be.servlets.BeGenericServlet;
59 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
60 import org.openecomp.sdc.common.api.Constants;
61 import org.openecomp.sdc.common.datastructure.Wrapper;
62 import org.openecomp.sdc.common.log.wrappers.Logger;
63 import org.openecomp.sdc.common.util.HttpUtil;
64 import org.openecomp.sdc.exception.ResponseFormat;
65 import org.springframework.stereotype.Controller;
66
67 /**
68  * This Servlet serves external users for distribution purposes.
69  *
70  * @author tgitelman
71  */
72 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
73 @Path("/v1")
74 @Tags({@Tag(name = "SDCE-6 APIs")})
75 @Servers({@Server(url = "/sdc")})
76 @Controller
77 public class DistributionServlet extends BeGenericServlet {
78
79     private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
80     private static final Logger log = Logger.getLogger(DistributionServlet.class);
81     private final DistributionBusinessLogic distributionLogic;
82     @Context
83     private HttpServletRequest request;
84
85     @Inject
86     public DistributionServlet(ComponentsUtils componentsUtils, DistributionBusinessLogic distributionLogic) {
87         super(componentsUtils);
88         this.distributionLogic = distributionLogic;
89     }
90
91     /**
92      * @param requestId
93      * @param instanceId
94      * @param accept
95      * @param authorization
96      * @return
97      */
98     @GET
99     @Path("/distributionUebCluster")
100     @Consumes(MediaType.APPLICATION_JSON)
101     @Produces(MediaType.APPLICATION_JSON)
102     @Operation(description = "UEB Server List", method = "GET", summary = "return the available UEB Server List", responses = {
103         @ApiResponse(responseCode = "200", description = "ECOMP component is authenticated and list of Cambria API server’s FQDNs is returned", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ServerListResponse.class)))),
104         @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),
105         @ApiResponse(responseCode = "401", description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its credentials  for  Basic Authentication - POL5002"),
106         @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
107         @ApiResponse(responseCode = "405", description = "Method  Not Allowed: Invalid HTTP method type used ( PUT,DELETE,POST will be rejected) - POL4050"),
108         @ApiResponse(responseCode = "500", description = "The GET request failed either due to internal SDC problem or Cambria Service failure. ECOMP Component should continue the attempts to get the needed information - POL5000")})
109     //TODO Tal G fix response headers
110
111     /*responseHeaders = {
112             @ResponseHeader(name = Constants.CONTENT_TYPE_HEADER, description = "Determines the format of the response body", response = String.class),
113             @ResponseHeader(name = "Content-Length", description = "Length of  the response body", response = String.class)})*/
114     public Response getUebServerList(
115         @Parameter(description = "X-ECOMP-RequestID header", required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
116         @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId,
117         @Parameter(description = "Determines the format of the body of the response", required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
118         @Parameter(description = "The username and password", required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization) {
119         String url = request.getMethod() + " " + request.getRequestURI();
120         log.debug(START_HANDLE_REQUEST_OF, url);
121         Response response = null;
122         ResponseFormat responseFormat = null;
123         if (instanceId == null) {
124             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
125             response = buildErrorResponse(responseFormat);
126             getComponentsUtils().auditGetUebCluster(null, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage());
127             return response;
128         }
129         try {
130             Either<ServerListResponse, ResponseFormat> actionResponse = distributionLogic.getUebServerList();
131             if (actionResponse.isRight()) {
132                 responseFormat = actionResponse.right().value();
133                 response = buildErrorResponse(responseFormat);
134             } else {
135                 responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
136                 response = buildOkResponse(responseFormat, actionResponse.left().value());
137             }
138             getComponentsUtils().auditGetUebCluster(instanceId, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage());
139             return response;
140         } catch (Exception e) {
141             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("failed to get ueb serbver list from cofiguration");
142             log.debug("failed to get ueb serbver list from cofiguration", e);
143             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
144             getComponentsUtils().auditGetUebCluster(instanceId, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage());
145             return buildErrorResponse(responseFormat);
146         }
147     }
148
149     /**
150      * @param requestId UUID to track the incoming request
151      * @param instanceId UUID to identify the requesting instance
152      * @param accept Determines the format of the body of the response
153      * @param authorization Username and password auth towards SDC
154      * @return KafkaDataResponse (Kafka bootstrap server and topic list to be used by clients)
155      */
156     @GET
157     @Path("/distributionKafkaData")
158     @Consumes(MediaType.APPLICATION_JSON)
159     @Produces(MediaType.APPLICATION_JSON)
160     @Operation(description = "Kafka data", method = "GET", summary = "return the kafka cluster and topic list", responses = {
161         @ApiResponse(responseCode = "200", description = "ECOMP component is authenticated and kafka endpoint and topic list is returned", content = @Content(array = @ArraySchema(schema = @Schema(implementation = KafkaDataResponse.class)))),
162         @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID'  HTTP header - POL5001"),
163         @ApiResponse(responseCode = "401", description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its credentials  for  Basic Authentication - POL5002"),
164         @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
165         @ApiResponse(responseCode = "405", description = "Method  Not Allowed: Invalid HTTP method type used ( PUT,DELETE,POST will be rejected) - POL4050"),
166         @ApiResponse(responseCode = "500", description = "The GET request failed either due to internal SDC problem or Cambria Service failure. ECOMP Component should continue the attempts to get the needed information - POL5000")})
167     public Response getKafkaData(
168         @Parameter(description = "X-ECOMP-RequestID header", required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
169         @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId,
170         @Parameter(description = "Determines the format of the body of the response", required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
171         @Parameter(description = "The username and password", required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization) {
172         String url = request.getMethod() + " " + request.getRequestURI();
173         log.debug(START_HANDLE_REQUEST_OF, url);
174         ResponseFormat responseFormat;
175         if (instanceId == null) {
176             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
177             getComponentsUtils().auditGetUebCluster(null, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage());
178             return buildErrorResponse(responseFormat);
179         }
180         try {
181             Response response;
182             Either<KafkaDataResponse, ResponseFormat> actionResponse = distributionLogic.getKafkaData();
183             if (actionResponse.isRight()) {
184                 responseFormat = actionResponse.right().value();
185                 response = buildErrorResponse(responseFormat);
186             } else {
187                 responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
188                 response = buildOkResponse(responseFormat, actionResponse.left().value());
189             }
190             getComponentsUtils().auditGetUebCluster(instanceId, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage());
191             return response;
192         } catch (Exception e) {
193             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("failed to get kafka cluster and topic list from configuration");
194             log.debug("failed to get kafka cluster and topic list from configuration", e);
195             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
196             getComponentsUtils().auditGetUebCluster(instanceId, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage());
197             return buildErrorResponse(responseFormat);
198         }
199     }
200
201     /**
202      * @param requestId
203      * @param instanceId
204      * @param accept
205      * @param contentType
206      * @param contenLength
207      * @param authorization
208      * @param requestJson
209      * @return
210      */
211     @POST
212     @Path("/registerForDistribution")
213     @Consumes(MediaType.APPLICATION_JSON)
214     @Produces(MediaType.APPLICATION_JSON)
215     @Operation(parameters = {
216         @Parameter(name = "requestJson", required = true, schema = @Schema(implementation = org.openecomp.sdc.be.distribution.api.client.RegistrationRequest.class))}, description = "Subscription status", method = "POST", summary = "Subscribes for distribution notifications", responses = {
217         @ApiResponse(responseCode = "200", description = "ECOMP component is successfully registered for distribution", content = @Content(array = @ArraySchema(schema = @Schema(implementation = TopicRegistrationResponse.class)))),
218         @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),
219         @ApiResponse(responseCode = "400", description = "Missing  Body - POL4500"),
220         @ApiResponse(responseCode = "400", description = "Invalid  Body  : missing mandatory parameter 'apiPublicKey' - POL4501"),
221         @ApiResponse(responseCode = "400", description = "Invalid  Body  : missing mandatory parameter 'distrEnvName' - POL4502"),
222         @ApiResponse(responseCode = "400", description = "Invalid Body :  Specified 'distrEnvName' doesn’t exist - POL4137"),
223         @ApiResponse(responseCode = "401", description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic Authentication credentials - POL5002"),
224         @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
225         @ApiResponse(responseCode = "405", description = "Method  Not Allowed  :  Invalid HTTP method type used to  register for  distribution ( PUT,DELETE,GET  will be rejected) - POL4050"),
226         @ApiResponse(responseCode = "500", description = "The registration failed due to internal SDC problem or Cambria Service failure ECOMP Component  should  continue the attempts to  register for  distribution - POL5000")})
227     public Response registerForDistribution(
228         @Parameter(description = "X-ECOMP-RequestID header", required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
229         @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId,
230         @Parameter(description = "Determines the format of the body of the response", required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
231         @Parameter(description = "Determines the format of the body of the request", required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
232         @Parameter(description = "Length  of  the request body", required = true) @HeaderParam(value = Constants.CONTENT_LENGTH_HEADER) String contenLength,
233         @Parameter(description = "The username and password", required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
234         @Parameter(hidden = true) String requestJson) {
235         String url = request.getMethod() + " " + request.getRequestURI();
236         log.debug(START_HANDLE_REQUEST_OF, url);
237         Wrapper<Response> responseWrapper = new Wrapper<>();
238         Wrapper<RegistrationRequest> registrationRequestWrapper = new Wrapper<>();
239         validateHeaders(responseWrapper, request, AuditingActionEnum.ADD_KEY_TO_TOPIC_ACL);
240         if (responseWrapper.isEmpty()) {
241             validateJson(responseWrapper, registrationRequestWrapper, requestJson);
242         }
243         if (responseWrapper.isEmpty()) {
244             validateEnv(responseWrapper);
245         }
246         if (responseWrapper.isEmpty()) {
247             distributionLogic.handleRegistration(responseWrapper, registrationRequestWrapper.getInnerElement(),
248                 buildAuditHandler(request, registrationRequestWrapper.getInnerElement()));
249         } else {
250             BeEcompErrorManager.getInstance()
251                 .logBeDistributionEngineSystemError(DistributionBusinessLogic.REGISTER_IN_DISTRIBUTION_ENGINE, "registration validation failed");
252         }
253         return responseWrapper.getInnerElement();
254     }
255
256     /**
257      * Returns list of valid artifact types for validation done in the distribution client.<br> The list is the representation of the values of the
258      * enum ArtifactTypeEnum.
259      */
260     @GET
261     @Path("/artifactTypes")
262     @Consumes(MediaType.APPLICATION_JSON)
263     @Produces(MediaType.APPLICATION_JSON)
264     @Operation(description = "Artifact types list", method = "GET", summary = "Fetches available artifact types list", responses = {
265         @ApiResponse(responseCode = "200", description = "Artifact types list fetched successfully", content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
266         @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),
267         @ApiResponse(responseCode = "401", description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic Authentication credentials - POL5002"),
268         @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
269         @ApiResponse(responseCode = "405", description = "Method  Not Allowed  :  Invalid HTTP method type used to  register for  distribution ( POST,PUT,DELETE  will be rejected) - POL4050"),
270         @ApiResponse(responseCode = "500", description = "The registration failed due to internal SDC problem or Cambria Service failure ECOMP Component  should  continue the attempts to  register for  distribution - POL5000")})
271     public Response getValidArtifactTypes(
272         @Parameter(description = "X-ECOMP-RequestID header", required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
273         @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId,
274         @Parameter(description = "The username and password", required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
275         @Parameter(description = "The username and password", required = true) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept) {
276         String url = request.getMethod() + " " + request.getRequestURI();
277         log.debug(START_HANDLE_REQUEST_OF, url);
278         Wrapper<Response> responseWrapper = new Wrapper<>();
279         //TODO check if in use
280         validateHeaders(responseWrapper, request, AuditingActionEnum.GET_VALID_ARTIFACT_TYPES);
281         if (responseWrapper.isEmpty()) {
282             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), ArtifactTypeEnum.values());
283         } else {
284             return responseWrapper.getInnerElement();
285         }
286     }
287
288     /**
289      * Removes from subscription for distribution notifications
290      *
291      * @param requestId
292      * @param instanceId
293      * @param accept
294      * @param contentType
295      * @param contenLength
296      * @param authorization
297      * @param requestJson
298      * @return
299      */
300     @POST
301     @Path("/unRegisterForDistribution")
302     @Consumes(MediaType.APPLICATION_JSON)
303     @Produces(MediaType.APPLICATION_JSON)
304     @Operation(parameters = @Parameter(name = "requestJson", required = true), description = "Subscription status", method = "POST", summary = "Removes from subscription for distribution notifications", responses = {
305         @ApiResponse(responseCode = "204", description = "ECOMP component is successfully unregistered", content = @Content(array = @ArraySchema(schema = @Schema(implementation = TopicUnregistrationResponse.class)))),
306         @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),
307         @ApiResponse(responseCode = "400", description = "Missing  Body - POL4500"),
308         @ApiResponse(responseCode = "400", description = "Invalid  Body  : missing mandatory parameter 'apiPublicKey' - POL4501"),
309         @ApiResponse(responseCode = "400", description = "Invalid  Body  : missing mandatory parameter 'distrEnvName' - SVC4506"),
310         @ApiResponse(responseCode = "400", description = "Invalid Body :  Specified 'distrEnvName' doesn’t exist - POL4137"),
311         @ApiResponse(responseCode = "401", description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic Authentication credentials - POL5002"),
312         @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
313         @ApiResponse(responseCode = "405", description = "Method  Not Allowed  :  Invalid HTTP method type used to  register for  distribution ( PUT,DELETE,GET will be rejected) - POL4050"),
314         @ApiResponse(responseCode = "500", description = "The registration failed due to internal SDC problem or Cambria Service failure ECOMP Component  should  continue the attempts to  register for  distribution - POL5000")})
315     //TODO Edit the responses
316     @Parameters({
317         @Parameter(name = "requestJson", required = true, schema = @Schema(implementation = org.openecomp.sdc.be.distribution.api.client.RegistrationRequest.class), description = "json describe the artifact")})
318     public Response unRegisterForDistribution(
319         @Parameter(description = "X-ECOMP-RequestID header", required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
320         @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId,
321         @Parameter(description = "Determines the format of the body of the response", required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
322         @Parameter(description = "Determines the format of the body of the request", required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
323         @Parameter(description = "Length  of  the request body", required = true) @HeaderParam(value = Constants.CONTENT_LENGTH_HEADER) String contenLength,
324         @Parameter(description = "The username and password", required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
325         @Parameter(hidden = true) String requestJson) {
326         String url = request.getMethod() + " " + request.getRequestURI();
327         log.debug(START_HANDLE_REQUEST_OF, url);
328         Wrapper<Response> responseWrapper = new Wrapper<>();
329         Wrapper<RegistrationRequest> unRegistrationRequestWrapper = new Wrapper<>();
330         validateHeaders(responseWrapper, request, AuditingActionEnum.REMOVE_KEY_FROM_TOPIC_ACL);
331         if (responseWrapper.isEmpty()) {
332             validateJson(responseWrapper, unRegistrationRequestWrapper, requestJson);
333         }
334         if (responseWrapper.isEmpty()) {
335             validateEnv(responseWrapper);
336         }
337         if (responseWrapper.isEmpty()) {
338             distributionLogic.handleUnRegistration(responseWrapper, unRegistrationRequestWrapper.getInnerElement(),
339                 buildAuditHandler(request, unRegistrationRequestWrapper.getInnerElement()));
340         } else {
341             BeEcompErrorManager.getInstance()
342                 .logBeDistributionEngineSystemError(DistributionBusinessLogic.UN_REGISTER_IN_DISTRIBUTION_ENGINE, "unregistration validation failed");
343         }
344         return responseWrapper.getInnerElement();
345     }
346
347     private void validateEnv(Wrapper<Response> responseWrapper) {
348         // DE194021
349         StorageOperationStatus environmentStatus = distributionLogic.getDistributionEngine().isEnvironmentAvailable();
350         if (environmentStatus != StorageOperationStatus.OK) {
351             if (environmentStatus == StorageOperationStatus.DISTR_ENVIRONMENT_NOT_FOUND) {
352                 Response missingHeaderResponse = buildErrorResponse(
353                     distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.DISTRIBUTION_ENV_DOES_NOT_EXIST));
354                 responseWrapper.setInnerElement(missingHeaderResponse);
355             } else {
356                 Response missingHeaderResponse = buildErrorResponse(
357                     distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR));
358                 responseWrapper.setInnerElement(missingHeaderResponse);
359             }
360         }
361     }
362
363     private void validateHeaders(Wrapper<Response> responseWrapper, HttpServletRequest request, AuditingActionEnum auditingAction) {
364         if (request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER) == null) {
365             Response missingHeaderResponse = buildErrorResponse(
366                 distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID));
367             responseWrapper.setInnerElement(missingHeaderResponse);
368             ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
369             getComponentsUtils().auditMissingInstanceIdAsDistributionEngineEvent(auditingAction, responseFormat.getStatus().toString());
370         }
371     }
372
373     private void validateJson(Wrapper<Response> responseWrapper, Wrapper<RegistrationRequest> registrationRequestWrapper, String requestJson) {
374         if (requestJson == null || requestJson.isEmpty()) {
375             Response missingBodyResponse = buildErrorResponse(
376                 distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_BODY));
377             responseWrapper.setInnerElement(missingBodyResponse);
378         } else {
379             Either<RegistrationRequest, Exception> eitherRegistration = HttpUtil.convertJsonStringToObject(requestJson, RegistrationRequest.class);
380             if (eitherRegistration.isLeft()) {
381                 RegistrationRequest registrationRequest = eitherRegistration.left().value();
382                 if (registrationRequest.getApiPublicKey() == null) {
383                     Response missingBodyResponse = buildErrorResponse(
384                         distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_PUBLIC_KEY));
385                     responseWrapper.setInnerElement(missingBodyResponse);
386                 } else if (registrationRequest.getDistrEnvName() == null) {
387                     Response missingBodyResponse = buildErrorResponse(
388                         distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_ENV_NAME));
389                     responseWrapper.setInnerElement(missingBodyResponse);
390                 } else {
391                     registrationRequestWrapper.setInnerElement(registrationRequest);
392                 }
393             } else {
394                 Response missingBodyResponse = buildErrorResponse(
395                     distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_BODY));
396                 responseWrapper.setInnerElement(missingBodyResponse);
397             }
398         }
399     }
400
401     private AuditHandler buildAuditHandler(HttpServletRequest request, RegistrationRequest registrationRequest) {
402         return new AuditHandler(getComponentsUtils(), request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), registrationRequest);
403     }
404 }