<commit_before>package org.adaptlab.chpir.android.activerecordcloudsync;

import java.io.InputStream;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.protocol.HTTP;
import com.activeandroid.query.Select;
import android.util.Log;

public class HttpPushr {
    private static final String TAG = "HttpPushr";
    private Class<? extends SendModel> mSendTableClass;
    private String mRemoteTableName;

    public HttpPushr(String remoteTableName,
            Class<? extends SendModel> sendTableClass) {
        mSendTableClass = sendTableClass;
        mRemoteTableName = remoteTableName;
    }

    public void push() {
        if (ActiveRecordCloudSync.getEndPoint() == null) {
            Log.i(TAG, "ActiveRecordCloudSync end point is not set!");
            return;
        }

        List<? extends SendModel> allElements = new Select()
                .from(mSendTableClass).orderBy("Id ASC").execute();

        for (SendModel element : allElements) {
            HttpClient client = new DefaultHttpClient();
            HttpConnectionParams
                    .setConnectionTimeout(client.getParams(), 10000); // Timeout limit

            HttpResponse response;

            if (!element.isSent() && element.readyToSend()) {
                try {
                    HttpPost post = new HttpPost(
                            ActiveRecordCloudSync.getEndPoint()
                                    + mRemoteTableName);
                    StringEntity se = new StringEntity(element.toJSON()
                            .toString());
                    se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
                            "application/json"));
                    post.setEntity(se);
                    Log.i(TAG, "Sending post request: "
                            + element.toJSON().toString());
                    response = client.execute(post);

                    /* Checking for successful response */
                    if (response.getStatusLine().getStatusCode() >= 200
                            && response.getStatusLine().getStatusCode() < 300) {
                        Log.i(TAG,
                                "Received OK HTTP status for "
                                        + element.toJSON());
                        InputStream in = response.getEntity().getContent();
                        element.setAsSent();
                        element.save();
                    }

                } catch (Exception e) {
                    Log.e(TAG, "Cannot establish connection", e);
                }

            }
        }

    }
}<commit_msg>Log bad http status code<commit_after>package org.adaptlab.chpir.android.activerecordcloudsync;

import java.io.InputStream;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.protocol.HTTP;
import com.activeandroid.query.Select;
import android.util.Log;

public class HttpPushr {
    private static final String TAG = "HttpPushr";
    private Class<? extends SendModel> mSendTableClass;
    private String mRemoteTableName;

    public HttpPushr(String remoteTableName,
            Class<? extends SendModel> sendTableClass) {
        mSendTableClass = sendTableClass;
        mRemoteTableName = remoteTableName;
    }

    public void push() {
        if (ActiveRecordCloudSync.getEndPoint() == null) {
            Log.i(TAG, "ActiveRecordCloudSync end point is not set!");
            return;
        }

        List<? extends SendModel> allElements = new Select()
                .from(mSendTableClass).orderBy("Id ASC").execute();

        for (SendModel element : allElements) {
            HttpClient client = new DefaultHttpClient();
            HttpConnectionParams
                    .setConnectionTimeout(client.getParams(), 10000); // Timeout limit

            HttpResponse response;

            if (!element.isSent() && element.readyToSend()) {
                try {
                    HttpPost post = new HttpPost(
                            ActiveRecordCloudSync.getEndPoint()
                                    + mRemoteTableName);
                    StringEntity se = new StringEntity(element.toJSON()
                            .toString());
                    se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
                            "application/json"));
                    post.setEntity(se);
                    Log.i(TAG, "Sending post request: "
                            + element.toJSON().toString());
                    response = client.execute(post);

                    /* Checking for successful response */
                    if (response.getStatusLine().getStatusCode() >= 200
                            && response.getStatusLine().getStatusCode() < 300) {
                        Log.i(TAG,
                                "Received OK HTTP status for "
                                        + element.toJSON());
                        InputStream in = response.getEntity().getContent();
                        element.setAsSent();
                        element.save();
                    } else {
                        Log.e(TAG, "Received BAD HTTP status code " + response.getStatusLine().getStatusCode()
                                + " for " + element.toJSON());
                    }

                } catch (Exception e) {
                    Log.e(TAG, "Cannot establish connection", e);
                }

            }
        }

    }
}
{'fraction_non_alphanumeric': 0.09534038334434898, 'fraction_numerical': 0.0036351619299405157, 'mean_word_length': 1.6559894690653796, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4362872', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1404, 'n_words': 308}