1
|
package eu.dnetlib.repo.manager.service.controllers;
|
2
|
|
3
|
|
4
|
import eu.dnetlib.api.functionality.ValidatorServiceException;
|
5
|
import eu.dnetlib.repo.manager.service.exception.ResourceNotFoundException;
|
6
|
import eu.dnetlib.repo.manager.service.exception.ServerError;
|
7
|
import eu.dnetlib.repo.manager.shared.BrokerException;
|
8
|
import org.apache.log4j.LogManager;
|
9
|
import org.apache.log4j.Logger;
|
10
|
import org.json.JSONException;
|
11
|
import org.springframework.core.Ordered;
|
12
|
import org.springframework.core.annotation.Order;
|
13
|
import org.springframework.http.HttpStatus;
|
14
|
import org.springframework.security.access.AccessDeniedException;
|
15
|
import org.springframework.web.bind.annotation.*;
|
16
|
|
17
|
import javax.servlet.http.HttpServletRequest;
|
18
|
import java.net.UnknownHostException;
|
19
|
|
20
|
|
21
|
@ControllerAdvice
|
22
|
@Order(Ordered.HIGHEST_PRECEDENCE)
|
23
|
public class GenericControllerAdvice {
|
24
|
|
25
|
private Logger logger = LogManager.getLogger(GenericControllerAdvice.class);
|
26
|
|
27
|
|
28
|
@ResponseStatus(HttpStatus.NOT_FOUND)
|
29
|
@ExceptionHandler(ResourceNotFoundException.class)
|
30
|
@ResponseBody
|
31
|
ServerError securityException(HttpServletRequest req, Exception ex) {
|
32
|
return new ServerError(req.getRequestURL().toString(),ex);
|
33
|
}
|
34
|
|
35
|
@ResponseStatus(HttpStatus.FORBIDDEN)
|
36
|
@ExceptionHandler(AccessDeniedException.class)
|
37
|
@ResponseBody
|
38
|
ServerError accessDeniedException(HttpServletRequest req, Exception ex) {
|
39
|
return new ServerError(req.getRequestURL().toString(),ex);
|
40
|
}
|
41
|
|
42
|
@ResponseStatus(HttpStatus.NOT_FOUND)
|
43
|
@ExceptionHandler(UnknownHostException.class)
|
44
|
@ResponseBody
|
45
|
ServerError unknownHostException(HttpServletRequest req, Exception ex) {
|
46
|
return new ServerError(req.getRequestURL().toString(),ex);
|
47
|
}
|
48
|
|
49
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
50
|
@ExceptionHandler({JSONException.class,BrokerException.class,ValidatorServiceException.class})
|
51
|
@ResponseBody
|
52
|
ServerError internalException(HttpServletRequest req, Exception ex) {
|
53
|
return new ServerError(req.getRequestURL().toString(),ex);
|
54
|
}
|
55
|
|
56
|
|
57
|
}
|