alexgbelov
alexgbelov

Reputation: 3121

Connecting to OrientDB server using Java restful HTTP

I'm running an OrientDB server on my local machine, and so far the only database I have is the GratefulDead one. I'm trying to connect to the server using this tutorial: https://github.com/orientechnologies/orientdb/wiki/OrientDB-REST

However, I always get a 204 HTTP code, even though the tutorial says I should be getting a 200 http code.

public void getConnection() throws MalformedURLException {
    BufferedReader rd;
    String line;
    Authenticator.setDefault( new Authenticator(){
         protected PasswordAuthentication getPasswordAuthentication(){
            return new PasswordAuthentication("admin", "admin".toCharArray());
        }
    });
    URL url = new URL("http://localhost:2480/connect/GratefulDeadConcerts");
    HttpURLConnection connection = null;
    try {
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        Map<String, List<String>> map = connection.getHeaderFields();
        for (Map.Entry<String, List<String>> entry : map.entrySet()) {
            System.out.println("Key : " + entry.getKey() +  " ,Value : " + entry.getValue());
        }
        rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        while ((line = rd.readLine()) != null) {
            System.out.println("Hello " + line);
        }
        rd.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Upvotes: 2

Views: 1433

Answers (1)

Lvca
Lvca

Reputation: 9060

The documentation wasn't updated. It returns 204 (OK, but no content). If you want database information you should call "database" command after logged in:

http://localhost:2480/database/GratefulDeadConcerts

This returns the database information.

Upvotes: 1

Related Questions