deepstreamIO / deepstream.io-client-java

The Java/Android Client for deepstream.io
Other
35 stars 37 forks source link

Client hangs on set with ack when you have create but not write permissions #103

Open grendo opened 7 years ago

grendo commented 7 years ago

Hi, in a perfect world I want to subscribe to a record that does not exist, and have a data provider listening and go and create the record, (ie I want the record to be readonly to the client). Unfortunately this functionality does not exist, it is logged as a potential feature https://github.com/deepstreamIO/deepstream.io/issues/684#issuecomment-304118122

The suggestion I got was to give a user create and read access but not write and delete access. An example permission would look like this, (the server user is what the active data provider will use to set the record).

record: "readonlyrec": create: "user.id === 'todd'" write: "user.id === 'server'" read: true delete: "user.id === 'server'" listen: true

I used the following code to test, the java client hangs at the setwithack and does not get any error back. So it looks like a bug in the java client ?

import io.deepstream.DeepstreamClient; import io.deepstream.Record; import java.net.URISyntaxException; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import com.google.gson.Gson;

class mytest { public static void main(String[] args) throws URISyntaxException { System.out.println("About to run"); // Display the string. try{ new mytest().run(); } catch(Exception e) { System.out.println("Error:" + e.getMessage()); // Display the string. } }

public void run() throws URISyntaxException {
    System.out.println("creating client"); 
    DeepstreamClient client = new DeepstreamClient("localhost:6020");
    System.out.println("closing client"); 
    JsonObject e = new JsonObject();
    e.add("username", new JsonPrimitive("chris"));
    e.add("password", new JsonPrimitive("test"));
    client.login(e);
    System.out.println("logged in"); 
    JsonObject params = new JsonObject();
    params.addProperty("name", "test");
    params.addProperty("age", "23");
    System.out.println("setting record"); 
    SetRecord(client, "readonlyrec" ,params);
    System.out.println("record set"); 
    client.close();
}
public void SetRecord(DeepstreamClient client, String recordname , JsonObject val)
{
    Record rec;
    System.out.println("getting record"); 
    rec = client.record.getRecord(recordname);
    System.out.println("set with ack"); 
    // hangs here, does not get an error back
    String r =   rec.setWithAck(val).getResult();
    System.out.println(String.format("Has result: %s", r));
}

}