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
}
});
}
}