Hey all I am trying to connect to my local Jira server via Java but I get the error of:
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certificate path to requested target.
The url I am using is this:
https://mycompaddresshere.com/rest/api/2/myself
And my java code:
private static final String JiraBase = "https://mycompanyurl.com"
private static final String JiraEmail = "[email protected]"
private static final String PAT = "ljknfg9u8h5h9nner9gbner098honeg+on"
try {
String apiURL = JiraBase + "/rest/api/2/myself";
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
String auth = JiraEmail + ":" + PAT;
byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(StandardCharsets.UTF_8));
String authHeader = "Basic " + new String(encodedAuth);
connection.setRequestMethod("GET");
connection.setRequestProperty("Authorization", authHeader);
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Type", "application/json");
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP-oK) {
BufferedReader in = new BufferedReader(new
InputStreamReader(connection.getInputStream())));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.printLn("Response: " + response.toString());
} else {
System.out.printLn("GET request failed");
}
connection.disconnect();
} catch (Exception e) {
System.out.printLn(e.getMessage());
}
When I log into the web site and visit that same URL I get data just fine:
{
"self": "https://mycompanyurl.com/rest/api/2/[email protected]",
"key": "name here",
"name": "[email protected]",
"emailAddress": "[email protected]",
"avatarUrls": {
},
"displayName": "Name, My",
"active": true,
"deleted": false,
"timeZone": America/New_York,
"locale": "en_uS",
"groups": {
"size": 13,
"items": []
},
"applicationRoles": {
"size": 1,
"items": []
},
"expand": "groups,applicationRoles"
}
Not sure why I am able to hit the site api but not when I use Java to hit that same url? Anyone spot what I may be missing? Or have I set something else up incorrectly?