モジュール jp.ecuacion.splib.web

クラス SplibExceptionHandler

java.lang.Object
jp.ecuacion.splib.web.exceptionhandler.SplibExceptionHandler
直系の既知のサブクラス:
SplibJpaExceptionHandler

public abstract class SplibExceptionHandler extends Object
  • ネストされたクラスの概要

    ネストされたクラス
    修飾子とタイプ
    クラス
    説明
    static class 
    NotEmptyの効率的な実装のために動的なNotEmptyの適用(BaseRecordに@NotEmptyを記載しておき、何らかの条件でそれをactiveにする形)を検討したが、 結果不可であることがわかった。
  • フィールドの概要

    フィールド
    修飾子とタイプ
    フィールド
    説明
    static final String
     
  • コンストラクタの概要

    コンストラクタ
    コンストラクタ
    説明
     
  • メソッドの概要

    修飾子とタイプ
    メソッド
    説明
     
    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
    handleObjectOptimisticLockingFailureException(org.springframework.orm.ObjectOptimisticLockingFailureException exception, org.springframework.security.core.userdetails.UserDetails loginUser)
    楽観的排他制御の処理。
    org.springframework.web.servlet.ModelAndView
    handlePessimisticLockingFailureException(org.springframework.dao.PessimisticLockingFailureException exception, org.springframework.security.core.userdetails.UserDetails loginUser)
     
    org.springframework.web.servlet.ModelAndView
    handleThrowable(Throwable exception, org.springframework.ui.Model model)
    WebでConstraintViolationExceptionが直接上がってくる場面は、事前のチェックが漏れた場合であり、 この場合は単体のConstraintViolationExceptionしか取得できないこともあり正しくないため、実装不備とみなしここに入れることとする。

    クラスから継承されたメソッド java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • フィールド詳細

  • コンストラクタの詳細

    • SplibExceptionHandler

      public SplibExceptionHandler()
  • メソッドの詳細

    • 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
      例外:
      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
      例外:
      Exception
    • handleObjectOptimisticLockingFailureException

      @ExceptionHandler(org.springframework.orm.ObjectOptimisticLockingFailureException.class) public org.springframework.web.servlet.ModelAndView handleObjectOptimisticLockingFailureException(org.springframework.orm.ObjectOptimisticLockingFailureException exception, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails loginUser) throws Exception
      楽観的排他制御の処理。 画面表示〜ボタン押下の間にレコード更新された場合は、手動でチェックなので直接BizLogicAppExceptionを投げても良いのだが、 複数sessionで同一レコードを同時更新した場合(service内の処理内でのselectからupdateの間に別sessionがselect〜updateを完了)は JPAが自動でObjectOptimisticLockingFailureExceptionを投げてくるので、それも同様に処理できるよう楽観的排他制御エラーは ObjectOptimisticLockingFailureExceptionで統一しておく。 尚、jpa以外でも、jdbcやfileでのlockでも同様の事象があるので全て統一しObjectOptimisticLockingFailureExceptionを使用するものとする。
      例外:
      Exception
    • handlePessimisticLockingFailureException

      @ExceptionHandler(org.springframework.dao.PessimisticLockingFailureException.class) public org.springframework.web.servlet.ModelAndView handlePessimisticLockingFailureException(org.springframework.dao.PessimisticLockingFailureException exception, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails loginUser) throws Exception
      例外:
      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()); }

      例外:
      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
      例外:
      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。
      例外:
      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しか取得できないこともあり正しくないため、実装不備とみなしここに入れることとする。