2013-07-30 55 views
0

如何注入的HttpServletRequest在Errai服務實現(服務器端)爲使用如下代碼:進樣HttpServletRequest的方法體(Errai服務實現)內

@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"); 
    }  
} 

回答

1

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

相關問題