2012-05-03 12 views
1

私は春のAOPを使用してインターセプタを作成しようとしていました。リクエストURLがブックマークであればインターセプタは見つけられ、そうであれば認証ページにリダイレクトされます。 コードスニペット:AOP-Springインターセプタを使用したBookMarkリダイレクション

パブリックオブジェクトを呼び出し(MethodInvocation呼び出し)がThrowableを{ logger.entering(this.getClass()getSimpleName()、 "呼び出し"、呼び出し)を投げます。予想通り

Object result = null; 
    try { 
     // Logic to exclude the beans as per the list in the configuration. 
     boolean excluded = false; 
     for (String excludebean : excludedBeans) { 
      if (excludebean != null && excludebean.equalsIgnoreCase(invocation.getThis().getClass().getSimpleName())) { 
       excluded = true; 
       break; 
      } 
     } 

     // If the Target Method is "toString", then set EXCLUDE to TRUE and process the request 
     if(excluded == false && invocation.getMethod().getName().equalsIgnoreCase("toString")) 
     { 
      excluded = true; 
     } 

     // if user session object is available, then process the request or 
     // else forward to the configured view. 
     if (excluded || getSessionHolder().getUserVO() != null) { 
      result = invocation.proceed(); 
     } 
     else { 
      logger.logp(Level.INFO, this.getClass().getSimpleName(), 
        "invoke(MethodInvocation)", "User Object is "+ getSessionHolder().getUserVO() 
          + ". So redirecting user to home page"); 
      result = new ModelAndView("redirect:/security/authenticate.do"); 

     } 
    } 
    catch (Throwable ex) { 
     throw ex; 
    } 
    logger.exiting(this.getClass().getSimpleName(), "invoke"); 
    return result; 
} 

私はコントロールをデバッグする他のブロックの中で来るが、私は結果を返した後、制御は、リダイレクトビューのハンドラよりもブックマークのURL ratehrのためのハンドル方法に行きます。

Plsはこれを手伝ってくれます。事前におねがいします。

答えて

1

なぜインターセプタにAOPが必要ですか? Regularインターセプタを使用して簡単にリダイレクトできます。

public class RedirectInterceptor extends HandlerInterceptorAdapter{ 

    private String redirectMapping; 

    public void setRedirectMapping(String redirectMapping) { 
     this.redirectMapping = **maintenanceMapping**; 
    } 


    //before the actual handler will be executed 
    public boolean preHandle(HttpServletRequest request, 
      HttpServletResponse response, Object handler) 
     throws Exception { 
         if (somethingHappened){ 
      response.sendRedirect(redirectMapping); 
      return false; 
         } else 
          return true; 

    } 
} 
+0

ありがとうdanny、これを試してみてください。 – RVP

+0

私はこの方法で試しましたが、私はインターセプタの中にデバッグポイントを持っていますが、コントロールは決して内部にはありません。私はインターセプタをに追加しました..アノテーションベースのURL mapping.plsヘルプを使用しています。 – RVP

+0

あなたのコードと設定を投稿してください。 –

関連する問題