0

I am trying to execute the API Management REST API to get the list of API's. https://<service>.management.azure-api.net/apis?api-version=2014-02-14 While executing through browser I am getting the output properly, but when I am trying to execute through java code it is giving following Error.

Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

I have enabled the API Management Services also. I am executing following code.

HttpsURLConnection con = null;
con = createConnection(url, proxyDetails);
con.setRequestMethod("GET");
con.addRequestProperty("Authorization", <Token>);
con.getResponseCode()

While getting the response code I am getting the error mentioned above.

Can someone please let me know why I am getting the certification error as I didn't find any document that mentions we need to use any certificate to use API Management Service?

Do I need to do any other setup except enabling the API Management Service check box in security section of manage?

dambros
  • 4,252
  • 1
  • 23
  • 39

2 Answers2

0

Take a look at these SO posts: Resolving javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed Error?

The problem is that the SSL server certificate of API management REST service isn't correctly recognized by your java client. Some certificate authority keystore error maybe?

Open the URL in the browser, check the ssl server certificate, and check the certificate chain to see the Certificate authority (CA) which issued the server sertificate. Check if this CA is in your java keystore.

Community
  • 1
  • 1
Erik Oppedijk
  • 3,496
  • 4
  • 31
  • 42
  • To use the API Management REST API to get the metrics data, do we need to upload the certificate? As I have uploaded the client certificate in Client Certificates tab in Security tab of API Management publisher portal. And I am using the same certificate? Even while creating the HttpUrlConnection I haven't use to setSSLConnectionFactory. Not sure about this.. Can you please let me know any other setup that I need to do? – Priyanka Dahat Apr 14 '16 at 09:23
  • This isnt about client certificates, which are used by API management to connect to the backend systems. This is java code connecting to an https server, and the server returns a server certificate. The java code is unable to link this server certificate to a trusted certificate authority. – Erik Oppedijk Apr 14 '16 at 19:04
0

I want to reproduce the issue, but failed.

Here is my code below. Accoring to the doc for API Management REST API Get a list of all APIs, it's not necessary to set the Authorization header for the /apis request.

URL url = new URL("https://<my-apimgmt-service-name>.management.azure-api.net/apis?api-version=2014-02-14");
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.connect();
int respCode = conn.getResponseCode();
System.out.println(respCode);

I got the status code 200. I think the issue might be caused by your function createConnection(url, proxyDetails). If you could share the code, I think it can help us for analyzing the issue.

Any concern, please feel free to let me know.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43