Archive for November, 2006

Is WS-I open? Look at their test license…

Sunday, November 26th, 2006

“WS-I is open industry oganization chartered to promote web service interoperability across platforms, operating systems, and programming languages”

Or so they say. From the WS-I test license:

License Grant: You (the “Licensee”) are hereby granted a personal, non-transferable and non-sublicenseable, nonexclusive, world-wide, royalty free license (the “License”) to use the WS-I Test Material (including software and documentation) solely for the purposes of evaluating this material and providing feedback to WS-I (the “Licensor”)… You may not distribute copies of the Test Material to other parties for any purpose, including for the purpose of allowing such other party to use the Test Material. Nor may you modify or incorporate the Test Material into any other software.

It seems to me that the licensing is directly opposed to the goal. I can only use the WS-I materials to provide feedback to WS-I. I can’t use it for testing my services to ensure that they conform to the basic profile. For framework builders, the best way to ensure that services built with that framework conform is to integrate the WS-I testing toolkit directly into the build. But, as an open source project, we are not allowed to do that, because doing so would involve redistribution. Whats the point of WS-I if you’re only allowed a personal license?

Gmail on the desktop?

Saturday, November 18th, 2006

I’m thinking about switching all Envoi Solution’s email to be hosted on GMail, with their hosted applications. I like Gmail in general, but one thing is getting to me: the lack of true support for email on the desktop. POP is rather lame and doesn’t provide access to all of GMail’s capabilities.

There happen to be two pieces of software which have been created to accomplish this goal. However they are both broken and seem unmaintained.

  • GmailerXP: This has a nice interface, but just doesn’t seem to work. It was last updated in 2004, so I’m guess the GMail API has changed a bit since then. I tried downloading the sources, but I’m not really sure whats going on.
  • Gmailclipse: I can actually log in to this one, but I can’t read my messages as I get a NullPointerException. No sources available currently.

I’ve emailed both the authors in an attempt to get them to try fixing things up a bit. Will post an update if I hear back.

Anyone know of others?

An American’s thoughts on China while dealing with jetlag

Saturday, November 18th, 2006

Its Saturday morning, and I’m up before 7 AM. And not because I have something to do today, no its because I’m dealing with jetlag from my trip back from China. I just spent two weeks in China working with several IONA employees and it was quite an experience…

On hospitality: The IONA team treated me great, took me out to eat, set up accomodations, took me to the great wall, and much more! Many many thanks to Bo who arranged the trip and made everything completely worry free.

On new foods: I tried jelly fish, donkey, cow throat, and BBQ’d goat ribs (yummm). I was not too much of a fan of the texture of both jelly fish and cow throat. Both were an odd mixture of chewy and crunch. Also, the Chinese seem to like eating their raw fat - for instance, pig’s fat in BBQ sauce. While it tasted good, the American in me was not comfortable with this, I kept thinking “but this is so bad for you…” Things I did not try: chicken feet and pig’s tail.

Yep, its communism. The Beijing Summit was going on the first week while I was there. They stopped letting people on the highway one night to make traffic better for an African president who was being carted some where one day. Supposedly they’re going to prevent people from driving on the streets at the olympics as well.
There are an interesting set of bars that the expat community seems to visit just off of Sanlitun’s main street. The main street itself seemed kind of sketchy though. I liked the Hidden Tree as it provided a wide variety of Belgian beers, which was a welcome change after to weeks of Tsing Tsao and Yan Jing.

On jet lag: I pulled an all nighter right before I left, staying awake until 8:30 AM when my flight took off. The idea being that it helps me pre adjust to the time change. I woke up on my second plane at 7 AM Michigan time, giving me about 7 hours of sleep, and was able to stay awake to 10:30 PM Michigan time last night. I’m wide awake this morning now, so it seems to have done the trick. The true test will be later tonight though.

On the Internet: Both my hotel and connection at the IONA office were rather dodgy. Often times my connection would be reset to any number of servers. This was highly annoying and made me thankful for my wonderful Cable connection at home and the life changing Verizon wireless card I carry.

On touring: I toured a bit with Oisin and Adrian and saw the Great Wall, Summer Palace, Tienneman square, and the Forbidden City. My legs got real tired. Pictures are here. (Yes, I finally got a Flickr Pro account. Woo!)

JSON/REST Services with CXF and Jettison

Sunday, November 12th, 2006

A couple weeks a go someone mentioned to me the idea of building JSON services with XFire/CXF. The thought hadn’t really occurred to me, but it seemed like a good one. If you’re already building a REST or SOAP web service, why not allow JSON as a format? JSON has a couple advantages. First, it doesn’t have to be as verbose as XML. XML requires both an end and start tag. JSON has brackets. Second, it is easier to work with for Javascript developers.

After about two evening hacking sessions, I came up with Jettison - as in let’s Jettison our XML and use JSON! Jettison is a StAX implementation that reads and writes JSON. You simply tell CXF about the new StAX implementation and what Content-Type you’re serving. Combine this with the CXF REST support and we have an instant JSON REST web services!

Currently Jettison implements two ways of mapping XML concepts to JSON - the BadgerFish convention and also a “mapped” convention. The later is my favorite as BadgerFish seems very verbose and hard to work with for javascript developers. The mapped convention allows you to map XML namespaces to prefixes for JSON elements. For instance, if we map “http://acme.com” to the “acme” prefix, this XML:

<price xmlns="http://acme.com">10.00</price>
Can be turned into this JSON:

{ "acme.price" : { "10.00" }

This assumes that there is some out of band communication of the JSON structure, however for many (most?) situations this is OK as it is being consumed by javascript anyway. And the less parsing you have to do there the better!

Lets take, the customer service again from my previous example and look at one of the operations:

@Get
@HttpResource(location="/customers")
@WebResult(name="Customers")
Customers getCustomers();

Our operation here is pretty simple. We get a request on /customers and we want to return a List of customers. You may wonder why we aren’t returning a List directly. While CXF supports that, it generates ugly XML infoset, so I created something a bit more visually pleasing.

Setting up the JSON parser on the endpoint is fairly simple. We need to create a map of the how to map XML namespaces to prefixes for our JSON elements. Then we’ll create a StAX XMLInputFactory and XMLOutputFactory for the service:
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
sf.setServiceClass(CustomerService.class);
...
HashMap<String, String> nstojns = new HashMap<String,String>
nstojns.put("http://customer.acme.com", "acme");
MappedXMLInputFactory xif = new MappedXMLInputFactory(nstojns);
properties.put(XMLInputFactory.class.getName(), xif);
MappedXMLOutputFactory xof = new MappedXMLOutputFactory(nstojns);
properties.put(XMLOutputFactory.class.getName(), xof);
sf.setProperties(properties);
sf.create();

Now if we do a GET on http://localhost:8080/json/customers, we get JSON back:

{"acme.Customers":{"acme.Customer":{"acme.id":"123","acme.name":"Dan Diephouse"}}}

We also have an addCustomers operation:

@Post
@HttpResource(location = "/customers")
long addCustomer(@WebParam(name = "Customer") Customer c);

Now we can post JSON to our services:

$ cat add.json
{
"acme.Customer" : {
"acme.name" : "Ricky Bobby"
}}

$ wget --post-file=add.json http://localhost:8080/json/customers

And then a GET on http://localhost:8080/json/customers will return:

{"acme.Customers":{"acme.Customer":
[{"acme.id":"123","acme.name":"Dan Diephouse"}, {"acme.id":"1","acme.name":"Ricky Bobby"}]
]}}

If you want to explore this example more, I’ve put together a demo which can be downloaded here. It publishes a set of REST JSON, REST XML, and SOAP XML services complete an HTML/Javascript demo and example files which you can use with wget. I’ll integrate this into the CXF distribution sometime soon, but currently the CXF samples all use ant, and I need to figure out whether I want to switch to ant or find a Maven strategy for the samples.