系统要求在后台写一个定时退出任务,使用token从远程获取用户信息,有一个问题就是我需要在后台写一个定时退出任务,我的token应该怎么存呢?String _token = SysLoginController.loginToken;这样存静态变量的只能存一个,或者用静态变量list之类,怎么去标识呢?一开始没想好,以为可以获取到session,但是后来发现没有定时器中无法获取req、resp这些东西,这下苦恼了,不知道怎么弄了,求大神指点迷津
System.err.println("=====后台检测token====开始检测token=========");
String _token = SysLoginController.loginToken;
//Object _token = session.getAttribute("token");
String token = _token.toString();
StringBuffer buffer = new StringBuffer();
String url = "http://172.16.64.72:8090/bam/identity/json/attributes?subjectid="+token;
URI uri = new URI(url);
URL urls = uri.toURL();
HttpURLConnection connection = (HttpURLConnection) urls.openConnection();
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Charset", "utf-8");
connection.setRequestMethod("GET");
connection.connect();
int responseCode = connection.getResponseCode();
if(responseCode==401 || responseCode!=200){
//loginController.logout();
loginController.doOut();
}else{
InputStream inputStream = connection.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String str = null;
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
bufferedReader.close();
inputStreamReader.close();
// 释放资源
inputStream.close();
connection.disconnect();
String str1 = buffer.toString();
System.err.println(str1);
JSONObject jsonObject = new JSONObject(str1);
JSONArray attributes = jsonObject.getJSONArray("attributes");
String s = attributes.get(0).toString();
JSONObject jsonObject1 = new JSONObject(s);
JSONArray values = jsonObject1.getJSONArray("values");
Object username = values.get(0);
if (null==username){
loginController.doOut();
}
}