用java实现QQ登录授权时报错

maketc 发布于 2013/12/09 17:58
阅读 2K+
收藏 0

用java实现QQ登录授权时,跳转到http://zhiqc.com/?code=F5D13DD6815D33F7A9FCD38C4C57D46D后,进入方法

public String qqLogin(ModelMap modelMap,HttpServletRequest request, HttpServletResponse response) {
		try {
			System.out.println(request.getParameter("code"));
			AccessToken accessTokenObj = new Oauth().getAccessTokenByRequest(request);
			String accessToken = null,
					openID = null;
			long tokenExpireIn = 0l;
			if (accessTokenObj.getAccessToken().equals("")) {
				try {
					throw new Exception("没有获取到Authorization Code");
				} catch (Exception e) {
					e.printStackTrace();
				}
			} else {
				accessToken = accessTokenObj.getAccessToken();
				tokenExpireIn = accessTokenObj.getExpireIn();
				OpenID openIDObj = new OpenID(accessToken);
				openID = openIDObj.getUserOpenID();
				request.getSession().setAttribute("openID", openID);
				UserInfo qzoneUserInfo = new UserInfo(accessToken, openID);
				UserInfoBean userInfoBean = qzoneUserInfo.getUserInfo();
				request.getSession().setAttribute("qqUserInfo", userInfoBean);
				request.getSession().setAttribute("user", new Usr(userInfoBean.getLevel(), openID));
			}
		} catch (QQConnectException e) {
			e.printStackTrace();
		}
		return "redirect:default.html";
	}



在运行到AccessToken accessTokenObj = new Oauth().getAccessTokenByRequest(request);时报错,如下

2013-12-9 17:46:22 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet mvc-dispatcher threw exception
java.lang.NullPointerException
	at java.util.Properties$LineReader.readLine(Properties.java:418)
	at java.util.Properties.load0(Properties.java:337)
	at java.util.Properties.load(Properties.java:325)
	at com.qq.connect.utils.QQConnectConfig.<clinit>(QQConnectConfig.java:21)
	at com.qq.connect.utils.Version.<clinit>(Version.java:15)
	at com.qq.connect.utils.Configuration.init(Configuration.java:33)
	at com.qq.connect.utils.Configuration.<clinit>(Configuration.java:20)
	at com.qq.connect.utils.http.HttpClient.<clinit>(HttpClient.java:110)
	at com.qq.connect.QQConnect.<init>(QQConnect.java:15)
	at com.qq.connect.oauth.Oauth.<init>(Oauth.java:20)
	at com.zhiqingchun.web.login.QQLoginController.qqLogin(QQLoginController.java:27)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:662)



我怀疑是没有读到qqconnectconfig.properties文件,但这个文件我是放在src文件夹下面的,应该可以读啊

加载中
0
H
HelloWorld_1

不知道你解决这个问题没,你要把qqconnectconfig.properties文件放到WEB-INF文件夹下的classes文件中。才能识别。

话说,解决了这个空指针问题,我进入了“没有获取到Authorization Code”的if分支。。。

肿么办?有什么建议不?
返回顶部
顶部