我使用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}]}}
有什么建议吗?
谢谢, 丹
答案 0 :(得分:2)
URLConnection
有一个default deadline of 5 seconds。您应该通过setConnectTimeout()
设置连接超时加上setReadTimeout()
的读取超时来增加它。连接和读取超时一起是截止时间,最长可达60秒。