Wednesday, March 30, 2011
unintentional multilingual woes of a tool for computational linguistics
offshore rush hour
Saturday, March 26, 2011
bing goes boing with axis2
Have you ever tried using the Bing Maps web services using Axis? The curious aspect of these web services lay in how one had to request a token. This amounted to a request that used digest authentication instead of basic authentication. This was not such a problem if you had used ye olde Axis.
Unfortunately, you had moved into the future and had generated client code using the WSDLs and the tools in the JAX-WS RI. You then prepared to use this code atop the Axis2 JAX-WS stack (at which point you did not heed the pealing of alarm bells in the distance). Voila! The stack could do nothing for the first HTTP 401 response. There you were, in the middle of the ocean, staring at sharks as they discussed the latest episode of the hottest new sea soap opera, while waiting for a good time to transfer you to the dinner plate.
You had seen this code work with the standard Java Development Kit. Why was Axis2 being so different and difficult? You look at the code you wrote to use the generated client classes to see what you did wrong, to see if you had missed a step. You see the call to Authenticator.setDefault
with the credentials. You know this is all you need to do. And yet.
Oh! goes your brain. Axis needed the Commons HTTPClient to help it with digest authentication. Surely, Axis2 could use Commons HTTPClient as well (after all, some of the developers on Axis2 had also committed code to Commons HTTPClient). You open axis2.xml
and the first wave of horror hits you. The configuration already uses a class derived from Commons HTTPClient. The second wave of horror hits you almost immediately. They wrote their own middling class that left all the glory of Commons HTTPClient behind and treated it now as a messenger.
At this point, you hunt for something to hurt, wound, maim and dismember as you gnash your teeth.
Miraculously, Commons HTTPClient has a few tricks of its own and all you really need is the magic below.
import org.apache.commons.httpclient.Credentials; import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.auth.AuthScheme; import org.apache.commons.httpclient.auth.CredentialsNotAvailableException; import org.apache.commons.httpclient.auth.CredentialsProvider; import org.apache.commons.httpclient.params.DefaultHttpParams; CredentialsProvider provider = new CredentialsProvider() { @Override public Credentials getCredentials(AuthScheme scheme, String host, int port, boolean proxy) throws CredentialsNotAvailableException { Credentials creds = new UsernamePasswordCredentials("BingMapsUserName", "BingMapsPassword"); return creds; } }; DefaultHttpParams.getDefaultParams().setParameter( "http.authentication.credential-provider", provider);
And that, as several not-so-famous people have said before, is all. You can get rid of Authenticator.setDefault(new AuthenticatorImpl("BingMapsUserName", "BingMapsPassword"))
. Don't forget to replace BingMapsUserName
and BingMapsPassword
with the values that you use. I'm sure you can figure that out. If you can't, you deserve to continue reaping the benefits of Axis2.
As soon as you find the right opportunity, walk away very slowly from Axis2. Go find something else that doesn't look like a school project.
Saturday, March 19, 2011
the king has not left the building
I had saved this novella for the end, but it was not a great way for me to end the collection. I should have tackled this right after my first pick, Fair Extension, where King explores the familiar Faustian bargain. Once Dave Streeter has signed the dotted line with George Elvid (hint: shuffle the letters in the last name), a cousin of Leland Gaunt, no doubt, King describes the unfolding of events like a long news story. It reminded me of Frederick Forsyth's The Art of the Matter.
Big Driver is the story of a woman who pays the price of taking a shortcut and then exacts her revenge. This is the stuff of EC comics with all humour of any kind stripped away. Rape is serious business and King makes sure every smile we crack is with Tess and never at her. The appropriate presence of films like The Last House on the Left and The Brave One is an Eastwoodian touch -- they do not beg to be treated as clever as they would have been in a Tarantino script.
A Good Marriage explores a good idea that I would imagine has been explored before (pointers welcome): imagine that you were the wife of someone like Mr. Brooks. Darcy Anderson discovers her husband's dark secret in a way that a character in a Stephen King story would and then tries to come to terms with it. King was inspired to write this story after the general public refused to accept that Paula Radar, the wife of Dennis Radar, the BTK killer, had been married to him for about thirty years and never knew anything about his evil deeds. The possibility is chilling as is the story.
Each story has a character killing someone (indirectly in Fair Extension) and ends with the character coming to terms with the deed, perhaps even being at peace after experiencing the moral conflict familiar to those who abhor violence. The writing is uncomplicated and boasts the ease, comfort and familiarity that King surely has come to enjoy after all these years. It's time to find a copy at a book sale and fill the spot once I (hopefully) manage to begin Lisey's Story.