a-schild/nextcloud-java-api

java.net.UnknownHostException: myserver.deocs

arminus opened this issue · 9 comments

I have a nextcloud instance running on myserver.de:444, WebDAV seems to work in general (with WinSCP) but when I'm trying to connect like this

static String serverName = "myserver.de";
static int port = 444;
static String userName = "myuser";
static String password = "mypass";
public static void main(String[] args) {
    NextcloudConnector nc = new NextcloudConnector(serverName, true, port, userName, password);
    Collection<Share> result = nc.getShares("/remote.php/dav/files/myuser", false, false);
    ...

I get the above error. Why does it append ocs to the hostname? Obviously, that hostname is then no longer valid.

I think this happens as the first parameter of getShares() is wrong.
According to

this should be a path to file/folder.
I guess it relative to the users root, eg. "/myFolder".

Thx, tried that just now, no difference, same error. IMHO it somewhere appends that "ocs" string to the domain name for some reason and that obviously can't be resolved.

I at least get a connection, but then it fails with "CSRF check failed".
I used my local NC server:

static String serverName = "localhost/nc";
static int port = 80;
static String userName = "tobi";
static String password = "tobi";

without https.

@a-schild recent NC server needs to have a specific header:
"OCS-APIREQUEST" with value "true"

Ok, I'm also one step further. It seems I need to append a trailing / to my serverName, only then does it not append that strange ocs. (i.e. I have no path part in my base NC URL on that server).

However, then I end up with SSL exception. I have different virtual hosts on that server, and it reports a certificate name mismatch because it seems to pick up the cert from another vhost on that server.

(NCs certificate is correct as confirmed by firefox when I load NC from that server there).

@arminus Why do you prefix everything with "/remote.php/dav/files" ?
The API takes care of the WEBDAV root stuff, so you can directly use the folders you wish to retrieve the shares for.

Have a look at the https://github.com/a-schild/nextcloud-java-api/blob/master/src/test/java/org/aarboard/nextcloud/api/filesharing/FilesharingConnectorTest.java for sample code

@a-schild thx - I did look at that code originally and in my case it doesn't seem to matter what path I use for getShares - unless I add a / to the server name, I get that strange java.net.UnknownHostException: myserver.deocs

Meanwhile I haven't progressed further since I'm stuck on the SSL exception - which is strange, too, because when browsing to the different vhosts on that server all different SSL certs are picked up correctly.

@arminus What java version are you using? Perhaps it hasn't the root CA certificates for your ssl certificate in question?
And port 444 is the correct one for you?

Java 1.8.0_192 and a missing root cert is not the issue because I can connect to that server with httpclient just fine. See this gist for my current test code.

Should be fixed in 11.0.3 release.
It did something wrong with the port number