QQ互联回调异常

package com.liuguanlin.travel.controll;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import com.jfinal.log.Log;
import com.liuguanlin.common.core.base.BaseController;
import com.liuguanlin.common.util.ValueUtil;
import com.liuguanlin.travel.service.UserTb;
import com.qq.connect.QQConnectException;
import com.qq.connect.api.OpenID;
import com.qq.connect.api.qzone.UserInfo;
import com.qq.connect.javabeans.AccessToken;
import com.qq.connect.javabeans.qzone.UserInfoBean;
import com.qq.connect.oauth.Oauth;
 

public class AccountController extends BaseController {
 
    private static final Log _log = Log.getLog(AccountController.class);
 
    // 跳转qq登录
    public void qc_login() {
        // 获取session对象
        UserTb userTb = getSessionAttr("user");
         
        //已经登录直接重定向到首页
        if (ValueUtil.isNotEmpty(userTb)) {
            redirect("/");
            return;
        }
         
        // 获取requese对象
        HttpServletRequest request = getRequest();
        // 获取response对象
        HttpServletResponse response = getResponse();
        response.setContentType("text/html;charset=utf-8");
        try {
            response.sendRedirect(new Oauth().getAuthorizeURL(request));
            renderNull();
        } catch (QQConnectException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    // 回调地址
    public void qc_callback() throws Exception {
        try {
            // 获取requese对象
            HttpServletRequest request = getRequest();
 
            // 获取token对象
            AccessToken accessTokenObj = (new Oauth()).getAccessTokenByRequest(request);
 
            // 变量token|openid|tokenExpireIn
            String accessToken = null;
            String openID = null;
            long tokenExpireIn = 0L;
 
            if (ValueUtil.isNotEmpty(accessTokenObj.getAccessToken())) {
                // 获取token
                accessToken = accessTokenObj.getAccessToken();
                tokenExpireIn = accessTokenObj.getExpireIn();
 
                /*--*--*--*--*--*--*--*--*--*--*--*--*--*--*-I'm a gorgeous dividing line-*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*/
 
                // 利用获取到的accessToken 去获取当前用的openid
                OpenID openIDObj = new OpenID(accessToken);
                openID = openIDObj.getUserOpenID();
                _log.info("欢迎你,代号为 " + openID + " 的用户! tokenExpireIn=" + tokenExpireIn);
 
                /*--*--*--*--*--*--*--*--*--*--*--*--*--*--*-I'm a gorgeous dividing line-*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*/
 
                // 利用获取到的accessToken,openid 去获取用户在Qzone的昵称等信息
                UserInfo userInfo = new UserInfo(accessToken, openID);
                UserInfoBean userInfoBean = userInfo.getUserInfo();
 
                // 判断是否获取到了正确的用户信息
                if (userInfoBean.getRet() == 0) {
                    // 操作入库
                    _log.info(toJsonStr(userInfo));
 
                    // 判断是否第一次登录,执行更新或新增用户
                    UserTb userTb = UserTb.add_user(userInfoBean, openID, accessToken);
 
                    // 登录成功回调
                    login_suc_callbcak(userTb);
 
                } else {
                    _log.error("很抱歉,我们没能正确获取到您的信息,原因是: " + userInfoBean.getMsg());
                }
 
            } else {
                // 我们的网站被CSRF攻击了或者用户取消了授权 做一些数据统计工作
                _log.error("没有获取到响应参数");
            }
 
            // 重定向首页
            redirect("/");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    // 登录成功回调地址,操作session
    public void login_suc_callbcak(UserTb userTb) {
        if (ValueUtil.isNotEmpty(userTb)) {
            setSessionAttr("user", userTb);
        }
    }
 
    // 注销
    public void signout() {
        UserTb userTb = getSessionAttr("user");
        if (ValueUtil.isNotEmpty(userTb)) {
            removeSessionAttr("user");
        }
        redirect("/");
    }
 
}

image.png

JFinal action report -------- 2017-06-06 13:13:24 ------------------------------
Url         : GET /qq/qc_callback
Controller  : com.liuguanlin.travel.controll.AccountController.(AccountController.java:1)
Method      : qc_callback
Interceptor : com.jfinal.ext.interceptor.SessionInViewInterceptor.(SessionInViewInterceptor.java:1)
              com.liuguanlin.travel.jfinal.interceptors.ExceptionInterceptor.(ExceptionInterceptor.java:1)
Parameter   : code=E5639F04A2A774643DF06050C70F7DEE  state=5eb8a7cafcd54a1de692c2e35c42b0d1  
--------------------------------------------------------------------------------

2017-06-06 13:13:24[INFO]-[Thread: http-nio-80-exec-52]-[org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry()]: I/O exception (javax.net.ssl.SSLException) caught when processing request: java.security.ProviderException: java.security.KeyException

2017-06-06 13:13:24[INFO]-[Thread: http-nio-80-exec-52]-[org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry()]: Retrying request

2017-06-06 13:13:24[INFO]-[Thread: http-nio-80-exec-52]-[org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry()]: I/O exception (javax.net.ssl.SSLException) caught when processing request: java.security.ProviderException: java.security.KeyException

2017-06-06 13:13:24[INFO]-[Thread: http-nio-80-exec-52]-[org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry()]: Retrying request

2017-06-06 13:13:25[INFO]-[Thread: http-nio-80-exec-52]-[org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry()]: I/O exception (javax.net.ssl.SSLException) caught when processing request: java.security.ProviderException: java.security.KeyException

2017-06-06 13:13:25[INFO]-[Thread: http-nio-80-exec-52]-[org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry()]: Retrying request
com.qq.connect.QQConnectException: java.security.ProviderException: java.security.KeyException
	at com.qq.connect.utils.http.HttpClient.httpRequest(HttpClient.java:364)
	at com.qq.connect.utils.http.HttpClient.post(HttpClient.java:237)
	at com.qq.connect.oauth.Oauth.getAccessTokenByRequest(Oauth.java:84)
	at com.liuguanlin.travel.controll.AccountController.qc_callback(AccountController.java:62)
	at sun.reflect.GeneratedMethodAccessor38.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:73)
	at com.liuguanlin.travel.jfinal.interceptors.ExceptionInterceptor.intercept(ExceptionInterceptor.java:25)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
	at com.jfinal.ext.interceptor.SessionInViewInterceptor.intercept(SessionInViewInterceptor.java:44)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
	at com.jfinal.core.ActionHandler.handle(ActionHandler.java:78)
	at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:74)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1757)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1716)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: javax.net.ssl.SSLException: java.security.ProviderException: java.security.KeyException
	at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
	at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1916)
	at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1874)
	at sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1857)
	at sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1783)
	at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:127)
	at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
	at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
	at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:506)
	at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2114)
	at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
	at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
	at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
	at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
	at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
	at com.qq.connect.utils.http.HttpClient.httpRequest(HttpClient.java:337)
	... 31 more
Caused by: java.security.ProviderException: java.security.KeyException
	at sun.security.ec.ECKeyPairGenerator.generateKeyPair(ECKeyPairGenerator.java:146)
	at java.security.KeyPairGenerator$Delegate.generateKeyPair(KeyPairGenerator.java:704)
	at sun.security.ssl.ECDHCrypt.<init>(ECDHCrypt.java:78)
	at sun.security.ssl.ClientHandshaker.serverKeyExchange(ClientHandshaker.java:717)
	at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:278)
	at sun.security.ssl.Handshaker.processLoop(Handshaker.java:913)
	at sun.security.ssl.Handshaker.process_record(Handshaker.java:849)
	at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1035)
	at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1344)
	at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:721)
	at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:122)
	... 41 more
Caused by: java.security.KeyException
	at sun.security.ec.ECKeyPairGenerator.generateECKeyPair(Native Method)
	at sun.security.ec.ECKeyPairGenerator.generateKeyPair(ECKeyPairGenerator.java:126)
	... 51 more

2017-06-06 13:13:25[ERROR]-[Thread: http-nio-80-exec-52]-[com.jfinal.core.ActionHandler.handle()]: /qq/qc_callback?code=E5639F04A2A774643DF06050C70F7DEE&state=5eb8a7cafcd54a1de692c2e35c42b0d1
com.jfinal.render.RenderException: java.lang.RuntimeException: File not found : /var/tomcat/tomcat-7/webapps/travel-master/html/qc_callback.html
	at com.jfinal.render.TemplateRender.render(TemplateRender.java:63)
	at com.jfinal.core.ActionHandler.handle(ActionHandler.java:99)
	at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:74)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1757)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1716)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: File not found : /var/tomcat/tomcat-7/webapps/travel-master/html/qc_callback.html
	at com.jfinal.template.FileStringSource.getContent(FileStringSource.java:70)
	at com.jfinal.template.Engine.buildTemplateByFileStringSource(Engine.java:147)
	at com.jfinal.template.Engine.getTemplate(Engine.java:133)
	at com.jfinal.render.TemplateRender.render(TemplateRender.java:61)
	... 20 more

本地回调是没有问题的,发布正式ip就有这个问题,其他一切正常,为什么?

评论区

威仔

2017-06-06 13:41

@jfinal 什时候框架自己整合一套权限管理进去啊,shiro虽然可以,但是好多地方用起来很麻烦而且不易入手新人

威仔

2017-06-06 13:41

把shiro放入jfinal也行啊

Dreamlu

2017-06-07 09:24

第三方 登陆 参考这个吧:http://git.oschina.net/596392912/JFinal-oauth2.0-login

威仔

2017-06-07 15:42

@Dreamlu 我改成这个也是报错:
2017-06-07 15:41:12[ERROR]-[Thread: http-nio-80-exec-9]-[com.liuguanlin.travel.controll.AccountController.qc_callback()]: javax.net.ssl.SSLException: java.security.ProviderException: java.security.KeyException

威仔

2017-06-07 16:05

@Dreamlu 搞定了谢了

热门反馈

扫码入社