0

如何在 Errai 服务实现(服务器端)中注入 HttpServletRequest 以用于如下代码:

@Override
public void login(String username, String password, boolean rememberMe) {
    try {
        HttpServletRequest request = null; // <---- Inject here...
        String host = request.getRemoteHost();
        UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe, host);
        try {
            Subject subject = SecurityUtils.getSubject();
            loginWithNewSession(token, subject);
            subject.login(token);
        } catch (AuthenticationException e) {
            throw new IllegalArgumentException("Service could not authenticate caller with the given authorization credentials.");
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new IllegalArgumentException("Something went wrong with the login request");
    }       
}
4

1 回答 1

1

RpcContext.getServletRequest()在这种情况下,您可以使用静态方法。在内部,它从 ThreadLocal Message 对象中检索 HttpServletRequest。

于 2013-07-30T15:27:53.750 回答