gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 14:17:56 24 4
gpt4 key购买 nike

如何在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com