google-http-java-client and java.lang.NumberFormatException: For input string: ” 0″ bug

I was developing a Java app to fetch a JSON data and process it. Because the the app will be running on GAE, I had to use GAE URL Fetch Java API. google-http-java-client library has this supported with UrlFetchTransport so it’s a clear signal to use it.

I wrote the simple script, tested it locally and uploaded to GAE. Tried it for the first time and it worked. Tried the second time, it failed. Tried few times more and it was failing at random interval. Full stack trace:

I had no idea what is going on. So I tried to investigate it:

1. Checked if I’m using latest versions -> Yes
2. Checked online if anyone else had same problem -> No
3. Tried to use same examples as in docs -> Same error
4. Made a request to some other servers -> It worked

The last one gave me a signal that something is wrong with the server I’m making requests to. So I made a test:

1. Make a request to some other server (which works)
2. Make request to primary server (which does not work)

I compared response headers. At first I didn’t notice it, but response from primary server was not returning Cache-Control header. Problem? I knew that primary server was using apache and mod_proxy. Main app that is returning JSON is behind a proxy server. So I had to update settings and updated the app which returns JSON to also send Cache-Control: private.

Private indicates that all or part of the response message is intended for a single user and MUST NOT be cached by a shared cache, such as a proxy server.

So the solution is actually pretty simple. Just make sure the Cache-Control: private is included in the response headers.

Hi, I'm Erol
Senior Fullstack Developer

I'm available for hire. So if you need help, send me an email.