java - 在方法体中注入(inject) HttpServletRequest(Errai 服务实现)

标签 java gwt errai

如何在 Errai 服务实现(服务器端)中注入(inject) 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");
    }       
}

最佳答案

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

关于java - 在方法体中注入(inject) HttpServletRequest(Errai 服务实现),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17936923/

相关文章:

java - 使用 JPA 在浏览器存储中持久保存第 3 方实体

java - Math.ceil() 方法不适用于 double 值

gwt - 将不同 GWT 事件所需的状态放在哪里?

java - NoClassDefFoundError : javax/inject/Provider and ClassNotFoundException: javax. 注入(inject).Provider

GWTP 获取从子演示者/ View 到父演示者/ View 的访问权限

apache - 在 Apache Web 服务器上运行 Gwt 应用程序

java - 在 SuperDevMode (Maven) 中运行时出错

java - 如何在for循环中跳出while循环

java - Controller 未重定向到我的 jsp

java - 如何访问 NAT 路由器后面的 ServerSocket?