簡體   English   中英

在方法體內注入HttpServletRequest(Errai服務實現)

[英]Inject HttpServletRequest inside method body (Errai service implementation)

如何在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");
    }       
}

在這種情況下,可以使用靜態方法RpcContext.getServletRequest() 在內部,它從ThreadLocal Message對象檢索HttpServletRequest。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM