Chathura Herath 's Blog

My Photo
Name: Chathura Herath
Location: Bloomington, Indiana, United States

Saturday, February 28, 2009

Java method level generics - Getting First Element from an Iterator.

There are ample examples where you are given an iterator but you are only interested in the first element of the collection. Following through some code i had to read, which was doing WSDL parsing, I ran into some code which most probably annoyed the programmer because of the repeating code of the same form that had to be written for different Iterator types, to loop through the iterator and extract the first element. One solution, besides writing helper for each case is to not do typing at all and do non generic helper method.


public static Object getFirst(Iterable itr){
for (Object object : itr) {
return object;
}
throw new RuntimeException("Iterator empty");
}


Obviously this is not why i wrote this blog. I wrote down the following code which is type safe and gives exactly what i want. This makes use of java method level templates. This is type safe because when some one calls this method the templates will be instantiated and the return values are obviously typed based on the instantiation happened at the caller and no type casting necessary.


public static <T extends Object> T getfirst(Iterable<T> vals) {
for (T val: vals) {
return val;
}
throw new RuntimeException("Iterator empty");
}

Tuesday, February 03, 2009

Generic Online web service client

As i ve mentioned many times before Eclipse WTP is cool for many reasons, one of them being the ability to generate a web service client to test a service in an instant.

Lately i came across this online tool to make web service call, and its pretty useful for testing purposes and does save you time. It would get the WSDL (as a http url or otherwise) and would generate a web client which would have the text boxes for the different simple types that would build the complex type.

One client can be found in service-repository and another at soap-client.

Labels: ,

Tuesday, June 17, 2008

Whats Up Vegas!!

Last week I attended the TeraGrid conference in Las Vegas, I was presenting a paper there.
Besides the conference proceedings the gambling and the other Vegas activities were pretty interesting. Best attraction for me was the Bellagio Fountains a video of that could be found here, it was amazing.

Thursday, June 05, 2008

Deepal's Axis2 Book

Deepal Jayasinghe has published a book on Axis2 and i believe its the first book published by one of my peers from University of Moratuwa. Job well done!

Tuesday, June 03, 2008

Proud of my school

Department of computer science University of Moratuwa, the school i did my undergrads and a place i revere, recently became the highest ranking school in Google Summer of Code acceptance. Well done.

Tuesday, May 06, 2008

Browser market share.

I was interested about knowing how the Firefox was doing in their quest "take back the web" and i came across this interesting article. It seems Firefox is eating away IE and numbers seem to add up. I think it would continue to grow, from my personnel experience, i have introduces Firefox to many, none seem to have gone back to IE. The original work can be found here.





Browser20072008diff
IE 74.8% 79.1% -4%
Firefox 14.6% 17.8% +3%
Safari 4.5% 5.8% +1%

Labels: , ,

Wednesday, January 17, 2007

How to accommodate an Out-Only MEP service in Axis2

I have been queried quite a few times by Axis2 users about writing Out-Only MEPed services with Axis2 wsdl2java compiler, so thought of writing this down for future use.

First of all Axis2 does not have first class support for Out-Only MEP, as at now. Main reason being that this MEP is not widely used. Further there is a technique that is stated below that could change Out-Only MEP paradigm in to some kind of isomorphism to IN-Only MEP by switching client and the server.
In technical point of view there are other concerns such as, if a Out-Only is sitting inside Tomcat what would trigger it to send out its message? This trigger cannot be an incoming SOAP message to that service, because if it is then the MEP of the service would change to IN-OUT. So we need some trigger interface to the service implementation to tell it 'ok service now its time to send out your message'. Say we do all that what would be the gain, I would say nothing much. Even though the service reside inside Tomcat it will not gain much from Tomcat scalability because when it is sending out its message it will use commons http to initiate its communication, i.e. it would not use Tomcat's(actually jetty's) features. So might as well keep it outside Tomcat and following is the way to do it.


Method
Say you have the out-only operation named op1( which does not have a input message reference)

WSDL operation would look something like the following:






We always refer to the MEP with respec
t to the server's message exchange.

Consider a In-Only MEP, its operation would look like the following.





Now compare the service of Out-Only MEP against the client of the In-Only MEP. They are semantically the same, both
send out only one message.

So if you have a WSDL with Out-Only MEP like the following.






Change it to (i.e. change the output message reference to an input message reference)






Now above is a very familiar MEP for Axis2, In-Only MEP. Now using this changed wsdl, instead of code generating for server we code generate for client using wsdl2java compiler.

Now you will get a client that would send out messages when you call/trigger it to the endpoint you define. Functionality sound familiar?? Its same as what Out-Only service would do.

The only flaw that I can think of is that there will be no endpoint where you could run a ?wsdl query and get the WSDL. That would something that you would achieve had this service been deployed inside Tomcat. Its a compromise.