Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
simbasister
Frequent Visitor

how to solve javax.net.ssl.SSLHandshakeException when I called power bi api

I have got access token and created client by using this access token. But when i called power bi api like below

client.getReportsOperations().getReportInGroup(workspaceId, reportId)

it throws javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

how could i solve it? Do i need to install one certificate? Which one and How? 

4 REPLIES 4
simbasister
Frequent Visitor

Thank u. My codes and screenshots of the error message as below.

get access token:

public String getAccessToken() throws MalformedURLException, ExecutionException, InterruptedException {
ConfidentialClientApplication app = createClientApplication();
Set<String> resourceSet = new HashSet<>();
resourceSet.add(resourceUrl);
ClientCredentialParameters parameters = ClientCredentialParameters.builder(resourceSet).build();
Future<IAuthenticationResult> future = app.acquireToken(parameters);
String result = future.get().accessToken();
return result;
}

private ConfidentialClientApplication createClientApplication() throws MalformedURLException {
authorityUrl = authorityUrl.replace("organizations", tenantId);
return ConfidentialClientApplication.builder(clientId, ClientCredentialFactory.createFromSecret(clientSecret)).
authority(authorityUrl).
build();
}

create power bi client:

PowerBiClient client = PowerBiClient.getInstance(accessToken);

 get report in group:

Report report = client.getReportsOperations().getReportInGroup(workspaceId, reportId);

this code will throw SSLException as below:

simbasister_1-1641868979533.png

 

 

Hi @simbasister ,

This seems to be a SSL issue, you can refer to the links below to make troubleshooting to try to solve it.

Java Exception Handling – SSLHandshakeException

1. Generate a new key and storing it in a local keystore file:

$ keytool -genkeypair -alias airbrake -keyalg RSA -validity 7 -keystore keystore

2. Export the keystore to a local file:

$ keytool -export -alias airbrake -keystore keystore -rfc -file airbrake.cer

3. Import the certificate into the truststore. The best way to think of the difference between a keystore and truststore is that the keystore is used for private keys, while the truststore is for public certificates.

$ keytool -import -alias airbrake -file airbrake.cer -keystore truststore

4. Add the following to the SSLServer class:

// SSLServer.java
System.setProperty("javax.net.ssl.keyStore", "keystore");
System.setProperty("javax.net.ssl.keyStorePassword", "password");

5. Add the following to the SSLClient class:

// SSLClient.java
System.setProperty("javax.net.ssl.trustStore", "truststore");
System.setProperty("javax.net.ssl.trustStorePassword", "password");

How to solve javax.net.ssl.SSLHandshakeException Error?

Troubleshooting SSL related issues (Server Certificate)

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

It seems that I need obtain the public certificate from power bi server. Is that right? I tried many ways to dowload and save a copy. Unfortunatelly, there may be something wrong in obtaining one. If so, could you tell me how and where can I get the public certificate from power bi server? Then I can use keytool to install it. Thank you. 

v-yiruan-msft
Community Support
Community Support

Hi @simbasister ,

Are you calling the two REST API below? Are you using the embedded analytics solution: Embed content for customers? And it embed with a service principal and a certificate? Could you please provide a screenshot of the error message that occurred and some of the operations you took?

Reports - Get Reports

Reports - Get Reports In Group

In addition, please review the following links. Hope they can help you solve the problem.

PKIX PATH BUILDING FAILED: UNABLE TO FIND VALID CERTIFICATION PATH TO REQUESTED TARGET

How To Use REST API's


You have to create a custom connector for using OAUTH2. There are some very good tutorials here: https://github.com/Microsoft/DataConnectors

https://github.com/Microsoft/DataConnectors/blob/master/docs/m-extensions.md#implementing-an-oauth-f...


Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.