Cookie handling with Apache XML-RPC

The example on the Apache website that explains how to pass cookies when calling an XML-RPC service is unfortunately... a bit b0rked. It doesn't compile, for starters. It's also quite a bit more complicated (and handwavy) than it needs to be. I don't know if this is because the API has changed over time. I tend to think it has suffered the copy-paste equivalent of chinese whispers from an origin in some mailing list.

Anyway, I needed to send a single sign on (SSO) cookie to an XML-RPC service recently. I'm using Apache XML-RPC 3.1 (I notice in the Javadoc that this code might be slightly different if you're using a later version). Here's roughly what I did:

First, the standard, boring stuff:

XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("https://myservice.com/api"));
XmlRpcClient client = new XmlRpcClient();

Now, the juicy part. It's really, really easy. Look, ma, so much less code than the example on the ws.apache.org website, and it's even syntactically correct!:

XmlRpcTransportFactory factory = new XmlRpcSunHttpTransportFactory(client) {
  public XmlRpcTransport getTransport() {
    return new XmlRpcSunHttpTransport(client) {
      @Override protected void initHttpHeaders(XmlRpcRequest request) throws XmlRpcClientException {
        setRequestHeader("Cookie", myLovelyCookieData);
Update: Fixed a bug in the code. Oh, the irony. That'll teach me to be so arrogant :P

AddThis Social Bookmark Button


Find a file inside a zip

Brutally simple shell script I often use to find a class file that I know exists somewhere in a directory tree full of jar files (but generally useful for finding files somewhere in a directory tree of zips):

for zip in $*                                                                           
  echo $zip                                                                             
  for file in $(unzip -Z -1 $zip)                                                       
    echo "$zip:$file"                                                                   
I put this in a file called zipdump, then do things like this:
find -name "*.jar" | xargs zipdump | grep SomeClass
And get:

AddThis Social Bookmark Button


Listing Chinese Words by Frequency of Use

A commenter on my previous blog entry, Yong Huang, pointed me to some wonderful research he did using search engine results to compile a list of Chinese characters in frequency order. I managed to miss his comment when he posted it back in March (d'oh. I really should have paid more attention to my blogger settings), but it's an interesting read and technique:


AddThis Social Bookmark Button


Getting serious about Mandarin

I'm finally making a big effort to learn mandarin properly. In addition to taking formal lessons at UC Berkley starting in February, and learning about usage from Cindy, I'm using flash cards to increase my knowledge of Chinese characters and their mandarin pronunciation (including the tones, which I've had a hard job remembering up till now while picking up mandarin informally through random conversation).

I've been using some tricks to memorize characters, and this technique seems to work well for me.

Here's the first set of characters. The first ten are numbers, and mostly pretty easy.

一 二 三

one (yi1), two (er4), three (san1). These are quite possibly the simplest Chinese characters ever. :)

four (si4). This one is kind of easy for me to remember, since I visited sichuan last year, and this character was everywhere :) It's also a box with four sides.

five (wu3). I convinced myself that this character has five distinct lines in it, which made it easy to remember (although it actually has only four strokes - the middle horizontal line and the smaller vertical line are combined together as a single stroke).

six (liu4). I found this one a bit tough. I sort of convinced myself that it looks like a lion (the sound liu4 is a bit like the English "leo", as in "Leo the Lion").

seven (qi1). This was tricky too. Until I turned my flash card upside down and realized it looks like an upside down 7 with a stroke through it. Nice.

eight (ba1). No tricks here, I just remember this character because it's pretty simple.

nine (jiu3). With the right amount of squinting, this character looks like a roman J and lower case i without the dots and with a weird line connecting the J to the top of the i. So if you can remember that jiu3 == nine, it's pretty easy.

ten (shi2). If you have Chinese friends, you might notice that sometimes when they say "ten", they make a hand gesture where they cross both index fingers over each other. If you ever wondered why, this character is the answer :)

And here's a random sampling of two more non numeric characters:

ask (wen4). This combines the character for door (门 men2) with the character for mouth (口 kou3). Can think of it as opening the door of your mouth to ask a question. The sound (wen2) is also similar to the sound for door (men2).

good (hao3). This combines the characters for female (女 nü3) and offspring / son / child (子 zi3). I guess that's good and harmonic.

Anyway, lots more where those came from. Kind of fun to learn.... :)

AddThis Social Bookmark Button


Still a bit proud

Looking at Steve Muench's blog with its screenshot of JDeveloper 11g production makes me feel a little bit proud of what we built. Somehow I left Oracle with the feeling that I hadn't been very productive for a while, but seeing what Steve posted reminded me that the team really poured a lot of stuff into 11g. 

Just visually from the screenshot, you can see the new look and feel I implemented based on a design from our talented visual design team. It got a lot of flak (experience is teaching me that fear or dislike of change is a very common trait), but apart from being unbelievably blue, I think it's quite attractive. 
Also shown in the screenshot is quick search (which, honestly, we always referred to internally as "Google-like search". Hehe). This was something I wanted and so hacked together on a lazy afternoon without any kind of design or project plan while we were supposed to be in bug fixing mode. Despite its birth, it somehow made it into the final product in a very visible way. A very talented member of the team (Neil) did some fantastic work improving the visual design of the component while I was buried under classloading related tasks. One of the things I loved about the JDev team in the early days was the freedom to do this kind of innovation. Although that flexibility to innovate had been almost entirely crushed by the time I left, you could sometimes still get away with it and succeed. 
Finally, Steve blogs elsewhere about log window search, which people begged and begged for until we finally relented and I was assigned the task late in the day. 
I'm still very proud of these things, and even prouder of all the other innovations my old team implemented. 

AddThis Social Bookmark Button


The Consequences of Job Hopping

I was pretty comfortable, and definitely not bored in my old job. Had a lot of stuff to do. The trouble though with saying in the same role for a very long time is that it's really hard to find time, reason, or energy to step outside your main job responsibilities a little bit and learn something new. I must have encountered a gazillion technologies and products that I really wanted to get a chance to play with but never did.

I wasn't sure when I quit my job at Oracle that working at Google would be any different necessarily. I felt like I'd probably swap my old batch of responsibilities for a new batch of responsibilities, and it would kind of be similar (but hopefully more fun). One thing I somehow failed to realize was that the really great thing about changing jobs is that it gives you that rare chance to really stretch a bit and learn something new.

So in my three months at Google so far, I've been able to get to know some fun new stuff. And instead of just reading about this stuff, I actually get the chance to play with it all the time. For me, this experience has reignited my passion for learning. I'm hoping that I can keep up the momentum.

Here are a small subset of the things I've learned about and used so far (not necessarily all Google technologies):

  • GXP is a templating engine that's really useful for putting together dynamic web pages. I never got much of a chance to play with JSP, JavaServer Faces etc. before. I like that GXP is straightforward and easy to use. Haven't built anything spectacularly complex with it yet, but it works fantastically well for simple dynamic web content.
  • IntelliJ Plugin API. I'm still getting my head around this. It's familiar to me in many respects (there seem to be only so many ways of designing IDE plugin APIs). The API is a tad on the underdocumented side, and there sometimes aren't enough samples. I'm really learning "from the other side" what it's like to have a plugin API without source code. I really wished we'd been able to do better about that at Oracle with JDeveloper, and I hope one day JetBrains might see the light too, and make it easier for its plugin developers by giving them access to source code. But it's still a nice API, and you can get a lot done with it.
  • SWT. I've been using Swing for 10 years, and somehow got into the "SWT is evil" mentality without really giving it a chance. It's actually a pretty fine API for most UI problems. Slightly depressing to see that layout seems to be an intractable problem that all widget toolkits seem to have trouble making straightforward.
  • BigTable is cool :)
  • Google Chart API makes it really easy to draw pretty graphs 'n charts 'n stuff
  • Debian package management
  • GNU Fortran don't ask. hehe.

Well... that's not a comprehensive list, but I think I've been able to learn quite a bit more over the last few months than I did over about a year or two. Changing jobs is good for your brain :)

AddThis Social Bookmark Button


Brings back memories

Ah... this brings back memories: Feel motivated yet? (via: http://thebode.blogspot.com/2006/07/demotivation.html)

AddThis Social Bookmark Button


Shirley that's not Shirley

Warning: herein lie spoilers!

Somewhat surprised to see Shirley Manson, Scottish lead singer of rock band Garbage show up in the second season premier of Fox's Terminator: The Sarah Connor Chronicles last night. Bit of a "holy crap, that's Shirley Manson" double take when the scene opened on her as an evil CEO who actually turns out to be a T-1000 model terminator (T-1000 is the gloopy, liquid metal model that Robert Patrick played so well in Terminator 2) hell bent on bringing about the Rise of the Machines.

Haven't quite figured out yet whether she's a good actor or not... She certainly came across as kind of cold, dominating, fearsome, and a little stiff. At first, I thought her acting was a bit iffy, but the reveal that she's actually a T-1000 sort of changed my perception a bit.

Was really nice hearing a genuine Scottish accent on US network television too. Scottish actors don't get to play the Bad Guy (or Lass) in TV sci fi nearly often enough. Witness the saccharinely well behaved Carson Beckett from Stargate Atlantis (Paul McGillion's accent is also faaar from genuine, probably on account of the fact that he moved to Canada when he was 2)

AddThis Social Bookmark Button


Nooglerization done (but is it ever, I wonder... ;) )

My first two weeks are over, now I'm taking a quick bout of unpaid leave to take Cindy to Paris and Barcelona. She's never been to europe - and even though I'm from Europe, it's a big place and I've never really spent much time in those two cities. We're also going to spend some time with my parents in the south east of Spain.

Cindy swears that I've put on weight in the mere two weeks since I joined google on account of the free food. This is an assertion which I stringently deny, alas to no avail. I try to convince myself that all of the cycling between buildings (or walking in the fairly regular no-available-bikes scenario) is burning off enough calories to make up for the additional input. I may or may not be kidding myself.

I've been using the convenient excuse that, since it takes some period of time after initial employment before registering for the gym is possible, working out and getting rid of the extra pounds is something I can put off until after our vacation.

Anyhow, looking forward to taking a break, and then getting down to some serious geekyness (er.. geekery?) when I get back. I haven't written code for a while, and my fingers are getting twitchy.

AddThis Social Bookmark Button


On shortcuts

I made the Big Switch from Windows to Linux at work several years ago, and never really looked back. For whatever reason, our version control system and builds are always about twice as fast on Linux compared to Windows. I'm also much more comfortable in a UNIX-y shell / scripting environment than I am in Windows Command Prompt, probably because of hours spent in various computer labs at university when I really should have been doing something more fun (like drinking beer).

As well as the raw productivity gain from the faster environment, I also customized my environment a great deal to minimize keypresses. For example, where most other people in my team might type something like this:

cd $ADE_VIEW_ROOT/jdevadf/modules/ide/src/oracle/ide
ade co -nc Ide.java MainWindow.java
cd `pwd`
emacs Ide.java MainWindow.java
cd $ADE_VIEW_ROOT/jdevadf
make release
I type:
m ide/src/oracle/ide
co Ide.java MainWindow.java
emacs Ide.java MainWindow.java
Doesn't seem like much, but over many many months and years of coding, all those extra keystrokes add up... Better still, I had some immensely powerful tools in my box that would invoke compound commands to provide interesting information.

So, if I wanted to quickly find a file in our source control system (an operation that can be sped up by grepping some version control metadata files, chopping the file up to make it readable), I'd type wi SomeFile.java (where is?). If I wanted to know which module (out of about 600 in our system) was responsible for delivering a jar file (again which involved a lot of grepping through multiple files and cleaning up the output), I could ask wm foo.java (which module?).

These utilities ran ridiculously quickly, because I figured out tricks that were somewhat specific to our system. For example, grepping the version control files to locate a file is way faster than using "find", since it's a grep on a single file instead of a directory tree traversal. Their real power was in compound commands. I could check out all files with the extension xml that contained the string "brian.duff" with a command like this:

wi '\.xml$' | xargs grep -l 'brian\.duff' | xargs co
This is all fine and great, but there's a huge downside. Every time I sat at someone else's terminal to help them with some problem and attempted to run some commands, I had to remember to type the longwinded versions of all these commands again. Like being thrown back into the dark ages. Worse than that, it actually slowed me down even compared to someone without the shortcuts, since my fingers would frequently forget and type my shortcuts instinctively even though my higher brain was fully aware that they wouldn't work. Finger memory is a strange thing.

AddThis Social Bookmark Button