B4J Question B4J Getting HTTPUtils2 Error

canalrun

Well-Known Member
Licensed User
Hello,
I am using B4J to prototype an application that will eventually be moved to B4A. The application uses B4J's HttpUtils2 library. The program downloads OSM tiles. I used your Image Downloader as an example changing the downloader service to a class in B4J.

I get the following error upon executing, after about a 30 second timeout, of the hj.download(t) line.

B4X:
http://otile1.mqcdn.com/tiles/1.0.0/sat/14/4728/6019.jpg ' (<- log(t) output)

Nov 22, 2013 7:57:31 PM org.apache.http.impl.client.DefaultRequestDirector execute
INFO: I/O exception (java.net.SocketException) caught when processing request: Connection reset
Nov 22, 2013 7:57:31 PM org.apache.http.impl.client.DefaultRequestDirector execute
INFO: Retrying request
java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:152)
    at java.net.SocketInputStream.read(SocketInputStream.java:122)
    at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:130)
    at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:127)
    at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:233)
    at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:98)
    at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:210)
    at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:271)
    at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:227)
    at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:229)
    at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:292)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:126)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)
    at anywheresoftware.b4a.http.HttpClientWrapper.executeWithTimeout(HttpClientWrapper.java:309)
    at anywheresoftware.b4a.http.HttpClientWrapper.access$0(HttpClientWrapper.java:307)
    at anywheresoftware.b4a.http.HttpClientWrapper$ExecuteHelper.run(HttpClientWrapper.java:208)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

This is the immediate area of code (I've also attached the project export)

B4X:
Public Sub Download ' check if svrs avail, create jobs
  Do While (True)
    If ((SvrCache.Size > 0) AND (TileCache.Size > 0)) Then
      Dim i As Int
      Dim s, t, u As String
      Dim tr As TileRec
   
      tr.Initialize
   
      i = SvrCache.Size - 1
      s = SvrCache.Get(i)
      SvrCache.RemoveAt(i)
   
      i = TileCache.Size - 1
      tr = TileCache.Get(i)
      TileCache.RemoveAt(i)
   
      t = s.Replace("*z", tr.zm).Replace("*x", tr.x).Replace("*y", tr.y)
      u = tr.zm & "_" & tr.x & "_" & tr.y
   
      Log(t)

      Dim hj As HttpJob
      hj.Initialize(u, Me)
      hj.Download(t)
      tr.svr = s
      ogTasks.Put(u, tr)
    Else
      Exit   
    End If
  Loop
End Sub

This is just a prototype in B4J – I really don't need it to work in B4J. I am wondering what causes the error. I will be moving it to B4A. If I enter the URL (t) into a browser I receive the JPG tile back successfully.

Barry.
 

Attachments

  • RegToTiles.zip
    3.8 KB · Views: 186
Last edited:

canalrun

Well-Known Member
Licensed User
Thanks,

On the B4J Libs tab, I checked the jHttp library in addition to jHttpUtils2. I get a slightly different error:
B4X:
http://android.canalrun.com ' <- output from log(t)

java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:152)
    at java.net.SocketInputStream.read(SocketInputStream.java:122)
    at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:130)
    at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:127)
    at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:233)
    at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:98)
    at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:210)
    at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:271)
    at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:227)
    at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:229)
    at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:292)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:126)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)
    at anywheresoftware.b4a.http.HttpClientWrapper.executeWithTimeout(HttpClientWrapper.java:309)
    at anywheresoftware.b4a.http.HttpClientWrapper.access$0(HttpClientWrapper.java:307)
    at anywheresoftware.b4a.http.HttpClientWrapper$ExecuteHelper.run(HttpClientWrapper.java:208)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

To me it doesn't seem like the error is caused by the timeout, the timeout is an artifact of the error.

I am only sending one request right now – a request that works, and returns almost immediately, if I paste the request into a browser. Eventually I'll have four or five concurrent requests at a time, but just one for now.

I also changed the request to a simple request for a web page, http://android.canalrun.com, that I know works. I get the same error.

I will be trying basically the same code on a device using B4A over the next few days.

Barry.
 
Upvote 0

canalrun

Well-Known Member
Licensed User
Strange…

I took essentially the same program, changing things like "as image" to "as bitmap" and a few other things, converted it to B4A and ran on a device. I got the tiles successfully with no errors.

It sounds like it may be an incompatibility with something like the Windows networking stack or the Java runtime as used by B4J. The computer I was using is Windows 7 Home Premium 64-bit. I have jdk1.7.0_45 and jre7. It is connected to a local network and the Internet. No problems with browsers or any other network stuff. I've done no modifications to standard Windows 7 networking.

Since you had no problems, maybe it is specific to my one computer. I have a few more older Windows 7 computers that I could try the code on.

I am not too familiar with Java. Is there something equivalent to an "exe" output from B4J that I could copy to other computers and try (without having to install B4J on each computer)?

Barry.
 
Upvote 0

canalrun

Well-Known Member
Licensed User
Compile in Release mode. It will generate a jar file under Objects folder. This is an executable jar. You can distribute it.

Thanks, I ran my demo app on three different Windows 7 64-bit computers. Computer 1 is my main development computer, Computer 2 is about 2 years old, Computer 3 is about 4 or 5 years old, but has probably had updates installed more recently than computer 2. All three computers are on the same network.

I've attached an export of the project (Unfortunately I could not include the Jar file – it makes the archive too large). I also attached screenshots of the results from each computer.

Computer 1: I get the error "Socket timeout exception". I know the URL is valid and should not timeout. It seems like the timeout is caused by an invalid query rather than an actual "getting a response" timeout.

Computer 2: Asked me to install jxpinstall.exe, an updated version of Java. That computer has been retired containing a valid project. I don't want to perform any updates or installs that may break the project if I come back to it in two or three years.

Computer 3: The demo app returned Success. This is the same Jar file that I ran on computer 1.

As I've mentioned in previous posts, I ported this application to a B4A application and it works properly. I am just using B4J to try it out and to prototype converting a lat/lon region to a set of tiles. I really don't need it to work in B4J. I will probably try installing the jxpinstall Java file on Computer 1 to see if that works.

To me it kind of seems like a missing Java thing, but I'm really not comfortable enough with Java to go investigating. My Computer 3 has Java installed all over it – Jre, Jse, Jdk, blah blah blah.

Any ideas?
 

Attachments

  • Results.jpg
    Results.jpg
    85.8 KB · Views: 204
  • RegToTiles.zip
    3.8 KB · Views: 171
Upvote 0

canalrun

Well-Known Member
Licensed User
Is it possible that your firewall / antivirus interferes with the connection?

Good suggestion! Nothing pops up, but this is a distinct possibility. I use Avast. The first time I tried to access email a dialog popped up asking me to make an "exception".

If I type the same tile fetch URL into a browser, it works. But, the browser might have a "global exception" in Avast. This is definitely something to investigate.

Barry.
 
Upvote 0
Top