Search code examples
javaorientdb

OrientDB http request failed...?


I'm trying to do a "POST" method in Java. I create my output with the OrientDB method like this:

"http://xxxxxxxxxxx:2480/command/mydb/sql/CREATE VERTEX V SET name = ' datoAletarorio'"

I need to use the write and flush methods to send the command.

My DB is empty with this method. Where is my error? Here is my code:

//...
PrintWriter out = null;
//...
conexion = (HttpURLConnection) url.openConnection();
conexion.setDoOutput(true);
conexion.setRequestMethod("POST");

out = new PrintWriter(conexion.getOutputStream());

conexion.connect();
//...
String cumuloDatos1 = "http://xxxxxxxxxxx:2480/command/mydb/sql/CREATE VERTEX V SET name = ' datoAletarorio'"

out.write(cumuloDatos1);
out.flush();
//..
conexion.disconnect();

Thank in advance.


Solution

  • The docs says:

    The command-text can appear in either the URL or the content of the POST transmission. Where the command-text is included in the URL, it must be encoded as per normal URL encoding.

    So you probably have to encode the URL before sending the request:

    String cumuloDatos1 = 
         "http://xxxxxxxxxxx:2480/command/mydb/sql/" +
         "CREATE%20VERTEX%20V%20SET%20name%20%3D%20%27%20datoAletarorio%27"
    

    Anyway, you should see messages in the logs for a 400 or similiar in the server, if the request isn't valid.