HarishKumarShivaru | 2022-09-06 12:48:35 UTC | #1
I am getting Connection timeout error while executing java program.
import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.util.Base64;
// HTTP basic authentication example in Java using the RTC Server RESTful API public class Base64Encoding {
public static void main(String[] args) throws IOException, InterruptedException {
// Customer ID final String customerKey = ""; // Customer secret final String customerSecret = "";
// Concatenate customer key and customer secret and use base64 to encode the concatenated string String plainCredentials = customerKey + ":" + customerSecret; String base64Credentials = new String(Base64.getEncoder().encode(plainCredentials.getBytes())); // Create authorization header String authorizationHeader = "Basic " + base64Credentials;
HttpClient client = HttpClient.newHttpClient();
// Create HTTP request object HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://api.mypurecloud.com/api/v2/routing")) .GET() .header("Authorization", authorizationHeader) .header("Content-Type", "application/json") .build(); // Send HTTP request HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body()); } }
tim.smith | 2022-09-06 13:27:18 UTC | #2
Hello, you must use one of the supported authorization methods: https://developer.genesys.cloud/authorization/platform-auth/.
HarishKumarShivaru | 2022-09-06 15:16:20 UTC | #3
yes, i am using client credentials with Grant method. if possible could you please share any sample java program that i can refer ?
tim.smith | 2022-09-06 16:44:34 UTC | #4
Please refer to the client credentials documentation for how to authorize using client credentials. Your example code is not implementing this grant type.
You might also choose to use the Java SDK https://developer.genesys.cloud/devapps/sdk/docexplorer/purecloudjava/
HarishKumarShivaru | 2022-09-07 06:03:48 UTC | #5
Thanks Tim, but i tried using same code for authorization still getting connection timeout. I Guess its proxy related issue, is there a way to use kerberos call for authentication?
package com.api.Genesys;
import java.io.IOException;
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.mypurecloud.sdk.v2.ApiClient; import com.mypurecloud.sdk.v2.ApiException; import com.mypurecloud.sdk.v2.ApiResponse; import com.mypurecloud.sdk.v2.Configuration; import com.mypurecloud.sdk.v2.api.UsersApi; import com.mypurecloud.sdk.v2.extensions.AuthResponse; import com.mypurecloud.sdk.v2.model.User; import com.mypurecloud.sdk.v2.model.UserMe; import com.mypurecloud.sdk.v2.model.UserEntityListing; import com.mypurecloud.sdk.v2.PureCloudRegionHosts;
@SpringBootApplication public class GenesysApplication {
public static void main(String[] args) throws IOException, ApiException { SpringApplication.run(GenesysApplication.class, args);
String clientId = ""; String clientSecret = "";
//Set Region PureCloudRegionHosts region = PureCloudRegionHosts.uswest2;
ApiClient apiClient = ApiClient.Builder.standard().withBasePath(region).build(); ApiResponse<AuthResponse> authResponse = apiClient.authorizeClientCredentials(clientId, clientSecret);
// Don't actually do this, this logs your auth token to the console! System.out.println(authResponse.getBody().toString());
// Use the ApiClient instance Configuration.setDefaultApiClient(apiClient);
// Create API instances and make authenticated API requests UsersApi apiInstance = new UsersApi(); UserEntityListing response = apiInstance.getUsers(null, null, null, null, null, null, null, null); System.out.print(response); }
}
tim.smith | 2022-09-22 06:09:22 UTC | #6
Please work with your network security team to diagnose your network issues that are preventing you from accessing the login service/API.
HarishKumarShivaru, post:5, topic:16166
is there a way to use kerberos call for authentication?
No, you can only use the supported authorization methods I linked to previously.
HarishKumarShivaru | 2022-09-22 06:10:25 UTC | #7
Thanks @tim.smith issue was related to firewall block.
system | 2022-10-23 06:11:03 UTC | #8
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 16166