Class AbstractRestHandlerExceptionResolver

  • All Implemented Interfaces:
    org.springframework.core.Ordered, org.springframework.web.servlet.HandlerExceptionResolver
    Direct Known Subclasses:
    RestExceptionResolver, RestHandlerExceptionResolver

    public abstract class AbstractRestHandlerExceptionResolver
    extends org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
    Converts HTTP request using provided list of HttpMessageConverter. Class also calculates HTTP status code and error message and sets it to HTTP response. It also logs information about exception such as message and stacktrace.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static int UNDEFINED_ERROR_STATUS  
      • Fields inherited from class org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver

        logger
      • Fields inherited from interface org.springframework.core.Ordered

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected int calculateStatusFromException​(java.lang.Exception ex)
      Calculates HTTP status code.
      protected ErrorListWsDTO convertException​(java.lang.Exception ex)
      Converts Exception object into list of ErrorWsDTO.
      protected org.springframework.web.servlet.ModelAndView doResolveExceptionInternal​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object handler, java.lang.Exception ex)  
      protected java.util.List<org.springframework.http.MediaType> getAcceptedMediaTypes​(org.springframework.http.HttpInputMessage httpInputMessage)
      Gets accepted media types for HTTP input message.
      org.springframework.http.converter.HttpMessageConverter<?>[] getMessageConverters()  
      protected WebserviceErrorFactory getWebserviceErrorFactory()  
      void init()
      Sets default order for bean if other custom order was not set.
      void setMessageConverters​(org.springframework.http.converter.HttpMessageConverter<?>[] messageConverters)  
      void setOrder​(int order)  
      void setWebserviceErrorFactory​(WebserviceErrorFactory webserviceErrorFactory)  
      protected boolean shouldDisplayStack​(java.lang.Exception ex)
      Calculates boolean value used to determine if exception stacktrace should be logged.
      protected org.springframework.web.servlet.ModelAndView writeWithMessageConverters​(java.lang.Object returnValue, org.springframework.http.HttpInputMessage inputMessage, org.springframework.http.HttpOutputMessage outputMessage)
      Writes HTTP input message into HTTP output message.
      • Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver

        buildLogMessage, doResolveException, getOrder, hasHandlerMappings, logException, prepareResponse, preventCaching, resolveException, setMappedHandlerClasses, setMappedHandlers, setPreventResponseCaching, setWarnLogCategory, shouldApplyTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • UNDEFINED_ERROR_STATUS

        protected static final int UNDEFINED_ERROR_STATUS
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractRestHandlerExceptionResolver

        public AbstractRestHandlerExceptionResolver()
    • Method Detail

      • calculateStatusFromException

        protected int calculateStatusFromException​(java.lang.Exception ex)
        Calculates HTTP status code.
        Parameters:
        ex - exception object
        Returns:
        HTTP status code
      • shouldDisplayStack

        protected boolean shouldDisplayStack​(java.lang.Exception ex)
        Calculates boolean value used to determine if exception stacktrace should be logged.
        Parameters:
        ex - exception object
        Returns:
        information if exception stacktrace should be logged or not
      • init

        @PostConstruct
        public void init()
        Sets default order for bean if other custom order was not set.
      • doResolveExceptionInternal

        protected org.springframework.web.servlet.ModelAndView doResolveExceptionInternal​(javax.servlet.http.HttpServletRequest request,
                                                                                          javax.servlet.http.HttpServletResponse response,
                                                                                          java.lang.Object handler,
                                                                                          java.lang.Exception ex)
      • convertException

        protected ErrorListWsDTO convertException​(java.lang.Exception ex)
        Converts Exception object into list of ErrorWsDTO.
        Parameters:
        ex - exception object
        Returns:
        Object with list of ErrorWsDTO
      • writeWithMessageConverters

        protected org.springframework.web.servlet.ModelAndView writeWithMessageConverters​(java.lang.Object returnValue,
                                                                                          org.springframework.http.HttpInputMessage inputMessage,
                                                                                          org.springframework.http.HttpOutputMessage outputMessage)
                                                                                   throws java.io.IOException
        Writes HTTP input message into HTTP output message. HTTP input message is converted using one converter from list of HttpMessageConverter.
        Parameters:
        returnValue - object to which should be HTTP input message converted
        inputMessage - object for conversion
        outputMessage - object for which converted value is written
        Returns:
        ModelAndView object with converted HTTP input message
        Throws:
        java.io.IOException
      • getAcceptedMediaTypes

        protected java.util.List<org.springframework.http.MediaType> getAcceptedMediaTypes​(org.springframework.http.HttpInputMessage httpInputMessage)
        Gets accepted media types for HTTP input message.
        Parameters:
        httpInputMessage - HTTP input message
        Returns:
        list of accepted media types for HTTP input message
      • setOrder

        public void setOrder​(int order)
        Overrides:
        setOrder in class org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
      • getMessageConverters

        public org.springframework.http.converter.HttpMessageConverter<?>[] getMessageConverters()
      • setMessageConverters

        public void setMessageConverters​(org.springframework.http.converter.HttpMessageConverter<?>[] messageConverters)
      • setWebserviceErrorFactory

        public void setWebserviceErrorFactory​(WebserviceErrorFactory webserviceErrorFactory)