2015-10-19 176 views
1

我正尝试使用Google OpenID登录用户。Apache Oltu OAuthClient.accessToken()失败,超时

当我尝试验证用户时,尝试检索AccessToken时总是遇到超时。

public class TestRun { 
    public static void main(String args[]) throws OAuthSystemException, OAuthProblemException { 
     OAuthClientRequest request = OAuthClientRequest 
       .tokenProvider(OAuthProviderType.GOOGLE) 
       .setGrantType(GrantType.AUTHORIZATION_CODE) 
       .setCode("") 
       .setRedirectURI(Env.REST_API_LOCATION+"/login") 
       .setClientId(Env.CLIENT_ID) 
       .setClientSecret(Env.CLIENT_SECRET) 
       .buildQueryMessage(); 

     OAuthClient oac = new OAuthClient(new URLConnectionClient()); 
     OAuthAccessTokenResponse response = oac.accessToken(request); 
     System.out.println(response.getAccessToken()); 
     System.out.println(response.getExpiresIn()); 
    } 
} 

我总是碰上的ConnectException(超时)时oac.accessToken(请求)被调用,没有得到关于所发生的任何详细信息。

回答

1

所以,问题很简单。运行我的软件的系统可以从互联网访问,但出站流量被迫使用代理。由于代理不是透明代理,我必须编写自己的实现HttpClient,它能够处理代理并用它替换URLConnectionClient