Project

General

Profile

Actions

CommitSync JAVA

/**
 * Send info to remote server about successful single table synchronization
 * @param syncId id of synchronization
 * @throws Exception
 */
private void commitSynchronization(@NonNull int syncId) throws Exception {
    HttpURLConnection connection = null;
    InputStream resultStream = null;
    String resultString = null;

    String requestUrl = String.format("%s/CommitSync/%s", _serverURL, syncId);

    try {
        connection = (HttpURLConnection) new URL(requestUrl).openConnection();

        int status = connection.getResponseCode();

        switch (status){
            case HttpURLConnection.HTTP_OK:
                resultStream = connection.getInputStream();
                resultString = IOUtils.toString(resultStream, "UTF-8");
                break;
            default:
                resultStream = connection.getErrorStream();
                resultString = IOUtils.toString(resultStream, "UTF-8");
                throw new Exception(resultString);
        }
    }
    finally {
        if (resultStream != null) {
            try {
                resultStream.close();
            } catch (IOException e) {
            }
        }
        if (connection != null) {
            connection.disconnect();
        }
    }
}

Updated by Tomek Dziemidowicz 3 months ago · 1 revisions