1 package org.onap.vid.controllers;
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.commons.lang.exception.ExceptionUtils;
5 import org.onap.vid.model.ExceptionResponse;
6 import org.onap.portalsdk.core.controller.RestrictedBaseController;
7 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
8 import org.springframework.http.HttpStatus;
9 import org.springframework.http.ResponseEntity;
10 import org.springframework.web.bind.annotation.ExceptionHandler;
11 import org.springframework.web.bind.annotation.ResponseBody;
12 import org.springframework.web.bind.annotation.ResponseStatus;
13 import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
15 import static org.onap.vid.utils.Logging.getMethodCallerName;
16 import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
18 public abstract class VidRestrictedBaseController extends RestrictedBaseController {
20 protected final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(this.getClass().getName());
22 @ExceptionHandler(MethodArgumentTypeMismatchException.class)
24 public ResponseEntity handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) {
25 LOGGER.error(EELFLoggerDelegate.errorLogger, "{}: {}", getMethodCallerName(), ExceptionUtils.getMessage(e), e);
26 Class<?> type = e.getRequiredType();
29 message = "The parameter " + e.getName() + " must have a value among : " + StringUtils.join(type.getEnumConstants(), ", ");
32 message = "The parameter " + e.getName() + " must be of type " + type.getTypeName();
34 ResponseEntity response = new ResponseEntity<String>(message, HttpStatus.BAD_REQUEST);
38 @ExceptionHandler(Exception.class)
39 @ResponseStatus(value=INTERNAL_SERVER_ERROR)
40 public ExceptionResponse exceptionHandler(Exception e) {
41 return ControllersUtils.handleException(e, LOGGER);