0

我試圖運行我的谷歌應用程序引擎項目中使用jsoup簡單的GET請求。該代碼是谷歌應用程序引擎 - jsoup.get()網址抓取超時異常

Document doc = Jsoup.connect("http://www.indianrail.gov.in/") 
         .userAgent("Mozilla") 
         .timeout(60000) 
         .get(); 

然而,當我部署我的應用程序App Engine和運行它,它會返回一個異常,如下圖所示。

com.smartapps.saseatavailability.RailwayResource readPnr: 
Timeout while fetching URL: http://www.indianrail.gov.in/ 
java.net.SocketTimeoutException: Timeout while fetching URL: http://www.indianrail.gov.in/ 
    at com.google.appengine.api.urlfetch.URLFetchServiceImpl.convertApplicationException(URLFetchServiceImpl.java:178) 
    at com.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:43) 
    at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.fetchResponse(URLFetchServiceStreamHandler.java:543) 
    at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.getInputStream(URLFetchServiceStreamHandler.java:422) 
    at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.getResponseCode(URLFetchServiceStreamHandler.java:275) 
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:443) 
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:424) 
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:178) 
    at org.jsoup.helper.HttpConnection.get(HttpConnection.java:167) 
    at com.smartapps.saseatavailability.RailwayResource.readPnr(RailwayResource.java:229) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_$1.run(Method_.java:171) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.privilegedInvoke(Method_.java:167) 
    at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.invoke_(Method_.java:125) 
    at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.invoke(Method_.java:44) 
    at org.apache.wink.server.internal.handlers.InvokeMethodHandler.handleRequest(InvokeMethodHandler.java:63) 
    at org.apache.wink.server.handlers.AbstractHandler.handleRequest(AbstractHandler.java:33) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) 
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) 
    at org.apache.wink.server.internal.handlers.CreateInvocationParametersHandler.handleRequest(CreateInvocationParametersHandler.java:54) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) 
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) 
    at org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleSubResourceMethod(FindResourceMethodHandler.java:183) 
    at org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleRequest(FindResourceMethodHandler.java:110) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) 
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) 
    at org.apache.wink.server.internal.handlers.FindRootResourceHandler.handleRequest(FindRootResourceHandler.java:95) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) 
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) 
    at org.apache.wink.server.internal.handlers.HeadMethodHandler.handleRequest(HeadMethodHandler.java:53) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) 
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) 
    at org.apache.wink.server.internal.handlers.OptionsMethodHandler.handleRequest(OptionsMethodHandler.java:46) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) 
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) 
    at org.apache.wink.server.internal.handlers.SearchResultHandler.handleRequest(SearchResultHandler.java:33) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) 
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) 
    at org.apache.wink.server.internal.log.ResourceInvocation.handleRequest(ResourceInvocation.java:92) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) 
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) 
    at org.apache.wink.server.internal.log.Requests.handleRequest(Requests.java:76) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) 
    at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) 
    at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) 
    at org.apache.wink.server.handlers.AbstractHandlersChain.run(AbstractHandlersChain.java:48) 
    at org.apache.wink.server.internal.RequestProcessor.handleRequestWithoutFaultBarrier(RequestProcessor.java:207) 
    at org.apache.wink.server.internal.RequestProcessor.handleRequest(RequestProcessor.java:154) 
    at org.apache.wink.server.internal.servlet.RestServlet.service(RestServlet.java:119) 
    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.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:37) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60) 
    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 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.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:260) 
    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.headerComplete(HttpConnection.java:923) 
    at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:78) 

有趣的是,這個代碼適用於我已嘗試「http://www.facebook.com」,「http://www.yahoo.com」所有其他網站等。此外,代碼工作正常「http://www.indianrail.gov.in/」當我在本地部署它,在我的本地測試。

爲什麼會發生這種情況? URLFetch是否故意阻止一些網站?當連接到該網站花費的時間比規定值timeout不再

回答

0

Timeout拋出異常。 「http://www.indianrail.gov.in/」可能會比其他網站(例如Facebook)加載時間更長。請嘗試timeout值增加到類似60*1000

+0

超時已設置爲60,000。我也嘗試將它增加到300,000,但沒有幫助,並在超時過期之前收到異常。 – tbag

+0

哎呀抱歉,沒有在那裏看到它。希望[此鏈接](http://stackoverflow.com/questions/30630560/google-app-engine-connection-request-timeout-error)和[此鏈接](http://stackoverflow.com/questions/7261567/在-sockettimeoutexception - 是 - 沮喪 - 上 - 谷歌 - 應用程序 - enginejava-解決方法)將是對您有所幫助。似乎是一個IP被阻止的問題。 –

+0

不要以爲這是因爲apache庫可以從谷歌應用程序引擎訪問網站。 – tbag