<commit_before>package com.jeremyroman.gcmfilepush.server;

import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.android.gcm.server.Constants;
import com.google.android.gcm.server.Message;
import com.google.android.gcm.server.Result;
import com.google.android.gcm.server.Sender;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;

/**
 * Issues GCM messages to push a URL.
 *
 * The device ID is assumed to be unique to the client, and randomly generated.
 * It should consist of one or more alphanumeric characters.
 *
 * Requests should be of the form:
 * POST /push/DEVICE_ID (request body is form-encoded with url and filename)
 */
public class PushServlet extends HttpServlet {
  @Override
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws IOException {

    // Read parameters and check that everything is in order.
    Key key = ServerUtils.getRegistrationKey(request);
    String url = request.getParameter("url");
    String filename = request.getParameter("filename");
    if (key == null || url == null || filename == null ||
        url.length() + filename.length() > 2048) {
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    }

    // Fetch the registration.
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    String registrationId = null;
    try {
      Entity registration = datastore.get(key);
      registrationId = (String) registration.getProperty("registration_id");
    } catch (EntityNotFoundException e) {
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    }

    // Ensure the registration ID exists.
    if (registrationId == null || registrationId.isEmpty()) {
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    }

    // Dispatch to GCM.
    String senderKey = System.getProperty("com.jeremyroman.gcmfilepush.server.SENDER_KEY");
    if (senderKey == null || senderKey.isEmpty()) {<commit_msg>clarify comment<commit_after>package com.jeremyroman.gcmfilepush.server;

import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.android.gcm.server.Constants;
import com.google.android.gcm.server.Message;
import com.google.android.gcm.server.Result;
import com.google.android.gcm.server.Sender;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;

/**
 * Issues GCM messages to push a URL.
 *
 * The device ID is assumed to be unique to the client, and randomly generated.
 * It should consist of one or more alphanumeric characters.
 *
 * Requests should be of the form:
 * POST /push/DEVICE_ID (request body is form-encoded with url and filename)
 */
public class PushServlet extends HttpServlet {
  @Override
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws IOException {

    // Read parameters and check that everything is in order.
    Key key = ServerUtils.getRegistrationKey(request);
    String url = request.getParameter("url");
    String filename = request.getParameter("filename");
    if (key == null || url == null || filename == null ||
        url.length() + filename.length() > 2048) {
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    }

    // Fetch the registration.
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    String registrationId = null;
    try {
      Entity registration = datastore.get(key);
      registrationId = (String) registration.getProperty("registration_id");
    } catch (EntityNotFoundException e) {
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    }

    // Ensure the registration ID is present.
    if (registrationId == null || registrationId.isEmpty()) {
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    }

    // Dispatch to GCM.
    String senderKey = System.getProperty("com.jeremyroman.gcmfilepush.server.SENDER_KEY");
    if (senderKey == null || senderKey.isEmpty()) {
{'fraction_non_alphanumeric': 0.0990348300461603, 'fraction_numerical': 0.001678556441460344, 'mean_word_length': 4.2098360655737705, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '10596', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1344, 'n_words': 322}