Skip to content

Instantly share code, notes, and snippets.

@arminus
Last active December 3, 2018 10:57
Show Gist options
  • Save arminus/acb2cdb7d6184a42b00325b408f95b13 to your computer and use it in GitHub Desktop.
Save arminus/acb2cdb7d6184a42b00325b408f95b13 to your computer and use it in GitHub Desktop.
nextcloud-java-api exception
public class Nextcloud {
static String serverName = "nextcloud.meinserver.de/"; // needs a trailing slash, otherwise, something appends "ocs" to that string
static int port = 444;
static String userName = "myuser";
static String password = "mypass";
public static void main(String[] args) throws ClientProtocolException, IOException {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet("https://nextcloud.meinserver.de:444/login");
CloseableHttpResponse response = httpclient.execute(httpGet);
System.out.println(response.getStatusLine().getStatusCode()); // <- 200 - SSL and everyting works
// String httpResult = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
// System.out.println(httpResult);
response.close();
NextcloudConnector nc = new NextcloudConnector(serverName, true, port, userName, password);
Collection<Share> result = nc.getShares("/Documents", false, false);
// Exception in thread "main" org.aarboard.nextcloud.api.exception.NextcloudApiException:
// java.util.concurrent.ExecutionException: javax.net.ssl.SSLPeerUnverifiedException:
// Host name 'nextcloud.meinserver.de' does not match the certificate subject provided by the peer (CN=some-other-vhost.meinserver.de)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment