Struts 2 + Spring - Interceptors - Bean Null
Bonjour à tous,
Petit problème sur lequel je m'acharne depuis plusieurs jours. J'utilise les frameworks Struts 2 + Spring 2 + JPA
J'ai 1 action pour m'authentifier. J'injecte un bean via Spring et cela fonctionne très bien.
J'essaye maintenant de créer un interceptor pour dissocier la validation de la saisie et l’accès à la base de donnée.
Voici un résumé de l'interceptor
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
public class AuthenticationInterceptor extends ActionSupport implements Interceptor {
private AccountBean accountBean;
@Override
public String intercept(ActionInvocation invocation) throws Exception {
Log.debug("----- Email : " + accountBean.getEmail());
Log.debug("----- Password : " + accountBean.getPassword());
String returnResult = Action.LOGIN;
try {
if (accountBean.getEmail().isEmpty() || accountBean.getPassword().isEmpty()) {
throw new ServiceNoResultException();
} else {
returnResult = invocation.invoke();
}
} catch (NullPointerException ex) {
ex.printStackTrace();
addActionError(getText("verification.connexion.errorLogIn"));
} catch (ServiceNoResultException ex) {
ex.printStackTrace();
addActionError(getText("verification.connexion.errorLogIn"));
} catch (Exception ex) {
ex.printStackTrace();
addActionError(getText("verification.connexion.error"));
} finally {
return returnResult;
}
public AccountBean getAccountBean() {
return accountBean;
}
public void setAccountBean(AccountBean accountBean) {
this.accountBean = accountBean;
}
} |
J'ai mis à jour applicationcontext.xml de la manière suivante :
Code:
1 2 3 4 5 6
|
<bean id="accountBean" class ="beans.AccountBean" />
<bean id="authentificationInterceptor" class="interceptors.AuthenticationInterceptor" >
<property name="accountBean" ref="accountBean" />
</bean> |
Et enfin j'inject dans struts.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
<interceptors>
<interceptor name="authenticationIntercept" class="authentificationInterceptor" />
<interceptor-stack name="newStack">
<interceptor-ref name="basicStack"/>
<interceptor-ref name="authenticationIntercept"/>
</interceptor-stack>
</interceptors>
<action name="authentificationAccount" class="accountAction" method="authentification" >
<interceptor-ref name="newStack"/>
<result name="login"> //jsp/loginCheckFailed.jsp </result>
<result name="success" type="redirectAction"> displayInformationMember.action </result>
</action> |
Et malheureusement j'ai en permanence l'erreur suivante
Code:
1 2 3 4 5
|
INFO: DEBUG:----- AuthenticationInterceptor Email : null
INFO: DEBUG:----- AuthenticationInterceptor Password : null
GRAVE: java.lang.NullPointerException
at interceptors.AuthenticationInterceptor.intercept(AuthenticationInterceptor.java:32) |
Dans le lien suivant le membre parlait d'un problème de scope. J'ai essayé dans tous les sens mais rien n'y fait.
http://www.developpez.net/forums/d11...n-interceptor/
Le plus étrange c'est quand je fais tout le traitement dans l'action (Sans intercepteur) j’accède bien au bean et tout fonctionne.
Si vous avez une idée je suis preneur .
Merci d'avance