【问题标题】:Getting IllegalAccessError获取非法访问错误
【发布时间】:2011-08-12 09:45:15
【问题描述】:

当我使用此代码时,它会报错:

2011-08-10 13:18:13.368::警告:异常
java.lang.IllegalAccessError: 试图从类 org.mortbay.jetty.HttpURI 访问方法 org.mortbay.util.Utf8StringBuffer.(I)V

代码:

package com.google.api.client.sample.docs.v3;

import com.google.api.client.auth.oauth.OAuthCredentialsResponse;
import com.google.api.client.auth.oauth.OAuthHmacSigner;
import com.google.api.client.auth.oauth.OAuthParameters;
import com.google.api.client.googleapis.auth.oauth.GoogleOAuthAuthorizeTemporaryTokenUrl;
import com.google.api.client.googleapis.auth.oauth.GoogleOAuthGetAccessToken;
import com.google.api.client.googleapis.auth.oauth.GoogleOAuthGetTemporaryToken;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.sample.docs.v3.model.DocsUrl;
import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.net.URI;

public class Auth {

    private static final String APP_NAME ="Google Documents List Data API Java Client Sample";

    private static OAuthHmacSigner signer;

    private static OAuthCredentialsResponse credentials;

    static void authorize(HttpTransport transport) throws Exception {
        // callback server
        LoginCallbackServer callbackServer = null;
        String verifier = null;
        String tempToken = null;
        try {

            callbackServer = new LoginCallbackServer();
            callbackServer.start();
            // temporary token
            GoogleOAuthGetTemporaryToken temporaryToken =new GoogleOAuthGetTemporaryToken();
            signer = new OAuthHmacSigner();
            signer.clientSharedSecret = "anonymous";
            temporaryToken.signer = signer;
            temporaryToken.consumerKey = "in.gappsdemo.in";
            //temporaryToken.scope ="https://apps-apis.google.com/a/feeds/user/";
            temporaryToken.scope = DocsUrl.ROOT_URL;
            temporaryToken.displayName = APP_NAME;
            temporaryToken.callback = callbackServer.getCallbackUrl();
            System.out.println("temporaryToken.callback: "+temporaryToken.callback);
            OAuthCredentialsResponse tempCredentials = temporaryToken.execute();
            signer.tokenSharedSecret = tempCredentials.tokenSecret;
            System.out.println("signer.tokenSharedSecret: " + signer.tokenSharedSecret);
            // authorization URL
            GoogleOAuthAuthorizeTemporaryTokenUrl authorizeUrl =new GoogleOAuthAuthorizeTemporaryTokenUrl();
            authorizeUrl.temporaryToken = tempToken = tempCredentials.token;
            String authorizationUrl = authorizeUrl.build();
            System.out.println("Go to this authorizationUrl: " + authorizationUrl);
            // launch in browser
            boolean browsed = false;
            if (Desktop.isDesktopSupported()) {
                Desktop desktop = Desktop.getDesktop();
                if (desktop.isSupported(Action.BROWSE)) {
                    System.out.println("In if browsed condition:");
                    desktop.browse(URI.create(authorizationUrl));
                    browsed = true;
                }
            }
            if (!browsed) {
                String browser = "google-chrome";
                Runtime.getRuntime().exec(new String[] {browser, authorizationUrl});
                System.out.println("In if !browsed condition1:");
            }
            System.out.println("tempToken: "+tempToken);
            verifier = callbackServer.waitForVerifier(tempToken);
            System.out.println("GoogleOAuthGetAccessToken: ");
        } finally {
            System.out.println("server Stop:");
            if (callbackServer != null) {
                System.out.println("server Stop:");
                callbackServer.stop();
            }
        }
        System.out.println("GoogleOAuthGetAccessToken: ");
        GoogleOAuthGetAccessToken accessToken = new GoogleOAuthGetAccessToken();
        accessToken.temporaryToken = tempToken;
        accessToken.signer = signer;
        accessToken.consumerKey = "in.gappsdemo.in";
        accessToken.verifier = verifier;
        credentials = accessToken.execute();
        signer.tokenSharedSecret = credentials.tokenSecret;
        System.out.println("signer.tokenSharedSecret: ");
        createOAuthParameters().signRequestsUsingAuthorizationHeader(transport);
    }

    static void revoke() {
        if (credentials != null) {
            try {
                GoogleOAuthGetAccessToken.revokeAccessToken(createOAuthParameters());
            } catch (Exception e) {
                e.printStackTrace(System.err);
            }
        }
    }

    private static OAuthParameters createOAuthParameters() {
        OAuthParameters authorizer = new OAuthParameters();
        authorizer.consumerKey = "in.gappsdemo.in";
        authorizer.signer = signer;
        authorizer.token = credentials.token;
        return authorizer;
    }
}

【问题讨论】:

    标签: java


    【解决方案1】:

    这里有两个可能是relatedposts。请注意,您得到的是错误,而不是异常,所以这很有趣。您可以尝试使用 -verbose 运行您的 JVM,以查看每个类是从哪里加载的,看看您是否正在使用一个类/jar 进行编译,但不小心使用了另一个。

    还从错误中注意到包与“org.mortbay.util”与“org.mortbay.jetty”略有不同,因此 UTF8StringBuffer 构造函数需要更加可见。但同样,通常编译器会捕捉到这一点。

    我意识到这不是一个完整的答案,可以肯定的是,但至少有几个地方可以开始寻找。

    【讨论】:

      猜你喜欢
      • 2013-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-30
      • 2013-10-11
      相关资源
      最近更新 更多