a-schild/nextcloud-java-api

Cant get connection

nicolasoliva62 opened this issue · 3 comments

Nextcloud version: 18.0.4
Connector version: 11.3.0

Hi Everyone! Im trying to get connect to nextcloud using this api and i can't get it!.

This is my Java code:

String serverName = "192.168.0.19/nextcloud";
boolean useHTTPS = false;
int port = 80;
String userName = "nextcloud";
String password = "Kapasky3";
NextcloudConnector nxt = new NextcloudConnector(serverName, useHTTPS, port, userName, password);
nxt.createFolder("nextcloud1");
SharePermissions permissions = new SharePermissions(SingleRight.READ);
nxt.doShare("/test", ShareType.PUBLIC_LINK, "2", true, "1234", permissions);

And this is the output i get:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" org.aarboard.nextcloud.api.exception.NextcloudApiException: com.github.sardine.impl.SardineException: status code: 405, reason phrase: Unexpected response (405 Method Not Allowed)
at org.aarboard.nextcloud.api.webdav.Folders.createFolder(Folders.java:157)
at org.aarboard.nextcloud.api.NextcloudConnector.createFolder(NextcloudConnector.java:692)
at com.mycompany.startnextcloud.StartNextCloud.main(StartNextCloud.java:37)
Caused by: com.github.sardine.impl.SardineException: status code: 405, reason phrase: Unexpected response (405 Method Not Allowed)
at com.github.sardine.impl.handler.ValidatingResponseHandler.validateResponse(ValidatingResponseHandler.java:48)
at com.github.sardine.impl.handler.VoidResponseHandler.handleResponse(VoidResponseHandler.java:34)
at com.github.sardine.impl.handler.VoidResponseHandler.handleResponse(VoidResponseHandler.java:29)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:223)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165)
at com.github.sardine.impl.SardineImpl.execute(SardineImpl.java:1050)
at com.github.sardine.impl.SardineImpl.execute(SardineImpl.java:1019)
at com.github.sardine.impl.SardineImpl.createDirectory(SardineImpl.java:998)
at org.aarboard.nextcloud.api.webdav.Folders.createFolder(Folders.java:155)
... 2 more

Could you please help me with this ! Thanks !

  1. Please configure a logger, just as the link in the warning shows
  2. is your login allowed to create the "nextcloud1" folder?
  3. is your login allowed to create public link shares?

Got also the response:
Exception in thread "main" org.aarboard.nextcloud.api.exception.NextcloudApiException: com.github.sardine.impl.SardineException: status code: 405, reason phrase: Unexpected response (405 Method Not Allowed)

I think this is the difficulty
String serverName = "192.168.0.19/nextcloud";

It is by AWebdavHandler.buildWebdavPath translated to "http://192.168.0.19:80/remote.php/webdav/nextcloud"

protected String buildWebdavPath(String remotePath)
    {
        URIBuilder uB= new URIBuilder()
        .setScheme(_serverConfig.isUseHTTPS() ? "https" : "http")
        .setHost(_serverConfig.getServerName())
        .setPort(_serverConfig.getPort())
        .setPath(WEB_DAV_BASE_PATH + remotePath);
        return uB.toString();
    }

Added a pull request.

Can you please try with the new 11.4.0 release?
There you can now specify the folder in which your nextcloud is installed, if it's not on root