Tuesday, December 19, 2006

WebServices --- Java/.NET interop issues

I've been working on a project where I need to port an existing service written in C# to Java. Your first question would be -- WHY ?? One should be able to access the service irrespective of the language its written in; So whats the point in porting a .NET service to Java ? I am not too sure about this, but I think the client wants all his applications in one language, so that its easy to modify it as and when needed.

With that answered, one would think its pretty much straight forward to port such a service. After all Java and C# have similar frameworks/libraries and constructs. Well.. that’s where most of us go wrong :(. Let me explain ---

This service is currently used only by .NET clients (but would soon be used by Java clients too). Many methods of the service return .NET specific data types like DataSet. This works fine with .NET clients since DataSets are serializable. When you come across such a method while porting, you realize you are pretty much screwed. Java doesn’t understand DataSets !! So, this is what we did -- we wrote a class which contains the following:-
1) Column names array (from the ResultSet metadata)
2) Column types array (from the ResultSet metadata)
3) Array of rowData objects ( each rowData object is an array of column values obtained from the resultSet)
4) Table name (required by DataSet)

An object of this class can be serialized and sent across to the client. On the Java side, you can create/generate this class and use it to read the results. On the .NET side, you can set the metadata and rowdata objects to a DataSet and also set the table name. You could then use that DataSet as before.
We could not return a 2 dimensional array of values (instead of array of rowdata), since we had problems deserializing the 2 dimensional array on the .NET side.

There have been quite a few such issues over the past couple of weeks, and I am sure there are more to confront. I’ll post again when I come across such issues. Btw, if you are designing web services with Apache Axis, do take a look at their wiki page for .NET interop issues ---> http://wiki.apache.org/ws/FrontPage/Axis/DotNetInterop

Some points for making interoperable services. Please avoid the following (taken from the wiki) :-
* Standard Java Collection classes.
* Typesafe enumerations. Use static final variables within Java instead.
* Multi-dimensional and jagged arrays.
* Sparse arrays (allowed in SOAP 1.1, not in SOAP 1.2).
* The Java char datatype is not supported because of an omission in XML Schema.
* Avoid using the same method name multiple times with varying parameters on a web service.


One last point --- If you are using Axis, please start with the WSDL first. Do not generate the WSDL from your classes/interfaces. Its a BAD idea !! Doing the WSDL first would help you comply with the W3C xml standard types, so you'd be almost guaranteed to interoperate. Unfortunately, we learnt it the hard way :(

Wednesday, December 06, 2006

Cordyceps

Came across this video on Yodha's blog. "The fungi infects the ant's brain, makes it go mad, pushes the ant to higher ground, kills the ant and grows a spike out of its brain !!". Another lovely narration by Sir David Attenborough.

Saturday, October 14, 2006

The best way to conserve....

is for humans to disappear from this planet.



Source : timesonline UK

Wednesday, September 27, 2006

7 signs of an entrepreneur

Came across this site while browsing casually.
So, how much of an entrepreneur do you have in you ?

Friday, September 01, 2006

Language Wars

I just finished reading this article on joelonsoftware and it is definitely an interesting read.


"In particular, a debate between the C#/.NET/IIS stack and the Java/J2EE/Apache/Solaris stack and the PHP/Apache/Linux stack could go on and on for years and years and you'd never find the right answer. That's because there are so many pros and cons of all these platforms that advocates of each side can debate and debate and never get any closer to the Truth, but it sure as heck is a fun debate."


Couldn't agree more !! You would come across such a debate in any IT/Software development firm, and quite often you'd be a part of such a debate. And it doesn't stop at programming languages... Developers love to argue over their favorite IDEs (Eclipse/IDEA/VS etc) too.


"Ruby is a beautiful language and I'm sure you can have a lot of fun developing apps it in, and in fact if you want to do something non-mission-critical, I'm sure you'll have a lot of fun, but for Serious Business Stuff you really must recognize that there just isn't a lot of experience in the world building big mission critical web systems in Ruby on Rails......"


This part is particularly interesting :-). I dont have enough Ruby or ROR experience to comment here, but I am sure some of my colleagues would be flaming Joel Spolsky about such a remark. Now that would be good fun to watch :-)

Wednesday, August 23, 2006

When Tigers attack....

Read this article --->

http://www.wildlifetrustofindia.org/html/news/2004/040609_joymala.htm



Now check out the video footage of the same incident

http://www.wildlifetimes.com/video/tiger.wmv



The tigress saw the ankush coming, dodged it in mid-leap and took a swipe at Pegu without actually landing on the elephant, which had stepped back,” Menon said.


What now happened was even more amazing. As the tigress landed on the ground Joymala quickly pinned her down with her left fore foot and tried to control it with its trunk. The tigress struggled under this weight for at least half a minute roaring, as other people in the vicinity shouted and fired shots in the air. In this commotion another attempt was made to dart it, but even this shot was off the mark. The tigress finally struggled loose and ran away.


The wonders of wildlife !! Marvelous.

Someday I'll work for the conservation of our wildlife.

Until then, I guess I'll be writing code :-)

Wednesday, April 26, 2006

Sahi --- A nice Web Automation and Testing Tool

We are using Sahi as a functional testing tool on my current project (Well, what else would you expect when Narayan is on the same team :-). Having used Selenium on my previous project, I find quite a few features of Sahi a lot more helpful in writing functional tests.

  • The record/playback feature is fantastic. While you are recording a functional script, you can append assertions to it by simply hovering over the required text (or other document objects) and clicking the assert button on the recorder.

  • You can assert text in any/every row in a table. This is a particularly useful feature when you have a sorted list of items to display and you want to assert that they are ordered correctly.
  • The ability to run multiple scripts simultaneously (i.e. in multiple threads) is wonderful. There are a couple of benefits in running your test suite using multiple threads – 1) it makes sure that you don’t have interdependent tests (i.e. some test that depends on the data created/modified by a previous test) and 2) Runs the entire test suite in a fraction of the time.

  • You can hit any remote machine and record/run tests against it. For example, if you have a build deployed on a production/QA machine, the QAs/testers can record and run the suite of tests on that machine instead of having to deploy the build on their local machine. (We are using this setup on our project and its working very well).
  • The kind of support you get when the author is on the same team :-).

I have used Selenium quite a bit on my previous project and I have liked it a lot. With Sahi, I see myself writing a lot more functional tests than I used to do before (and it doesn’t take much time to run them all).

Monday, January 23, 2006

In search of a Tiger

Narayan and I participated in a tiger census conducted by the forest department at Balle near Kabini. We were there for 4 days, trekking through the forest in search of pug marks, scat and prey animals (deer, sambar, wild boars, elephants etc.). We worked with the RFO (Range forest officer), Mr. Ravindra Kumar and few of his forest guards. Here’s a brief description of my experience during those 4 days.


Counting tigers in the wild

Well, it’s not an easy task. Chances of spotting a tiger in the wild are very low. A tigers' stripes may look striking in a zoo, but in the wild, it’s very well camouflaged. The thick vegetation of the south Indian jungles makes it a lot more difficult to spot one. We were in the jungle for 4 days, but weren’t lucky enough to see a tiger.

The census is conducted for a period of 6 days. There are 2 parts to it :- 1) Trek for about 5 -10 kms in the forest searching for tiger pug marks, scat and scratch marks on the barks of trees. 2) Walk along line transects of 2.4 kms, stopping at every 400m to note down the kind of vegetation, scat and sighting (if any) of prey animals. With this data, (i.e looking at the approximate number of prey animals) the forest department tries to estimate the number of tigers it could support, and also the distribution of tigers in various parts of the forest. This is nothing more than an informed guess and by no means an absolute number (or even close) of tigers in the wild.

Radio tracking tigers in the wild has been tried by conservation scientists like Dr. Ullas Karanth in various parts of India. Although this sounds to be a viable solution for counting tigers, it has a few problems :- 1) Catching tigers in the wild is a very difficult task in itself .. 2) A more serious problem is tranquilizing a tiger when seen. If the dosage is too little, it doesn’t serve its purpose; if it’s too much, it could be fatal. The forest guards told us that a few tigers had died due to excessive dosage. Hence, it’s not a widely used method to count tigers, although, it has been used to study individual tigers.

Another method worthy of mention is camera trapping. In this method, an automatically triggered camera is strapped to a tree. Whenever any animal moves in front of the camera, it fires and captures a snap of the animal. Since the pattern of stripes on each individual tiger is unique (much like the human fingerprints), these pictures can give us some idea about the number of tigers in the wild. But again, this method had its own problems :- 1) to setup camera traps at multiple sites in the forest proves to be expensive. 2) Large mammals (elephants) get disturbed when the flash fires and they attack the camera, breaking it into pieces. 3) It doesn’t necessarily photograph all the tigers in the wild.

Due to these problems, the first method is preferred and is widely used all over India to count tigers.


Challenges faced by the forest department

1) Habitat destruction:- A lot of tribals still live within the forest. They depend on the forest for their very existence – wood, food (basically meat), water etc. The forest department is trying their best to relocate them to the outskirts of the forest by providing them agricultural land and shelter.

A lot of villages surround the forest. The villagers have been cutting down the forests and converting it to agricultural land over the years. They graze cattle at the edges of the forest which eat most of the grass required for the survival of herbivores in the forest. Most of the poachers come from these villages. Since they have easy access to the forest, these poachers’ setup traps to capture deer meat, tiger skin, elephant tusks etc. (In the images below, you can see the paw bones of a tiger which was caught in one of these traps. Click on the image for a bigger picture.)


2) Finance:- The forest dept. is severely short of funds. Some officials mentioned that they couldn’t afford diesel to run their jeeps!! These jeeps / forest vehicles are old and in very bad shape. They don’t have sufficient funds to setup camera traps or procure GPS units to navigate within the forest.


Call for Help

Narayan and I spoke with the RFO about the kind of problems they face and how we could help them. We had no answers for many questions that he put forward --- “Why should we (i.e. the forest officials) put our lives at risk to protect these forests? We don’t get paid well enough, we have no social/family life and the living conditions/facilities aren’t great.”

This RFO (Mr. Ravindra kumar) had worked with Dr. Ullas Karanth at Nagarhole, helping him research the behavior and habitat of tigers. He has shot dead a poacher while a group of them were trying to steal deer meat from the forest (Read the full story here). We (Narayan and I) found him to be a very helpful, sensible, well educated and practical person and a great nature/wildlife enthusiast.

After spending 4 days/nights in the forest, living and working with the forest guards, I’m highly impressed (and moved) by dedication and interest that they’ve shown in protecting whatever is left of these Indian jungles. I’m thinking of ways to help them financially, but I alone can’t do much. I don’t know how many of you guys out there are interested in contributing to this cause, but if you are even remotely interested please do leave a comment or mail/IM me and I’ll try and get in touch with you.

PS :- 1) The paw bones that you see in the picture above belong to a tiger named “Maasti”. Maasti still survives (with only 3 paws) and is taken care of at Bannerghatta zoo, Bangalore.

2) I’ll upload the pictures (about 300 of them) as soon as possible.