GWT Dispatch & Session Access without guice or spring

22 views
Skip to first unread message

Kay Hellmich

unread,
Mar 25, 2015, 4:03:13 PM3/25/15
to gwt-di...@googlegroups.com
Hi,
I'm new to gwt-dispatch and try to use gwt-dispatch 1.2 to simplify service calls. However I cannot get access to the session up and running.
I'm trying a simplified "Helloworld".
I read a lot about solutions with spring and guice, however I don't know these concepts and wonder if there's an easier way as a starting point.
Also -neither for juice nor for spring- I found full working examples, just snippets that don't allow me to get to a working service.
Could someone tell me what I need to add or - if there's no simple solution without guice/spring - can post a fully working version of some dispatcher code (with imports / additional libraries) that allows session access?
many thanks
Kay


DispatchService: (working so far)
public class RPCDispatchService extends RemoteServiceServlet implements StandardDispatchService {

    private static final long serialVersionUID = 1L;
    private Dispatch dispatch;
    private HttpSession session;
    public RPCDispatchService() {
        InstanceActionHandlerRegistry registry = new DefaultActionHandlerRegistry();
        registry.addHandler(new RPCSomeAction2SomeResultExecutor()); // call my testservice here
        this.dispatch = new SimpleDispatch(registry);
    }
    
    public Result execute(Action<?> action) throws DispatchException {
        this.session = this.getThreadLocalRequest().getSession();
        this.session.setAttribute("answer", 42);
        try {
            return dispatch.execute(action);
        } catch ( RuntimeException e) {
            log( "Exception while executing " + action.getClass().getName() + ": " + e.getMessage(), e );
            throw e;
        }
    }
}


TestService: (no session available)

public class RPCSomeAction2SomeResultExecutor implements ActionHandler<SomeAction, SomeResult>{
    private int result = 0;
    public Class<SomeAction> getActionType() {

        return SomeAction.class;
    }
    public synchronized SomeResult execute( SomeAction action, ExecutionContext context ) throws ActionException {
        result = action.getParameter() + 1; // the Action is an Incrementer...
        if (this.getThreadLocalRequest().getSession() == null) // not available because i'm not a servlet
            result = -1; 
else
    result = (int) this.httpSession.get().getAttribute("answer"); // how do i get access to the session?
            return new SomeResult( action.getParameter(), result );

}
public synchronized void rollback( SomeAction action, SomeResult result, ExecutionContext context ) throws ActionException {
}
    }    
}

Juan Pablo Gardella

unread,
Mar 25, 2015, 4:13:23 PM3/25/15
to gwt-di...@googlegroups.com

--

---
You received this message because you are subscribed to the Google Groups "GWT Dispatch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gwt-dispatch...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages