Dienstag, 19. Januar 2010

Getting redirected

I just ran into a problem with HTTP redirects.

As a BlackBerry developer I don't have to deal with those 30X responses as long as the BIS or BES is doing the HttpConnection. Those services follow every redirect automatically and the clientside call to HttpConnection.getResponseCode() will get only return the final result. The application will not know, that it was redirected at all.
Actually I saw a lot of implementations (example Symbian) where this is simple handled by HTTP API itself. On ME devices some implementations also do this.

But when you start with SSL Connections (https) this will fall back on you. Same for APN based connections where no proxy is inbetween.

But my code was prepared and checked for:
HttpConnection.HTTP_MOVED_PERM
and
HttpConnection.HTTP_MOVED_TEMP
which I knew for a long time where the redirect values (as integers these are 301 and 302).

But yesterday this code broke! Why? Because I got a different result: 307!
After some google I found out that the specification of HTTP 1.1 changed the default value for moved temporarily. They now called it "redirect temporarily" with the new value 307. The old moved 302 is not simply called "found".

But as always I just should have looked into the JavaDoc more closely, its already there:
HttpConnection.HTTP_TEMP_REDIRECT

So alway check for both: HTTP_MOVED_TEMP and HTTP_TEMP_REDIRECT!

see also http://developers.sun.com/mobility/reference/techart/design_guidelines/http_redirection.html

Dienstag, 5. Januar 2010

Google utilities

A happy new year!

it doesn't always has to be Apache/Jacarta libraries when you need some utilities.
Check out what google has to offer:
http://code.google.com/p/guava-libraries/
It's Apache licenced too and contains Googles new Collection Library 1.0

It's for Java5 only, therefore currently only mobile developers for Android can benefit of it