gpt4 book ai didi

google-app-engine - 在GAE使用Parse REST API的SocketTimeoutException

转载 作者:行者123 更新时间:2023-12-03 11:53:14 25 4
gpt4 key购买 nike

我将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}]}}

有什么建议?

谢谢,

最佳答案

GAE上的URLConnection具有default deadline of 5 seconds。您应该通过setConnectTimeout()设置连接超时,再通过setReadTimeout()设置读取超时来增加该超时时间。连接和读取超时都为最后期限,最长为60秒。

关于google-app-engine - 在GAE使用Parse REST API的SocketTimeoutException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17697669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com