繁体   English   中英

使用adal java 500内部服务器错误Ms动态CRM

[英]500 Internal Server error Ms dynamics CRM using adal java

我正在尝试使用java从ms dynamics crm加载帐户,这是我的代码。 我通过使用代码获得了访问令牌

private static AuthenticationResult getAccessTokenFromUserCredentials() throws Exception {
    AuthenticationContext context = null;
    AuthenticationResult result = null;
    ExecutorService service = null;
    try {
        service = Executors.newFixedThreadPool(1);
        context = new AuthenticationContext(AUTHORITY, false, service);
        /*
         * Replace {client_id} with ApplicationID and {password} with
         * password that were used to create Service Principal above.
         */
        ClientCredential credential = new ClientCredential("xxxxxxxxxxxxxxxxxxxx",
                "xxxxxxxxxxxxxxxxxxxxxxxxx=");
        Future<AuthenticationResult> future = context.acquireToken("https://xxxxxxxxxx.api.crm8.dynamics.com",
                credential, null);
        result = future.get();
    } finally {
        service.shutdown();
    }
    if (result == null) {
        throw new ServiceUnavailableException("authentication result was null");
    }
    return result;
}

我用来从Dynamics CRM加载帐户的代码

private static String loadAccounts(String token, String userId) throws MalformedURLException, IOException {
    HttpURLConnection connection = null;
    URL url = new URL(RESOURCE + "/api/data/v8.0/accounts?$select=name&$top=1");
    connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod("GET");
    connection.setRequestProperty("Authorization", "Bearer " + token);
    connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
    connection.setRequestProperty("OData-MaxVersion", "4.0");
    connection.addRequestProperty("OData-Version", "4.0");


    int responseCode = connection.getResponseCode();
    System.out.println("res code : "+ responseCode);


    BufferedReader in = new BufferedReader(
            new InputStreamReader(connection.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
    }
    in.close();

但我收到以下异常。

Access Token - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
UserId - xxxxxxxxxxxxxxxxxxxxxxxxxxxx
res code : 500
Exception in thread "main" java.io.IOException: Server returned HTTP   
response code: 500 for URL: https://paperflite1.api.crm8.dynamics.com/api/data/v8.0/accounts?$select=name&$top=1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$10.run(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$10.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at PublicClient.loadAccounts(PublicClient.java:104)
at PublicClient.main(PublicClient.java:53)
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: https://paperflite1.api.crm8.dynamics.com/api/data/v8.0/accounts?$select=name&$top=1
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
at PublicClient.loadAccounts(PublicClient.java:99)
... 1 more

谁能帮帮我吗..

您似乎为Web API调用使用了错误的URL。 它应该是https://paperflite1.crm.dynamics.com/api/data/v8.0/accounts?$select=name&$top=1而不是假定这是您的CRM组织URL。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM