2

我使用 GAE 作为我的应用程序的服务器,当发生某些事情时,我想通知相关用户。我使用 Parse REST API 来执行此推送通知(不是 GCM,因为我也有 iphone 用户)。但有时(不知道什么时候)我得到

java.net.SocketTimeoutException: Timeout while fetching: https://api.parse.com/1/push
at com.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:52)
at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.fetchResponse(URLFetchServiceStreamHandler.java:417)
at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.getInputStream(URLFetchServiceStreamHandler.java:296)
at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.getResponseCode(URLFetchServiceStreamHandler.java:149)
at com.starling.parse.PushNotifications.sendRequest(PushNotifications.java:113)
at com.starling.parse.PushNotifications.sendPushUpdate(PushNotifications.java:71)
at com.starling.parse.PushNotifications.notifyUsersWithSongUpdates(PushNotifications.java:121)
at com.straling.server.db.actions.VoteActions$1.run(VoteActions.java:86)
at com.straling.server.db.actions.VoteActions$1.run(VoteActions.java:1)
at com.googlecode.objectify.impl.cmd.ObjectifyImpl.transactOnce(ObjectifyImpl.java:257)
at com.googlecode.objectify.impl.cmd.ObjectifyImpl.transactNew(ObjectifyImpl.java:234)
at com.googlecode.objectify.impl.cmd.ObjectifyImpl.transactNew(ObjectifyImpl.java:224)
at com.googlecode.objectify.impl.cmd.ObjectifyImpl.transact(ObjectifyImpl.java:216)
at com.straling.server.db.actions.VoteActions.newVote(VoteActions.java:50)
at com.straling.server.servlets.VoteSongServlet.doPost(VoteSongServlet.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.googlecode.objectify.cache.AsyncCacheFilter.doFilter(AsyncCacheFilter.java:59)
at com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:49)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:110)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:61)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:380)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

当它发生时,它会立即发生(不是在 45 秒之后。这是 GAE 请求超时)?

我的代码:

private static void sendRequest(String payload) throws IOException {

    HttpURLConnection connection = null;
    URL urlObject = new URL("https://api.parse.com/1/push");
    connection = (HttpURLConnection) urlObject.openConnection();
    connection.setRequestProperty("X-Parse-Application-Id", APPLICATION_ID);
    connection.setRequestProperty("X-Parse-REST-API-Key", REST_API_KEY);
    connection.setRequestProperty("Content-Type", "application/json");
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");

    connection.getOutputStream().write(payload.getBytes());

    connection.getResponseCode();

}

有效载荷字符串:

{ "channel": "vID18483", "data": {"action": "com.starling.app.UPDATE_SONGS","songs":[{"id":36209,"length":0,"points":104,"isPlaying":false,"isInPlaylist":true}]}}

有什么建议么?

谢谢,丹

4

1 回答 1

2

URLConnectionGAE 上的默认期限为 5 秒。您应该通过设置连接超时setConnectTimeout()加上读取超时来增加它setReadTimeout()。连接超时和读取超时都是截止时间,最长可达 60 秒。

于 2013-07-17T15:48:09.423 回答