Sanjay Jain
Sanjay Jain

Reputation: 3587

Server side session management in GWTP

Hello I am using GWTP for my application development. In the application I am in need to server side session instance to put some data in that session instance. I saw some examples of GWT where there is Action class which extends ActionSupport class. There are some method in the examples through which we can have the server side session instance.Like below :

public HttpServletRequest getRequest() {
        return ServletActionContext.getRequest();
    }

public HttpServletResponse getResponse() {
    return ServletActionContext.getResponse();
}

public HttpSession getSession() {
    HttpSession session = getRequest().getSession();
    return session;
}

But I am not getting the similar thing in GWTP. Please help me out. Thanks in Advance.

Upvotes: 3

Views: 2388

Answers (2)

Sanjay Jain
Sanjay Jain

Reputation: 3587

Finally I got some thing which is helping me.I am sharing this here.

private Provider<HttpServletRequest> requestProvider;
private ServletContext servletContext;


@Inject
public LoginCallerActionHandler(
        Provider<HttpServletRequest> requestProvider,
        ServletContext servletContext) {
    super();
    this.requestProvider = requestProvider;
    this.servletContext = servletContext;
}

Here is my action handler class.In which i can use session.

servletContext.setAttribute(SessionKeys.LOGGEDIN_USER.toString(), returnObject.getLoggedInUser());

Upvotes: 4

Tahir Akhtar
Tahir Akhtar

Reputation: 11625

If you are using Spring or Guice on your server side you can get Request/Response injected into your Action. For example, if your are using GWTP's DispatchServletModule, you can use features of Guice's ServletModule as:

DispatchServletModule extends Guice ServletModule and maps request URLs to handler classes.

Here's an example from Guice wiki:

@RequestScoped
class SomeNonServletPojo {

  @Inject
  SomeNonServletPojo(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
    ...
  }

}

I am not sure if GWTP binds the handlers in Singleton scope or not. If it does bind it in singleton you should inject a Provider instead.

Upvotes: 1

Related Questions