J'ai donc une application Struts2 sur laquelle je travaille. Sur ma page d'accueil, j'ai une section qui affiche toutes les exceptions que mon application lance. Cela a bien fonctionné jusqu'à ce que j'ajoute un Interceptor personnalisé.Struts2 L'application cache mes exceptions après l'ajout d'Interceptor
Voici mon code Interceptor:
public String intercept(ActionInvocation actionInvocation) throws Exception {
String result = actionInvocation.invoke();
return result;
}
Voici le code dans ma classe d'action où l'exception est généré, il se produit où AuthService.Authorize() est appelée:
if(AuthService.Authorize(username, password)) {
if(AuthService.AdminAuthorized()) {
return "admin";
}
return SUCCESS;
}
Cette est à l'intérieur de AuthService.Authorize(), il déclenche une exception de point nul lorsque acc est accédé:
try {
acc = profileRepository.WhereSingle("Username", "=", username);
} catch (Exception e) {
return false;
}
if (acc.Password.equals(password)) {
Cependant, lorsque la page est chargée. Ce n'est pas remplie:
<s:property value="%{exception.message}"/>
Je l'ai testé et cela fonctionnerait si je jetais simplement une exception de la classe d'action. Je ne demande pas un redirectAction ou quoi que ce soit
Voici le haut de ma définition de package par défaut qui tous mes autres paquets s'étendent
<package name="default" namespace="/" extends="struts-default">
<!-- Interceptors -->
<interceptors>
<interceptor name="conversation" class="global.ConversationInterceptor"/>
<interceptor-stack name="dils-stack">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="conversation"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="dils-stack"/>
<global-results>
<result name="Exception" >/index.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="Exception"/>
<exception-mapping exception="java.lang.NullPointerException" result="Exception"/>
</global-exception-mappings>
voir ci-dessus, merci. – WSkinner
Confirmé avec Struts 2.2.1 sur Tomcat 6.x. –