“未授权执行此请求”使用arangodb java驱动程序

时间:2017-06-27 08:16:46

标签: java eclipse maven arangodb

我想在Eclipse上的Maven项目中使用ArangoDB的java驱动程序。我正在尝试按照ArangoDB可用的here的Java驱动程序的教程,但我甚至无法使更简单的应用程序工作,甚至从一个干净的项目开始。

main.java:

package test;

import com.arangodb.ArangoDB;

public class main {

    public static void main(String[] args) {

        ArangoDB arangoDB = new ArangoDB.Builder().build();

        arangoDB.createDatabase("myDatabase");
    }

}

的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>test</groupId>
   <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
    <dependency>
        <groupId>com.arangodb</groupId>
        <artifactId>arangodb-java-driver</artifactId>
        <version>4.2.0</version>
    </dependency>
  </dependencies>
</project>

运行代码时出现以下错误:

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" com.arangodb.ArangoDBException: Response: 401, Error: 11 - not authorized to execute this request
    at com.arangodb.internal.velocystream.VstCommunication.checkError(VstCommunication.java:106)
    at com.arangodb.internal.velocystream.VstCommunicationSync.execute(VstCommunicationSync.java:134)
    at com.arangodb.internal.velocystream.VstCommunicationSync.execute(VstCommunicationSync.java:46)
    at com.arangodb.internal.velocystream.VstCommunication.execute(VstCommunication.java:96)
    at com.arangodb.internal.velocystream.VstProtocol.execute(VstProtocol.java:46)
    at com.arangodb.internal.ArangoExecutorSync.execute(ArangoExecutorSync.java:58)
    at com.arangodb.ArangoDB.createDatabase(ArangoDB.java:437)
    at test.main.main(main.java:12)

我尝试了其他基本操作,没有工作(即使是简单的arangoDB.getVersion();)。

如果我将以下依赖项添加到pom.xml,它会删除警告但不会删除错误:

<dependency> 
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.7.22</version>
</dependency>

结果:

Exception in thread "main" com.arangodb.ArangoDBException: Response: 401, Error: 11 - not authorized to execute this request
    at com.arangodb.internal.velocystream.VstCommunication.checkError(VstCommunication.java:106)
    at com.arangodb.internal.velocystream.VstCommunicationSync.execute(VstCommunicationSync.java:134)
    at com.arangodb.internal.velocystream.VstCommunicationSync.execute(VstCommunicationSync.java:46)
    at com.arangodb.internal.velocystream.VstCommunication.execute(VstCommunication.java:96)
    at com.arangodb.internal.velocystream.VstProtocol.execute(VstProtocol.java:46)
    at com.arangodb.internal.ArangoExecutorSync.execute(ArangoExecutorSync.java:58)
    at com.arangodb.ArangoDB.createDatabase(ArangoDB.java:437)
    at test.main.main(main.java:12)

2 个答案:

答案 0 :(得分:1)

你需要为你的数据库指定连接数据,如用户,密码等,所有db都需要成功连接,再次检查类的javadoc Builder并设置用户和密码。

ArangoDB arangoDB = new ArangoDB.Builder().build();

这里你没有设置任何东西,并且在没有任何连接数据的情况下构建ArrangoDb实例

答案 1 :(得分:0)

我指定了完整的用户凭据(API 6.2.2),但收到错误11。 server = new ArangoDB.Builder()。host(host,port).user(user).password(password).useProtocol(Protocol.HTTP_JSON).build(); 集合数据库= server.getDatabases(); 我可以做所有事情,但是ArangoDB的用户界面方式。