<commit_before>//
//  RecaptchaHelper.java
//  blogwt
//
//  Created by <NAME> (billy1380) on 20 Nov 2015.
//  Copyright © 2015 WillShex Limited. All rights reserved.
//
package com.willshex.blogwt.server.helper;

import java.util.logging.Logger;

/**
 * @author <NAME> (billy1380)
 *
 */
public class RecaptchaHelper {

	private static final Logger LOG = Logger.getLogger(RecaptchaHelper.class
			.getName());

	public static final String VERIFY_URL = "https://www.google.com/recaptcha/api/siteverify";

	public static boolean isHuman (String input, String key) {
		return false;
	}
}
<commit_msg>call recaptcha server to verify<commit_after>//
//  RecaptchaHelper.java
//  blogwt
//
//  Created by <NAME> (billy1380) on 20 Nov 2015.
//  Copyright © 2015 WillShex Limited. All rights reserved.
//
package com.willshex.blogwt.server.helper;

import java.net.URL;
import java.nio.charset.Charset;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.google.appengine.api.urlfetch.HTTPHeader;
import com.google.appengine.api.urlfetch.HTTPMethod;
import com.google.appengine.api.urlfetch.HTTPRequest;
import com.google.appengine.api.urlfetch.HTTPResponse;
import com.google.appengine.api.urlfetch.URLFetchService;
import com.google.appengine.api.urlfetch.URLFetchServiceFactory;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.willshex.gson.json.service.client.HttpException;

/**
 * @author <NAME> (billy1380)
 *
 */
public class RecaptchaHelper {

	private static final Logger LOG = Logger.getLogger(RecaptchaHelper.class
			.getName());
	private static final Charset UTF8 = Charset.forName("UTF-8");
	private static URLFetchService client = URLFetchServiceFactory
			.getURLFetchService();

	public static final String VERIFY_URL = "https://www.google.com/recaptcha/api/siteverify";

	public static boolean isHuman (String input, String key) {
		boolean isHuman = false;

		try {
			String requestData = "secret=" + key + "&response=" + input + "&";
			URL url = new URL(VERIFY_URL);

			HTTPRequest request = new HTTPRequest(url, HTTPMethod.POST);

			HTTPHeader contentTypeHeader = new HTTPHeader("Content-Type",
					"application/x-www-form-urlencoded");
			request.setHeader(contentTypeHeader);
			request.setPayload(requestData.getBytes(UTF8));

			String responseText = null;
			HTTPResponse response = client.fetch(request);
			if (response.getResponseCode() >= 200
					&& response.getResponseCode() < 300
					&& (responseText = getResponseBody(response)) != null
					&& !"".equals(responseText)
					&& !"null".equalsIgnoreCase(responseText)) {
				JsonElement element = (new JsonParser()).parse(responseText);
				JsonObject jsonObject;
				if (element.isJsonObject()) {
					jsonObject = element.getAsJsonObject();
					element = jsonObject.get("success");

					if (element.isJsonPrimitive()) {
						isHuman = element.getAsBoolean();
					}
				}
			} else if (response.getResponseCode() >= 400)
				throw new HttpException(response.getResponseCode());
		} catch (Exception e) {
			if (LOG.isLoggable(Level.WARNING)) {
				LOG.log(Level.WARNING, "Error verifying error", e);
			}
		}

		return isHuman;
	}

	private static String getResponseBody (HTTPResponse response) {
		return new String(response.getContent(), UTF8);
	}
}

{'fraction_non_alphanumeric': 0.12563718140929536, 'fraction_numerical': 0.014692653673163419, 'mean_word_length': 4.2125, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6440781', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1024, 'n_words': 231}