我这样获取的时候会报request为null,求大神指点
@IocBean
public class LoginOutJob implements Job {
@Inject
private SysLoginController loginController;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
ActionContext actionContext = new ActionContext();
HttpServletRequest request = actionContext.getRequest();
HttpSession session = request.getSession();
checkLoginOut(session);
}
public void checkLoginOut(HttpSession session){
try {
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();
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.logout();
}
} catch (URISyntaxException e) {
e.printStackTrace();
loginController.logout();
} catch (IOException e) {
e.printStackTrace();
loginController.logout();
}catch (Exception e){
e.printStackTrace();
loginController.logout();
}
}
}
java.lang.NullPointerException
at cn.wizzer.app.web.commons.quartz.job.LoginOutJob.execute(LoginOutJob.java:31)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
[ERROR] 2018-04-13 16:11:30,080 org.quartz.core.ErrorLogger.schedulerError(QuartzScheduler.java:2425) - Job (logoutGroup.logout threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NullPointerException]
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: java.lang.NullPointerException
at cn.wizzer.app.web.commons.quartz.job.LoginOutJob.execute(LoginOutJob.java:31)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
... 1 more