com.google.apphosting.api.ApiProxy $ CancelledException:显式取消了API调用urlfetch.Fetch()。代码503 App Engine后端错误

时间:2015-07-13 13:14:25

标签: android google-app-engine exception google-cloud-messaging

我使用Google App Engine作为GCM的后端。它工作正常,除了以下错误:

private List<RegistrationRecord> regIdTrim(List<RegistrationRecord> wholeList, final int start) {

        List<RegistrationRecord> parts = wholeList.subList(start,(start+1000)> wholeList.size()? wholeList.size() : start+1000);
        return parts;
    }
    /**
     * Send to the first 1000 devices (You can modify this to send to any number of devices or a specific device)
     *
     * @param message The message to send
     */
    public void sendMessage(@Named("message") String message) throws IOException {

        int count = ofy().load().type(RegistrationRecord.class).count();


        if(count<=1) {
            List<RegistrationRecord> records = ofy().load().type(RegistrationRecord.class).limit(count).list();
            sendMsg(records,message);
        }else
        {
            int msgsDone=0;
            List<RegistrationRecord> records = ofy().load().type(RegistrationRecord.class).list();

            do {
                List<RegistrationRecord> regIdsParts = regIdTrim(records, msgsDone);
                msgsDone+=1000;
                sendMsg(regIdsParts,message);
            }while(msgsDone<count);

        }
    }
    private void sendMsg(List<RegistrationRecord> records,@Named("message") String msgToSend) throws IOException {

        if (msgToSend == null || msgToSend.trim().length() == 0) {
            log.warning("Not sending msgToSend because it is empty");
            return;
        }

        Sender sender = new Sender(API_KEY);
       // Message msg = new Message.Builder().addData("msgToSend", msgToSend).build();
        Message msg = new Message.Builder().
                addData("notification_title", msgToSend)
                .addData("description","Check ").build();

        // crop longer messages
        if (msgToSend.length() > 1000) {
            msgToSend = msgToSend.substring(0, 1000) + "[...]";
        }
        for (RegistrationRecord record : records) {
            Result result = sender.send(msg, record.getRegId(), 5);

            if (result.getMessageId() != null) {
                log.info("Message sent to " + record.getRegId());
                String canonicalRegId = result.getCanonicalRegistrationId();
                if (canonicalRegId != null) {
                    // if the regId changed, we have to update the datastore
                    log.info("Registration Id changed for " + record.getRegId() + " updating to " + canonicalRegId);
                    record.setRegId(canonicalRegId);
                    ofy().save().entity(record).now();
                }
            } else {
                String error = result.getErrorCodeName();
                if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
                    log.warning("Registration Id " + record.getRegId() + " no longer registered with GCM, removing from datastore");
                    // if the device is no longer registered with Gcm, remove it from the datastore
                    ofy().delete().entity(record).now();
                } else {
                    log.warning("Error when sending msgToSend : " + error);
                }
            }
        }
    }

为了找到原因我在我的整个代码中搜索了urlfetch.Fetch()方法,但我找到了它。

之前有没有人遇到同样的错误?如果是的话请告诉我你是如何解决的?

有关详细信息,我在下面添加了代码,以便为超过1000个用户发送推送通知。

C:\ProgramData\PostSharp\InstalledFrameworks

1 个答案:

答案 0 :(得分:0)

看起来服务器阻止了你:/ 我认为这与您在其上拍摄的1000个网络请求有关。

向服务器发送要推送给他们的1000个ID的列表,让服务器处理推送。