Monday, February 26, 2007

Accepting the Q factor

http://www.w3.org/2000/09/xmldsig# is the namespace for the schema for XML Signatures - one of the many, many schemas you end up accessing if you do XML Schema based completion for WS-SecurityPolicy (2005) (part of our WSDL policy editor in the Eclipse plugins for Sonic ESB Workbench). Why is this one special? For the following reason -

If you access http://www.w3.org/2000/09/xmldsig# from Mozilla Firefox you will get back the schema at http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd (through an HTTP re-direct response code 303) but if you use Java's java.net.URL.openConnection() (basically through HttpURLConnection) you get an HTML page and not the Schema (XML) which our Schema loader does not particularly appreciate.

It took a while for me to understand why the same URL is behaving differently. Using Eclipse 's TCP/IP Monitor I captured the headers sent by my code and used LiveHTTPHeaders for Firefox.

This is what Firefox sends -

GET /2000/09/xmldsig HTTP/1.1
Host: www.w3.org
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive

and this is what it receives -

HTTP/1.x 303 See Other
Date: Mon, 26 Feb 2007 11:50:20 GMT
Server: Apache/1.3.37 (Unix) PHP/4.4.5
WWW-Authenticate: Basic realm="W3CACL"
Location: http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd
Keep-Alive: timeout=2, max=99
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1



But when HttpURLConnection sends the request this is what it sends -

GET /2000/09/xmldsig HTTP/1.1
User-Agent: Java/1.4.2_12
Host: www.w3.org
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive


and this is what it receives -

HTTP/1.1 303 See Other
Date: Mon, 26 Feb 2007 11:56:47 GMT
Server: Apache/1.3.37 (Unix) PHP/4.4.5
WWW-Authenticate: Basic realm="W3CACL"
Location: http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/Overview.html
Keep-Alive: timeout=2, max=99
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1


Notice the difference in the Location header
Firefox : Location: http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd
Java URLConnection : Location: http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/Overview.html

The problem turns out to be in the Accept header set by Java URLConnection by default (or I guess the Sun HttpURLConnection implementation).

Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2


Note no text/xml as in Firefox. Although there is a */* its 'q' value is lower than text/html and the nice server at www.w3.org uses this to change its output to suit what is best accepted by the user-agent. I guess since they are the standards organization they should do this :-). Fixing the accept header fixes this behaviour. Is there something I am missing in my understanding of how URLConnection works?

Saturday, February 24, 2007

Experiments with development on the Nokia 6265

I recently got myself the Nokia 6265 CDMA phone. It is a nice phone and I intend to write a reveiw of it in my other blog one of these days. The phone supports the Nokia's Series 40 3rd Edition development platform and I am trying out developing Java Micro Edition applications for it. I hit some interesting problems and found some solutions - I am trying to chronicle them here.

Firstly, I have never done development for a mobile phone so I had to start from scratch. I wanted to know what I could do with my phone and Nokia had quite a lot of information. They have these videos of their Eclipse integration called Carbide.j which seemed interesting although a little painful (being a graphical modeling like UI and all).

I found the Nokia site a tad vague about what exactly is needed for what but eventually I figured I needed the Nokia Series 40 3rd Edition SDK. Now, Nokia has 3rd Edition Feature Pack 1 and 3rd Edition Feature Pack 2. It wasn't very clear to me which one would work and I chose the base version and thankfully that is the right one. Only one phone so far supports Feature pack 1 as far as I know.

After installing the SDK, the documentation said that I need a JDK, Eclipse, NDS for Java ME, and then I should install SDK. Did I mention that the Nokia site is slightly confusing? :-) I went off in search for NDS and found out that it is now renamed to Carbide.j and is a 135+ MB download. While it was downloading, I thought I would try and locate J2ME support in IntelliJ Idea.

IntelliJ Idea J2ME integration

Now, this is the nice part.

I went through the IntelliJ Idea documentation which described how to set up a J2ME module and the only part that looked a little hard was the Mobile JDK configuration. I crossed my fingers and pointed at the Nokia installation and IntelliJ found all it needed - bootclasspath, javadocs, emulator, etc. It is really sweet!!

Everything works out of the box - compile works great, and when you run it runs against the Nokia emulator. Even debugging is seamlessly supported!! Fantastic - and no need for Eclipse or the Eclipse plugins! Needless to say I cancelled my Carbide.j download. You do not need it for development on the Nokia phones. I hope the Nokia guys put this on their documentation.

One strange problem so far (in my HelloWorld application) has been that the jad and jar generated by IntelliJ is not working on my phone or on the emulator. It fails with an error message saying "Application invalid. Delete?". There is a temporary file that Idea is generating which seems to work. I think I am missing something here. I would appreciate any help.


Annoying UI Change in Firefox 2.0

Firefox 2.0 is out and I upgraded from 1.5.x to 2.0. While closing a tab I realized something was amiss. In 1.5.0 there are two ways to close a tab - each tab is associated with a close button and the tab bar has a close button at its extreme right which is applicable to the most active tab. That is the button I use the most and that is gone from 2.0.



Why do I think this is an annoying change? The old button on the right of the task bar never moved - which meant irrespective of which tab I was on I could aim my mouse over it (a centimeter square area that my hand and wrist manage to reach magically) and close without having to think too much about it. Now, I have to look for the close button and my target has just expanded horizontally to unpredictably include my entire horizontal resolution. Another reason was I could close many consecutive windows one after the other just pressing the button multiple times because the selection automatically moves to the next tab. No longer possible. Arghhh! Hopefully there is a preference somewhere which can get it back - but so far I haven't found it. In its place there is a drop down of all windows to quickly navigate to it.

Well...sigh...I still love Firefox and I'll just use Ctrl+F4 more frequently...