I trying configure global exception handler, but it doesn't work.
1-st variant:
@ControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ExHandler extends ResponseEntityExceptionHandler {
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(value = Exception.class)
protected ResponseEntity<Object> handleConflict(Exception ex, WebRequest request) {
String bodyOfResponse = "This should be application specific";
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.CONFLICT, request);
}
}
2-nd variant:
@Component
public class ExResolver extends AbstractHandlerExceptionResolver {
@Override
public int getOrder() {
return Integer.MIN_VALUE;
}
@Override
protected ModelAndView doResolveException
(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
try {
if (ex instanceof IllegalArgumentException) {
return handleIllegalArgument((IllegalArgumentException) ex, response);
}
} catch (Exception handlerException) {
logger.warn("Handling of [" + ex.getClass().getName() + "] resulted in Exception", handlerException);
}
return null;
}
private ModelAndView handleIllegalArgument(IllegalArgumentException ex, HttpServletResponse response) throws IOException {
response.sendError(HttpServletResponse.SC_CONFLICT);
return new ModelAndView();
}
}
src/main/resources/alfresco/web-extension/custom-slingshot-application-context.xml
<?xml version='1.0' encoding='UTF-8'?>
<!-- This is a sample configuration file from Alfresco Community - Please adapt to your version -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="net.example.alfresco"/>
</beans>
Beans success created, but it not work
What am I missing or doing wrong?
Alfresco does not use Spring Boot, just simple Spring beans. Nothing is looking for or using any exception handler or resolver, so defining one has no effect at all. In short, there is no support for adding generic / global exception handlers in Alfresco Content Services - exception handling is done as part of the individual ReST API operation code.
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.