获得IllegalAccessError

时间:2011-08-12 09:45:15

标签: java

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

  

2011-08-10 13:18:13.368 ::警告:EXCEPTION
  java.lang.IllegalAccessError:尝试访问方法org.mortbay.util.Utf8StringBuffer。(I)来自org.mortbay.jetty.HttpURI类的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;
    }
}

1 个答案:

答案 0 :(得分:1)

以下是两个可能的relatedposts。请注意,您收到错误,而不是异常,因此这很有趣。您可以尝试使用-verbose运行JVM以查看每个类的加载位置,以查看是否正在使用一个类/ jar进行编译,但是不小心与另一个类一起运行。

另请注意,错误是“org.mortbay.util”与“org.mortbay.jetty”略有不同,因此UTF8StringBuffer构造函数需要更加明显。但同样,通常编译器会抓住它。

我确信这不是一个完整的答案,但至少有几个地方可以开始寻找。