Seriously, I've just wasted hours ...
I bought a BlackBerry Storm (I have Verizon so no Android for me) when it was available thinking I could finally start doing some J2ME programming (think 6 year old gets first erector set). After some initial learning, I've been writing small apps to interact with Facebook and Twitter. To run these apps locally, I have to use the MDS server. The MDS server allows your locally running BlackBerry Simulator to communicate externally, for example, an HTTP request to a website.
First, I really like the Twitter API; it's effortless REST programming. The problem is that I kept getting 401 unauthorized HTTP responses. How could this be on such simple code?
conn = (HttpConnection) Connector.open(resource, Connector.READ_WRITE);
conn.setRequestProperty("Authorization", "Basic "
+ BasicAuth.encode(creds.getUsername(), creds
Enter the IBM support engineer ... after all, I'm used to troubleshooting, right? First, I checked that the request and response would work using cURL which looks something like curl -u username:password http://twitter.com/statuses/friends_timeline.xml. Success, no problems there. Then I made sure the authentication method was accurate by using Wireshark to compare cURL's and the MDS server's GET requests. Lo' and behold, there's no Authorization header when using my BlackBerry app. So then I checked to make sure I wasn't forcing a premature connection, and subsequently changed the code to match the above snippet . Still no luck. I did a bit of Googling and found this, http get authorization header eaten.
In the HttpHandler stanza, you have to set application.handler.http.AuthenticationSupport to false in MDS_root\config\rimpublic.property. Truthfully, I'd never figured this out without the above post. Even if I had seen the AuthenticationSupport property by chance, I'd assumed true to be the correct value. Hopefully someone comes across this post much sooner than I came across the other ...[Read More]