}
private void sendSingleMessage(String regId, HttpServletResponse resp) {
logger.info("Sending message to device " + regId);
Message message = createMessage();
Result result;
try {
result = sender.sendNoRetry(message, regId);
} catch (IOException e) {
logger.log(Level.SEVERE, "Exception posting " + message, e);
taskDone(resp);
return;
}
if (result == null) {
retryTask(resp);
return;
}
if (result.getMessageId() != null) {
logger.info("Succesfully sent message to device " + regId);
String canonicalRegId = result.getCanonicalRegistrationId();
if (canonicalRegId != null) {
// same device has more than on registration id: update it
logger.finest("canonicalRegId " + canonicalRegId);
Datastore.updateRegistration(regId, canonicalRegId);
}
} else {
String error = result.getErrorCodeName();
if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
// application has been removed from device - unregister it
Datastore.unregister(regId);
} else {
logger.severe("Error sending message to device " + regId