Multiple ActionHandler not recognise when using gwtp-dispatch-server-spring-0.7

171 views
Skip to first unread message

Marc-Andre Vanier

unread,
Oct 14, 2012, 11:24:02 PM10/14/12
to gwt-pl...@googlegroups.com
Hi, 
 
I started a Maven, Spring, GWTP project based on gwtp-sample-basic-spring. I 
added new actions, results, handlers, mapped it in ServerModule. I am stuck 
with an application that the only possible action is to sign in. Every other 
server call gives me an 500 error. 
 
The only error message I see is: 
00:01:34.384 [INFO] (AuditTrailsPresenter.java:110) 2012-10-12 14:18:32,370 
[DEBUG] onFailure() - 500 The call failed on the server; see server log for 
details 
 
I played a lot with the files and configuration and when I comment out the 
working handler, I receive this error message with a long stack trace in the 
eclipse console: 
[ERROR] com.gwtplatform.dispatch.shared.UnsupportedActionException: No 
handler is registered for audit.shared.action.LoginAction 
 
No error message is displayed when removing the other action handlers. 
 
What am I doing wrong? Or can I turn the log on with a special command? 
 
I posted this post in gwt-dispatch and was redirected to this group.
Thanks, 
Marc-Andre 
 
 web.xml
 ------ 
 <!-- GWT-Dispatch Spring --> 
 <servlet> 
 <servlet-name>dispatch</servlet-name> 
 <servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class> 
 <load-on-startup>1</load-on-startup> 
 </servlet> 
 
 applicationContext.xml 
 --------------------------------- 
 <context:component-scan 
 base-package="com.gwtplatform.dispatch.server.spring"/> 
 <context:annotation-config/> 
 
 <!-- GWT Service Beans --> 
 <bean class="audit.server.ServerModule"/> 
 
 
 ServerModule.java 
 -------------------------- 
 /** 
  * Module which binds the handlers and configurations. 
  */ 
 @Configuration 
 @Import(DefaultModule.class) 
 public class ServerModule extends HandlerModule { 
 
 public ServerModule() { 
 } 
 
 @Bean 
 public LoginHandler getLoginHandler() { 
 return new LoginHandler(); 
 } 
 
 @Bean 
 public RetrieveAuditTrailHandler getRetrieveAuditTrailHandler() { 
 return new RetrieveAuditTrailHandler(); 
 } 
 
 @Bean 
 public ActionValidator getDefaultActionValidator() { 
 return new DefaultActionValidator(); 
 } 
 
 protected void configureHandlers() { 
 bindHandler(LoginAction.class, LoginHandler.class); 
 bindHandler(RetrieveAuditTrailListAction.class, 
 RetrieveAuditTrailHandler.class); 
 bindHandler(TestAction.class, TestActionActionHandler.class, 
 LoggedInActionValidator.class); 
 } 
 
 @Bean 
 public TestActionActionHandler getTestActionActionHandler() { 
 return new TestActionActionHandler(); 
 } 
 } 
 
 
 Service call in a presenter 
 ------------ 
 getDispatcher().execute(new TestAction("test"), new 
 AsyncCallback<TestActionResult>() { 
 
 @Override 
 public void onFailure(Throwable caught) { 
 // TODO Auto-generated method stub 
 Log.debug("TestAction failure!"); 
 } 
 
 @Override 
 public void onSuccess(TestActionResult result) { 
 // TODO Auto-generated method stub 
 Log.debug("TestAction successful!"); 
 } 
 }); 
 
 Non Working Handler 
 ------------------ 
 public class RetrieveAuditTrailHandler extends 
 AbstractActionHandler<RetrieveAuditTrailListAction, 
 RetrieveAuditTrailListResult> {  
 
 @Autowired 
 AuditTrailService auditTrailService; 
 
 // @Inject 
 public RetrieveAuditTrailHandler() { 
 super(RetrieveAuditTrailListAction.class); 
 } 
 
 @Override 
 public RetrieveAuditTrailListResult execute(RetrieveAuditTrailListAction 
 action, ExecutionContext context) throws ActionException { 
 List<AuditTrail> audits = 
 auditTrailService.retrieve(action.getFirstResult(), action.getMaxResults()); 
 
 List<AuditTrailDto> results = new ArrayList<AuditTrailDto>(); 
 
 for (AuditTrail auditTrail : audits) { 
 AuditTrailDto dto = new AuditTrailDto(); 
 dto.setId((String) auditTrail.get("_id")); 
 dto.setApplicationName((String) auditTrail.get("applicationName")); 
 dto.setServerNode((String) auditTrail.get("serverNode")); 
 dto.setEventName((String) auditTrail.get("eventName")); 
 dto.setObjectId((String) auditTrail.get("ojectId")); 
 dto.setFilename((String) auditTrail.get("filename")); 
 dto.setDescription((String) auditTrail.get("description")); 
 } 
 
 return new RetrieveAuditTrailListResult(results); 
 } 
 
 @Override 
 public Class<RetrieveAuditTrailListAction> getActionType() { 
 return RetrieveAuditTrailListAction.class; 
 } 
 
 @Override 
 public void undo(RetrieveAuditTrailListAction action, 
 RetrieveAuditTrailListResult result, ExecutionContext context) 
 throws ActionException { 
 // Do nothing 
 } 
 } 
 
 Working Handler 
 ------------------------ 
 public class LoginHandler extends AbstractActionHandler<LoginAction, 
 LoginResult> { 
 
   @Autowired 
   private ServletContext servletContext; 
 
   @Autowired 
   UserService userService; 
 
   public LoginHandler() { 
 super(LoginAction.class); 
   } 
 
   @Override 
   public LoginResult execute(final LoginAction action, final 
 ExecutionContext context) throws ActionException { 
 
     LoginResult result = null; 
 
     try { 
       User user = userService.retrieveUser(action.getLogin()); 
 
       if (user != null && isValidLogin(action, user)) { 
 
      servletContext.setAttribute("login.authenticated", action.getLogin()); 
 
     String sessionKey = UUID.randomUUID().toString(); 
     servletContext.setAttribute("sessionId", UUID.randomUUID()); 
 
         result = new LoginResult(sessionKey); 
 
         Log.debug(action.getLogin() + " has logged in"); 
         Log.debug("Session key: " + result.getSessionKey()); 
       } 
       else { 
         throw new LoginException("Invalid User name or Password."); 
       } 
     } 
     catch (Exception e) { 
 
       // log the stack trace 
       StringWriter stringWriter = new StringWriter(); 
       PrintWriter printWriter = new PrintWriter(stringWriter); 
       e.printStackTrace(printWriter); 
 
       Log.debug("Exception e: " + stringWriter.toString()); 
       // Log.debug("e: " + e); 
 
       throw new ActionException(e); 
     } 
 
     return result; 
   } 
 
   private Boolean isValidLogin(LoginAction action, User user) { 
     Log.debug("LoginHandler - hash: " + " password: " + user.getPassword()); 
 
     return true; 
   } 
 
   @Override 
   public Class<LoginAction> getActionType() { 
     return LoginAction.class; 
   } 
 
   @Override 
   public void undo(LoginAction action, LoginResult result, 
       ExecutionContext context) throws ActionException { 
   } 
 } 

Christian Goudreau

unread,
Oct 15, 2012, 12:19:30 PM10/15/12
to gwt-pl...@googlegroups.com, mrabti...@arcbees.com
Driss, can you answer this question please? (He's the Spring pro :D)

--
 
 



--
Christian Goudreau

Mrabti idriss

unread,
Oct 15, 2012, 12:40:49 PM10/15/12
to gwt-pl...@googlegroups.com
Hello,

Have you declared the RequestContextListener in your web.xml, if not please add the following lines : 

<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

Have you executed your code in debug mode, maybe the service in your Handler is not correctly injected.
This also will help to be sure that the Handler is executed and there is something inside it causing the issues.

The handler seems to be correct, but a debug mode will help you to find where it is stuck.

Marc-Andre Vanier

unread,
Oct 15, 2012, 4:39:42 PM10/15/12
to gwt-pl...@googlegroups.com
By Adding the RequestContextListener in web.xml, all my handlers are now working. 

Thanks,
Marc-André
Reply all
Reply to author
Forward
0 new messages