Class SplibExceptionHandler

java.lang.Object
jp.ecuacion.splib.web.exceptionhandler.SplibExceptionHandler

public abstract class SplibExceptionHandler extends Object
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    NotEmptyの効率的な実装のために動的なNotEmptyの適用(BaseRecordに@NotEmptyを記載しておき、何らかの条件でそれをactiveにする形)を検討したが、 結果不可であることがわかった。
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    org.springframework.web.servlet.ModelAndView
    handleAppException(jp.ecuacion.lib.core.exception.checked.AppException exception, org.springframework.security.core.userdetails.UserDetails loginUser)
     
    org.springframework.web.servlet.ModelAndView
    handleAppWarningException(jp.ecuacion.lib.core.exception.checked.AppWarningException exception, org.springframework.security.core.userdetails.UserDetails loginUser)
     
    handleHttpRequestMethodNotSupportedException(org.springframework.web.HttpRequestMethodNotSupportedException exception, org.springframework.ui.Model model)
     
    org.springframework.web.servlet.ModelAndView
    handleInputValidationException(InputValidationException exception, org.springframework.security.core.userdetails.UserDetails loginUser)
    本来はspring mvcのvalidationに任せれば良いのだが、以下の2点が気に入らず、springで持っているerror情報(*)を    * 修正しようとしたが「unmodifiablelist」で修正できなかったため、やむなく個別の処理を作成。
    void
    handleNoResourceFoundException(org.springframework.web.servlet.resource.NoResourceFoundException exception, org.springframework.ui.Model model)
    HTTP 404。
    org.springframework.web.servlet.ModelAndView
    handleOptimisticLockingFailureException(OverlappingFileLockException exception, org.springframework.security.core.userdetails.UserDetails loginUser)
     
    org.springframework.web.servlet.ModelAndView
    handleThrowable(Throwable exception, org.springframework.ui.Model model)
    WebでConstraintViolationExceptionが直接上がってくる場面は、事前のチェックが漏れた場合であり、 この場合は単体のConstraintViolationExceptionしか取得できないこともあり正しくないため、実装不備とみなしここに入れることとする。

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • SplibExceptionHandler

      public SplibExceptionHandler()
  • Method Details

    • getController

      protected SplibGeneralController<?> getController()
    • handleAppWarningException

      @ExceptionHandler(jp.ecuacion.lib.core.exception.checked.AppWarningException.class) public org.springframework.web.servlet.ModelAndView handleAppWarningException(jp.ecuacion.lib.core.exception.checked.AppWarningException exception, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails loginUser) throws Exception
      Throws:
      Exception
    • handleAppException

      @ExceptionHandler(jp.ecuacion.lib.core.exception.checked.AppException.class) public org.springframework.web.servlet.ModelAndView handleAppException(jp.ecuacion.lib.core.exception.checked.AppException exception, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails loginUser) throws Exception
      Throws:
      Exception
    • handleOptimisticLockingFailureException

      @ExceptionHandler(java.nio.channels.OverlappingFileLockException.class) public org.springframework.web.servlet.ModelAndView handleOptimisticLockingFailureException(OverlappingFileLockException exception, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails loginUser) throws Exception
      Parameters:
      exception -
      loginUser -
      Returns:
      Throws:
      Exception
    • handleInputValidationException

      @ExceptionHandler(InputValidationException.class) public org.springframework.web.servlet.ModelAndView handleInputValidationException(InputValidationException exception, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails loginUser) throws Exception
      本来はspring mvcのvalidationに任せれば良いのだが、以下の2点が気に入らず、springで持っているerror情報(*)を    * 修正しようとしたが「unmodifiablelist」で修正できなかったため、やむなく個別の処理を作成。
      1. 画面上部に複数項目のエラー情報をまとめて表示する場合、並び順が実行するたびに変わる
      2. @Sizeなどのvalidationで、blankを無視する設定になっていないため、 値がblankで、かつblankがエラーのannotationが付加されている場合でも、@Sizeなどのvalidationが走ってしまう。

      尚、controller層でのinput validationが漏れた場合、JPAの仕様によりDBアクセス直前にもう一度validationが行われ、 そこでConstraintViolationExceptionが発生する。 そうなる場合は、事前のチェックが漏れた場合のみであり、また単体のConstraintViolationExceptionしか取得できず、 想定しているエラー表示方法(input validation分はまとめて結果を表示)とは異なり正しくない。 そのため実装不備とみなしシステムエラーとする(=本クラス上で特別扱いはせず、"handleThrowable"methodで拾う)。
      I(*) このような形でspring mvcのerror情報の取得が可能。最後のprintlnではfieldとcode(validator名:"Size"など)を取得している。

      // bean validation標準の各種validatorが、""の場合でもSize validatorのエラーが表示されるなどイマイチ。 // 空欄の場合には空欄のエラーのみを出したいので、同一項目で、NotEmptyと別のvalidatorが同時に存在する場合はNotEmpty以外を間引く。 // spring標準のvalidatorは、model内に以下のようなkey名で格納されているのでkey名を前方一致で取得 // org.springframework.validation.BindingResult.driveRecordEditForm String bindingResultKey = getModel().asMap().keySet().stream() .filter(key -> key.startsWith("org.springframework.validation.BindingResult")) .collect(Collectors.toList()).get(0); BeanPropertyBindingResult bindingResult = (BeanPropertyBindingResult) getModel().asMap().get(bindingResultKey); for (FieldError error : bindingResult.getFieldErrors()) { System.out.println(error.getCode()); System.out.println(error.getField()); }

      Throws:
      Exception
    • handleHttpRequestMethodNotSupportedException

      @ExceptionHandler(org.springframework.web.HttpRequestMethodNotSupportedException.class) public String handleHttpRequestMethodNotSupportedException(org.springframework.web.HttpRequestMethodNotSupportedException exception, org.springframework.ui.Model model) throws jp.ecuacion.lib.core.exception.checked.BizLogicAppException
      Throws:
      jp.ecuacion.lib.core.exception.checked.BizLogicAppException
    • handleNoResourceFoundException

      @ExceptionHandler(org.springframework.web.servlet.resource.NoResourceFoundException.class) public void handleNoResourceFoundException(org.springframework.web.servlet.resource.NoResourceFoundException exception, org.springframework.ui.Model model) throws org.springframework.web.servlet.resource.NoResourceFoundException
      HTTP 404。
      Throws:
      org.springframework.web.servlet.resource.NoResourceFoundException
    • handleThrowable

      @ExceptionHandler(java.lang.Throwable.class) public org.springframework.web.servlet.ModelAndView handleThrowable(Throwable exception, org.springframework.ui.Model model)
      WebでConstraintViolationExceptionが直接上がってくる場面は、事前のチェックが漏れた場合であり、 この場合は単体のConstraintViolationExceptionしか取得できないこともあり正しくないため、実装不備とみなしここに入れることとする。