Domanda

I am new to GWTP. I am trying to build an application using GWTP + Command Pattern + Spring.

Currently my application has a login page using Spring controller, which redirects user to GWT page. In spring controllers we can access session as we have access to HttpRequest object. In case of GWTP Command Handler, I cannot find any way to access HttpSession. Following is my Command Handler code -

public class GetItemsCommandHandler extends AbstractActionHandler<GetItemsCommand, GetItemsResult>{

    @Autowired
    private ItemService itemService;

    public GetItemsCommandHandler() {
        super(GetItemsCommand.class);
    }

    @Override
    public GetItemsResult execute(GetItemsCommand action, ExecutionContext context) throws ActionException {
        // How to get User info(userid) from session??
        GetItemsResult getItemsResult = new GetItemsResult();
        getItemsResult.setItems(itemService.getItemsForUser(userId));
        return getItemsResult;
    }

}

Is there any way I can access HttpSession from a GWTP Command Handler?

È stato utile?

Soluzione

Thanks @Baadshah but I am using Spring on the server side. By the way I got the solution and I am posting if someone is facing similar problem.

First we need to add following entry in web.xml

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

RequestContextListener is a listener that exposes the request to the current thread.

and then we can use @Autowired annotation.

@Autowired
private HttpServletRequest httpServletRequest;

and in processing method we can session from this httpServletRequest using getSession method.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top