Hello Everyone,
First of all, I know that this forum is for B4X development. However, currently, I'm working with Android studio and I want to connect my app to jrdc2 (B4J server). So I'm here because I'm stuck and need a little help that I couldn't find anywhere else.
So I implemented DBRequestManager & DBCommand just like in b4a. I try to send commands and parameters but keep getting the following error:
java.util.zip.ZipException: incorrect header check
This is my code. I would greatly appreciate it if someone could help and help me figure out where is the problem
And finally in MainActivity.Java
First of all, I know that this forum is for B4X development. However, currently, I'm working with Android studio and I want to connect my app to jrdc2 (B4J server). So I'm here because I'm stuck and need a little help that I couldn't find anywhere else.
So I implemented DBRequestManager & DBCommand just like in b4a. I try to send commands and parameters but keep getting the following error:
java.util.zip.ZipException: incorrect header check
This is my code. I would greatly appreciate it if someone could help and help me figure out where is the problem
DBCommand:
public class DBCommand implements Serializable {
String Name;
List<Object> Parameters;
public DBCommand(String name, List<Object> parameters) {
Name = name;
Parameters = parameters;
}
}
DBRequestManager:
public class DBRequestManager implements Serializable {
private Object mTarget;
private String link;
private float VERSION = 2;
public void initialize(Object target, String connectorLink) {
mTarget = target;
link = connectorLink;
}
public void ExecuteQuery(DBCommand command, int limit, Object tag) throws IOException {
Map<String, Object> map = new HashMap<>();
map.put("command", command);
// Convert Map to byte array
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(byteOut);
out.writeObject(map);
byte[] data = byteOut.toByteArray();
AsyncHttpClient httpClient = new AsyncHttpClient();
RequestParams params = new RequestParams();
try {
params.put("command", data);
params.put("limit", limit);
params.put("version", VERSION);
} catch (Exception exception) {
System.out.println("error");
}
httpClient.post(link, params, new AsyncHttpResponseHandler() {
@Override
public void onStart() {
System.out.println("START");
}
@Override
public void onFinish() {
System.out.println("FINISH");
}
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
System.out.println("SUCCESS");
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
System.out.println("FAILED" + error.toString()); //this is where i get the error too
}
});
}
}
And finally in MainActivity.Java
MainActivity:
DBRequestManager dbRequestManager = new DBRequestManager();
List<Object> temp = new ArrayList<>();
temp.add("Name");
DBCommand dbCommand = new DBCommand("getInfo", temp);
dbRequestManager.initialize(MainActivity.this, "http://x.x.x.x:yyyy/rdc?method=query2");
try {
dbRequestManager.ExecuteQuery(dbCommand, 0, null);
} catch (IOException e) {
System.out.println("ERROR");
e.printStackTrace();
}